Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
26950 | liuyile | 【BJ】T1 | C++ | 解答错误 | 55 | 784 MS | 216576 KB | 2552 | 2024-02-27 16:38:57 |
#include<bits/stdc++.h> //#define int long long //#define endl "\n" using namespace std; #pragma GCC optimize(2) int pre[301][301][301]; short rkd[90010][310],rku[90010][310]; int ALL[100030]; int LEN,len[310]; int a[310][310]; int b[310][310]; int n,m,q,tp; inline int rkdn(int x){ return upper_bound(ALL+1,ALL+LEN+1,x)-ALL-1; } inline int rkup(int x){ return lower_bound(ALL+1,ALL+LEN+1,x)-ALL; } signed main(){ //freopen("bath.in","r",stdin); //freopen("bath.out","w",stdout); //ios::sync_with_stdio(false); cin>>n>>m>>q>>tp; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++) scanf("%d",&a[i][j]),b[i][j]=a[i][j],ALL[++LEN]=a[i][j]; sort(b[i]+1,b[i]+m+1); len[i]=unique(b[i]+1,b[i]+m+1)-b[i]-1; for(int j=1;j<=m;j++){ a[i][j]=lower_bound(b[i]+1,b[i]+len[i]+1,a[i][j])-b[i]; memcpy(pre[i][j],pre[i][j-1],sizeof(pre[i][j])); pre[i][j][a[i][j]]++; } for(int j=1;j<=m;j++) for(int k=1;k<=m+1;k++) pre[i][j][k]+=pre[i][j][k-1]; b[i][0]=-1; b[i][len[i]+1]=2e9; } sort(ALL+1,ALL+LEN+1); LEN=unique(ALL+1,ALL+LEN+1)-ALL-1; for(int i=1;i<=n;i++){ int it=0; for(int j=1;j<=LEN;j++){ while(b[i][it]<ALL[j]) it++; rku[j][i]=it; } it=0; for(int j=1;j<=LEN;j++){ while(b[i][it]<=ALL[j]) it++; rkd[j][i]=it-1; } } int lst=0; while(q--){ register int xl,xr,yl,yr,wl,wr; //cin>>xl>>yl>>xr>>yr>>wl>>wr; scanf("%d%d%d%d%d%d",&xl,&yl,&xr,&yr,&wl,&wr); if(tp){ xl^=lst; xl=(xl-1+n)%n+1; xr^=lst; xr=(xr-1+n)%n+1; yl^=lst; yl=(yl-1+m)%m+1; yr^=lst; yr=(yr-1+m)%m+1; wl^=lst; wr^=lst; } if(xl>xr)swap(xl,xr); if(yl>yr)swap(yl,yr); if(wl>wr)swap(wl,wr); wl=rkup(wl); wr=rkdn(wr); int res=0; for(register int i=xl;i<=xr;i++){ register short L=rku[wl][i]; register short R=rkd[wr][i]; res+=pre[i][yr][R]-pre[i][yl-1][R]; if(L)res+=pre[i][yl-1][L-1]-pre[i][yr][L-1]; } printf("%d\n",lst=res); //cout<<(lst=res)<<'\n'; } //fflush(); cout.flush(); return 0; } /* */