Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
26913 LYLAKIOI 【BJ】T1 C++ 通过 100 831 MS 111376 KB 2387 2024-02-27 13:16:17

Tests(20/20):


#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define pi pair<int,int> #define p1 first #define p2 second #define x1 x114514 #define y1 y114514 #define p_b push_back using namespace std; typedef long long ll; inline ll read(){ ll x=0;short t=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } int n,m,q,typ,a[305][305]; short f[305][305][305],id[305][305*305]; vector<int>P[305],Q; void init(){ up(i,1,n){ P[i].p_b(0); up(j,1,m)P[i].p_b(a[i][j]); sort(P[i].begin(),P[i].end()); up(j,1,m){ int w=lower_bound(P[i].begin(),P[i].end(),a[i][j])-P[i].begin(); up(k,w,m)f[i][j][k]=f[i][j-1][k]+1; up(k,1,w-1)f[i][j][k]=f[i][j-1][k]; } }Q.p_b(0); up(i,1,n)up(j,1,m)Q.p_b(a[i][j]); sort(Q.begin(),Q.end()); up(i,1,n){ int pos=0; up(j,1,n*m){ while(pos<=m&&P[i][pos]<=Q[j])pos++; id[i][j]=pos-1; } } } int qry(int x1,int y1,int x2,int y2,int l,int r){ int res=0; up(i,x1,x2){ short w1=id[i][r]; short w2=id[i][l]; if(w2==m||(!w1))continue; res+=f[i][y2][w1]-f[i][y2][w2]; res-=f[i][y1-1][w1]-f[i][y1-1][w2]; }return res; } void slv(){ n=read(),m=read(),q=read(),typ=read(); up(i,1,n)up(j,1,m)a[i][j]=read();init(); //cerr<<clock()*1.0/CLOCKS_PER_SEC<<"s\n"; int lst=0; while(q--){ int x1=read(),y1=read(),x2=read(),y2=read(),l=read(),r=read(); if(typ){ x1^=lst,y1^=lst,x2^=lst,y2^=lst,l^=lst,r^=lst; }x1=(x1-1+n)%n+1,x2=(x2-1+n)%n+1,y1=(y1-1+m)%m+1,y2=(y2-1+m)%m+1; if(x1>x2)swap(x1,x2);if(y1>y2)swap(y1,y2);if(l>r)swap(l,r); l--;r=upper_bound(Q.begin(),Q.end(),r)-Q.begin(),l=upper_bound(Q.begin(),Q.end(),l)-Q.begin(); r--,l--; int res=qry(x1,y1,x2,y2,l,r); printf("%d\n",lst=res); } //cerr<<clock()*1.0/CLOCKS_PER_SEC<<"s\n"; //cerr<<(sizeof(f)+sizeof(id))/1024.0/1024.0<<"MB\n"; }int main(){ // freopen("bath.in","r",stdin); // freopen("bath.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }


测评信息: