QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#44711 | #4405. 普罗霍洛夫卡 | Crysfly# | 100 ✓ | 9466ms | 27328kb | C++11 | 3.0kb | 2022-08-21 11:09:14 | 2022-08-21 11:09:17 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for( int i=(a);i<=(b);++i)
#define Rep(i,a,b) for( int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 400005
#define inf 0x3f3f3f3f
int n,m,t,col[maxn],pre[maxn],nl[maxn],res[maxn];
vector<pii>q[maxn];
#define B 512
#define S 511
int rev[B<<1|5],dep[B<<1|5];
int a[B+5],his[B+5],add,sum[2],f[B+5],lstsum,now;
int cnt[B<<1|5],tr[B<<1|5];
int addc[2][B+5],addv[2][B+5],av[B+5],al[B+5];
int g[B<<1|5];
void trans(int*f){
For(i,0,B-1)cnt[rev[i]|B]=f[i]&1;
Rep(i,B-1,1)cnt[i]=cnt[i<<1]^cnt[i<<1|1];
For(i,1,B|S)tr[i]=tr[i>>1]^(cnt[i]<<dep[i]);
For(i,0,B-1)f[i]=tr[rev[i]|B];
}
void clear(){
sum[0]=sum[1]=0;
memset(f,0,sizeof f);
memset(addc,0,sizeof addc);
memset(addv,0,sizeof addv);
memset(av,-1,sizeof av);
}
int lstt=0,o;
void down(){
// cout<<"down\n";
if(add){
trans(addc[o]);
For(i,1,B){
int c=(a[i]&S);
his[i]^=addc[o][c]^addv[o][c];
a[i]+=add;
}
}else{
if(o==lstt)
For(i,1,B)his[i]^=a[i];
}
add=0;
}
void rebuild(){
clear();
for(int l=1,r;l<=B;l=r+1){
r=l; while(r<B&&a[r+1]==a[l])++r;
int c=(a[l]&S);
av[c]=a[l],f[c]=al[c]=(r-l+1&1);
if(al[c])sum[o^1]^=a[l];
addv[o^1][c]=a[l];
}
trans(f);
lstt=o^1;
}
void mdf(int l,int r){
l=max(l,1),r=min(r,B);
down();
++t; o^=1; lstsum=0;
For(i,l,r)++a[i];
For(i,1,B)his[i]^=a[i],lstsum^=his[i];
rebuild();
}
void addone(){
int c=(S^(add&S));
++add;
++t; o^=1;
sum[o]^=f[c];
addc[o][c]^=1;
if(av[c]!=-1){
int val=(av[c]+add)^(av[c]+add-1)^B^S;
if(al[c]) sum[o]^=val;
addv[o][c]^=val;
}
}
int ask(int l,int r){
l=max(l,1),r=min(r,B);
int res=0;
if(add){
down();
lstsum=0;
For(i,1,B)lstsum^=his[i];
For(i,l,r)res^=his[i];
rebuild();
return res;
}
For(i,l,r)res^=his[i]^addv[o][a[i]&S];
return res;
}
signed main()
{
// freopen("data.in","r",stdin);
// freopen("now.out","w",stdout);
n=read(),m=read();
For(i,0,B-1)rev[i]=(rev[i>>1]>>1)|((i&1)*(B>>1));
For(i,2,B*2-1)dep[i]=dep[i>>1]+1;
For(i,1,n)col[i]=read();
For(i,1,m){
int l=read(),r=read();
q[r].pb(mkp(l,i));
}
For(i,1,n)nl[i]=pre[col[i]]+1,pre[col[i]]=i;
For(_,1,(n-1)/B+1){
int L=(_-1)*B+1,R=L+B-1;
memset(a,0,sizeof a);
memset(his,0,sizeof his);
add=lstsum=now=0;
clear();
av[0]=0,al[0]=0;
t=0;o=0;
For(i,L,n){
int tl=nl[i],tr=i,ttr=tr-L+1;
if(tl<=L&&tr>=R) addone();
else if(tl<=R)mdf(tl-L+1,ttr);
else ++t,o^=1;
int nowsum=lstsum^sum[o];
for(auto t:q[i]){
tl=t.fi;
if(tl<=L&&tr>=R) res[t.se]^=nowsum;
else if(tl<=R) res[t.se]^=ask(tl-L+1,ttr);
}
}
}
For(i,1,m)printf("%d\n",res[i]);
return 0;
}
Details
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 19188kb
Test #2:
score: 0
Accepted
time: 6ms
memory: 18648kb
Test #3:
score: 0
Accepted
time: 7ms
memory: 18004kb
Test #4:
score: 0
Accepted
time: 2ms
memory: 18024kb
Test #5:
score: 0
Accepted
time: 5ms
memory: 17936kb
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 5
Accepted
time: 52ms
memory: 19020kb
Test #7:
score: 0
Accepted
time: 53ms
memory: 17676kb
Test #8:
score: 0
Accepted
time: 47ms
memory: 19140kb
Test #9:
score: 0
Accepted
time: 47ms
memory: 18036kb
Test #10:
score: 0
Accepted
time: 42ms
memory: 18992kb
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 10
Accepted
time: 1356ms
memory: 20204kb
Test #12:
score: 0
Accepted
time: 1366ms
memory: 21252kb
Test #13:
score: 0
Accepted
time: 1371ms
memory: 20888kb
Test #14:
score: 0
Accepted
time: 1380ms
memory: 20144kb
Test #15:
score: 0
Accepted
time: 1377ms
memory: 21300kb
Subtask #4:
score: 10
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 10
Accepted
time: 3303ms
memory: 22816kb
Test #17:
score: 0
Accepted
time: 3328ms
memory: 22052kb
Test #18:
score: 0
Accepted
time: 3303ms
memory: 22296kb
Test #19:
score: 0
Accepted
time: 3339ms
memory: 21248kb
Test #20:
score: 0
Accepted
time: 3323ms
memory: 22512kb
Subtask #5:
score: 10
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 10
Accepted
time: 5899ms
memory: 24508kb
Test #22:
score: 0
Accepted
time: 5897ms
memory: 24140kb
Test #23:
score: 0
Accepted
time: 6044ms
memory: 24852kb
Test #24:
score: 0
Accepted
time: 6015ms
memory: 24296kb
Test #25:
score: 0
Accepted
time: 5960ms
memory: 24344kb
Subtask #6:
score: 10
Accepted
Dependency #5:
100%
Accepted
Test #26:
score: 10
Accepted
time: 7801ms
memory: 25908kb
Test #27:
score: 0
Accepted
time: 7657ms
memory: 26020kb
Test #28:
score: 0
Accepted
time: 7586ms
memory: 26224kb
Test #29:
score: 0
Accepted
time: 7651ms
memory: 26180kb
Test #30:
score: 0
Accepted
time: 7519ms
memory: 26144kb
Subtask #7:
score: 10
Accepted
Test #31:
score: 10
Accepted
time: 109ms
memory: 23640kb
Test #32:
score: 0
Accepted
time: 110ms
memory: 21492kb
Test #33:
score: 0
Accepted
time: 110ms
memory: 21804kb
Test #34:
score: 0
Accepted
time: 95ms
memory: 22704kb
Test #35:
score: 0
Accepted
time: 110ms
memory: 22264kb
Subtask #8:
score: 10
Accepted
Test #36:
score: 10
Accepted
time: 4922ms
memory: 26608kb
Test #37:
score: 0
Accepted
time: 4886ms
memory: 27080kb
Test #38:
score: 0
Accepted
time: 4977ms
memory: 27260kb
Test #39:
score: 0
Accepted
time: 4883ms
memory: 27268kb
Test #40:
score: 0
Accepted
time: 4922ms
memory: 27268kb
Subtask #9:
score: 10
Accepted
Dependency #8:
100%
Accepted
Test #41:
score: 10
Accepted
time: 4910ms
memory: 27320kb
Test #42:
score: 0
Accepted
time: 4992ms
memory: 27060kb
Test #43:
score: 0
Accepted
time: 4921ms
memory: 26796kb
Test #44:
score: 0
Accepted
time: 4898ms
memory: 27276kb
Test #45:
score: 0
Accepted
time: 4892ms
memory: 27328kb
Subtask #10:
score: 15
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
100%
Accepted
Dependency #7:
100%
Accepted
Dependency #8:
100%
Accepted
Dependency #9:
100%
Accepted
Test #46:
score: 15
Accepted
time: 9352ms
memory: 27260kb
Test #47:
score: 0
Accepted
time: 9466ms
memory: 27256kb
Test #48:
score: 0
Accepted
time: 9387ms
memory: 27324kb
Test #49:
score: 0
Accepted
time: 9325ms
memory: 27288kb
Test #50:
score: 0
Accepted
time: 9466ms
memory: 27256kb