记录编号 |
143475 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
[国家集训队2011]candy(吴确) |
最终得分 |
100 |
用户昵称 |
cstdio |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
2.670 s |
提交时间 |
2014-12-15 09:20:09 |
内存使用 |
17.42 MiB |
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long LL;
const int SIZEN=610,SIZEP=3010;
int N,M;
LL PA,PB,PC,P;
LL A[SIZEP],B[SIZEP],C[SIZEP];
LL V[SIZEN][SIZEN];
LL S1[SIZEN][SIZEN],S2[SIZEN][SIZEN];
LL LD[SIZEN][SIZEN],RD[SIZEN][SIZEN],PD[SIZEN][SIZEN];//↙,↘,↓
LL query_naive(int x,int y,int k){
LL ans=0;
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
int d=abs(i-x)+abs(j-y);
if(d<k) ans+=V[i][j]*(k-d);
}
}
return ans;
}
LL ld_sum(int x1,int y1,int x2,int y2){//(x1,y1)左下角,(x2,y2)右上角
if(y1<0) x1--,y1++;
return LD[x1][y1]-LD[x2-1][y2+1];
}
LL rd_sum(int x1,int y1,int x2,int y2){//(x1,y1)左上角,(x2,y2)右下角
return RD[x2][y2]-(y1>0?RD[x1-1][y1-1]:0);
}
LL query(int x,int y,int k){
k--;
LL ans=0;
ans+=rd_sum(x-k,y,x,y+k);
ans+=ld_sum(x+k,y,x+1,y+k-1);
ans+=ld_sum(x,y-k-2,x-k,y-2);
ans+=rd_sum(x+1,y-k-1,x+k,y-2);
ans-=2*(PD[x+k][y-1]-PD[x-k-1][y-1]);
return ans;
}
void prepare(void){
for(int i=1;i<=N;i++){
S1[i][0]=0;
for(int j=1;j<=M;j++) S1[i][j]=S1[i][j-1]+V[i][j];
S2[i][0]=0;
for(int j=1;j<=M;j++) S2[i][j]=S2[i][j-1]+S1[i][j];
}
for(int i=1;i<=N;i++){
LD[i][M]=S2[i][M];for(int j=0;j<M;j++) LD[i][j]=LD[i-1][j+1]+S2[i][j];
RD[i][0]=S2[i][0];for(int j=1;j<=M;j++) RD[i][j]=RD[i-1][j-1]+S2[i][j];
for(int j=0;j<=M;j++) PD[i][j]=PD[i-1][j] +S2[i][j];
}
}
LL getval(int i,int j){
return A[i%PA]+B[i%PB]+C[i%PC]+A[j%PA]+B[j%PB]+C[j%PC];
}
inline int min(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
void work(void){
int Q,cmd[4];
LL ans=0;
scanf("%d",&Q);
for(int i=1;i<=Q;i++){
for(int j=1;j<=3;j++) cmd[j]=getval(i,j);
int x=cmd[1]%N+1,y=cmd[2]%M+1;
int k=cmd[3]%min(x,y,N-x+1,M-y+1)+1;
ans^=query(x,y,k);
}
printf("%lld\n",ans);
}
void read(void){
scanf("%lld",&PA);for(int i=0;i<PA;i++) scanf("%lld",&A[i]);
scanf("%lld",&PB);for(int i=0;i<PB;i++) scanf("%lld",&B[i]);
scanf("%lld",&PC);for(int i=0;i<PC;i++) scanf("%lld",&C[i]);
scanf("%d%d",&N,&M);
scanf("%lld",&P);
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++) V[i][j]=getval(i,j)%P+1;
}
int main(){
freopen("nt2011_candy.in","r",stdin);
freopen("nt2011_candy.out","w",stdout);
read();
prepare();
work();
return 0;
}