1989 竞赛表格
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MX = 1e10;
typedef pair<LL,LL> P;
const int maxn = 1e7;
LL co[20];
P p[maxn]; int p1;
LL A[maxn],S[maxn];int p2;
void dfs(int x,LL v,LL count,int len){
if(v > MX) return ;
if(x > (len+1)/2){
p[p1++] = P(v,count);
return ;
}
int nn = 18;
bool t = x == (len+1)/2 && (len & 1);
if(t) nn = 9;
for(int i = 0;i <= nn; ++i){
int cnt = 1;
if(!t)
cnt = min(i,9)-max(i-9,(int)(x==1))+1;
if(cnt <= 0) continue;
dfs(x+1,v+i*co[x],cnt*count,len);
}
}
LL rev(LL x){
LL a = 0;
while(x)
a = a*10+x%10,x /= 10;
return a;
}
int main(void){
LL t = 1;
int len = 10;
for(int i = 1;i <= len; ++i){
LL a = 1,b = t;
for(int j = 1;j <= (i+1)/2; ++j){
co[j] = a+b;
a *= 10;
b /= 10;
}
dfs(1,0,1,i);
t *= 10;
}
sort(p,p+p1);
for(int i = 0,j;i < p1; ++i){
LL t = i;
for(j = i+1;j < p1; ++j){
if(p[j].first == p[i].first)
p[i].second += p[j].second,t = j;
else
break;
}
A[p2] = p[i].first;
S[p2++] = p[i].second;
i = t;
}
for(int i = 0;i < p2; ++i){
LL r = A[i]+rev(A[i]);
if(r > MX) continue;
S[lower_bound(A,A+p2,r)-A] += S[i];
}
for(int i = 1;i < p2; ++i) S[i] += S[i-1];
int Q; cin>>Q;
LL L,R,P;
LL ans = 0;
while(Q--){
scanf("%lld%lld%lld",&L,&R,&P);
LL tmp = (S[upper_bound(A,A+p2,R)-A-1] - S[lower_bound(A,A+p2,L)-A-1]+R-L+1);
tmp %= P;
ans ^= tmp;
}
cout<<ans<<endl;
return 0;
}