QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#576152 | #4405. 普罗霍洛夫卡 | DaiRuiChen007 | 100 ✓ | 4968ms | 40776kb | C++17 | 2.5kb | 2024-09-19 18:51:49 | 2024-09-19 18:51:50 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=4e5+5,K=8,B=1<<K;
namespace Q {
const int C=B<<1;
int rv[B+5],Y[C+5],D[C+5];
bool X[C+5];
void init() {
for(int i=1;i<B;++i) rv[i]=(rv[i>>1]>>1)|((i&1)<<(K-1));
for(int i=2;i<C;++i) D[i]=D[i>>1]+1;
}
void fft(bool *f,int *g) {
for(int i=0;i<B;++i) X[rv[i]|B]=f[i];
for(int i=B-1;i;--i) X[i]=X[i<<1]^X[i<<1|1];
for(int i=1;i<C;++i) Y[i]=Y[i>>1]^(X[i]<<D[i]);
for(int i=0;i<B;++i) g[i]=Y[rv[i]|B]^(f[i]?C-1:0);
}
}
struct Block {
int n,a[B+5],b[2][B+5],tg,s[2],w[B+5],hd[B+5],lk[B+5];
bool t[2][B+5];
void psd() {
static int Z[B];
for(int o:{0,1}) {
Q::fft(t[o],Z);
for(int i=1;i<=n;++i) b[o][i]^=Z[a[i]&(B-1)];
}
for(int i=1;i<=n;++i) a[i]+=tg;
memset(t,0,sizeof(t)),tg=0;
}
void psu() {
static bool Z[B];
memset(Z,0,sizeof(Z));
memset(hd,0,sizeof(hd));
for(int i=1,A;i<=n;++i) A=a[i]&(B-1),lk[i]=hd[A],hd[A]=i,Z[A]^=1;
Q::fft(Z,w);
}
void add(bool o) {
int k=~tg&(B-1);
s[o]^=w[k],t[o][k]^=1;
for(int i=hd[k],z;i;i=lk[i]) z=(a[i]+tg)^(a[i]+tg+1),s[o]^=z,b[o][i]^=z;
++tg;
}
void add(bool o,int l,int r) {
if(tg) psd();
for(int i=l,z;i<=r;++i) z=a[i]^(a[i]+1),s[o]^=z,b[o][i]^=z,++a[i];
psu();
}
int qry(bool o,int l,int r) {
if(tg) psd(),psu();
int z=0;
for(int i=l;i<=r;++i) z^=b[o][i];
return z;
}
} ds[MAXN/B+5];
int n,q,a[MAXN],pos[MAXN],b[MAXN],L[MAXN],R[MAXN],ans[MAXN];
vector <array<int,2>> O[MAXN];
void add(int x,int o,int l,int r) {
l=max(l,L[x]),r=min(r,R[x]);
if(l==L[x]&&r==R[x]) ds[x].add(o);
else ds[x].add(o,l-L[x]+1,r-L[x]+1);
}
int qry(int x,int o,int l,int r) {
l=max(l,L[x]),r=min(r,R[x]);
if(l==L[x]&&r==R[x]) return ds[x].s[o];
else return ds[x].qry(o,l-L[x]+1,r-L[x]+1);
}
signed main() {
ios::sync_with_stdio(false);
cin>>n>>q,Q::init();
for(int i=1;i<=n;++i) cin>>a[i];
for(int i=1,l,r;i<=q;++i) cin>>l>>r,O[r].push_back({l,i});
for(int i=1;(i-1)*B+1<=n;++i) {
L[i]=(i-1)*B+1,R[i]=min(n,i*B);
fill(b+L[i],b+R[i]+1,i);
ds[i].n=R[i]-L[i]+1,ds[i].psu();
}
for(int i=1;i<=n;++i) {
int l=pos[a[i]]+1,r=i;
pos[a[i]]=i;
if(b[l]^b[r]) {
add(b[l],i&1,l,r),add(b[r],i&1,l,r);
for(int x=b[l]+1;x<=b[r]-1;++x) ds[x].add(i&1);
} else add(b[l],i&1,l,r);
for(auto z:O[i]) {
l=z[0],r=i;
if(b[l]^b[r]) {
ans[z[1]]=qry(b[l],i&1,l,r)^qry(b[r],i&1,l,r);
for(int x=b[l]+1;x<=b[r]-1;++x) ans[z[1]]^=ds[x].s[i&1];
} else ans[z[1]]=qry(b[l],i&1,l,r);
}
}
for(int i=1;i<=q;++i) cout<<ans[i]<<"\n";
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 3ms
memory: 23220kb
Test #2:
score: 5
Accepted
time: 6ms
memory: 22944kb
Test #3:
score: 5
Accepted
time: 2ms
memory: 21908kb
Test #4:
score: 5
Accepted
time: 2ms
memory: 22096kb
Test #5:
score: 5
Accepted
time: 0ms
memory: 22876kb
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 5
Accepted
time: 24ms
memory: 23504kb
Test #7:
score: 5
Accepted
time: 29ms
memory: 22980kb
Test #8:
score: 5
Accepted
time: 28ms
memory: 23100kb
Test #9:
score: 5
Accepted
time: 29ms
memory: 23176kb
Test #10:
score: 5
Accepted
time: 28ms
memory: 23748kb
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 10
Accepted
time: 764ms
memory: 27348kb
Test #12:
score: 10
Accepted
time: 764ms
memory: 27664kb
Test #13:
score: 10
Accepted
time: 766ms
memory: 27980kb
Test #14:
score: 10
Accepted
time: 760ms
memory: 26956kb
Test #15:
score: 10
Accepted
time: 764ms
memory: 28924kb
Subtask #4:
score: 10
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 10
Accepted
time: 1844ms
memory: 33060kb
Test #17:
score: 10
Accepted
time: 1833ms
memory: 33328kb
Test #18:
score: 10
Accepted
time: 1820ms
memory: 33140kb
Test #19:
score: 10
Accepted
time: 1841ms
memory: 33312kb
Test #20:
score: 10
Accepted
time: 1838ms
memory: 32016kb
Subtask #5:
score: 10
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 10
Accepted
time: 3198ms
memory: 36496kb
Test #22:
score: 10
Accepted
time: 3202ms
memory: 38016kb
Test #23:
score: 10
Accepted
time: 3176ms
memory: 37468kb
Test #24:
score: 10
Accepted
time: 3157ms
memory: 37532kb
Test #25:
score: 10
Accepted
time: 3162ms
memory: 37180kb
Subtask #6:
score: 10
Accepted
Dependency #5:
100%
Accepted
Test #26:
score: 10
Accepted
time: 3941ms
memory: 38488kb
Test #27:
score: 10
Accepted
time: 3928ms
memory: 38772kb
Test #28:
score: 10
Accepted
time: 3944ms
memory: 38348kb
Test #29:
score: 10
Accepted
time: 3942ms
memory: 39008kb
Test #30:
score: 10
Accepted
time: 3936ms
memory: 38428kb
Subtask #7:
score: 10
Accepted
Test #31:
score: 10
Accepted
time: 101ms
memory: 26384kb
Test #32:
score: 10
Accepted
time: 97ms
memory: 27236kb
Test #33:
score: 10
Accepted
time: 100ms
memory: 26692kb
Test #34:
score: 10
Accepted
time: 99ms
memory: 25268kb
Test #35:
score: 10
Accepted
time: 98ms
memory: 25476kb
Subtask #8:
score: 10
Accepted
Test #36:
score: 10
Accepted
time: 849ms
memory: 40716kb
Test #37:
score: 10
Accepted
time: 826ms
memory: 40776kb
Test #38:
score: 10
Accepted
time: 830ms
memory: 40720kb
Test #39:
score: 10
Accepted
time: 834ms
memory: 40712kb
Test #40:
score: 10
Accepted
time: 829ms
memory: 40692kb
Subtask #9:
score: 10
Accepted
Dependency #8:
100%
Accepted
Test #41:
score: 10
Accepted
time: 839ms
memory: 40708kb
Test #42:
score: 10
Accepted
time: 846ms
memory: 40712kb
Test #43:
score: 10
Accepted
time: 854ms
memory: 40628kb
Test #44:
score: 10
Accepted
time: 854ms
memory: 40648kb
Test #45:
score: 10
Accepted
time: 865ms
memory: 40712kb
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: 4845ms
memory: 40636kb
Test #47:
score: 15
Accepted
time: 4868ms
memory: 40724kb
Test #48:
score: 15
Accepted
time: 4968ms
memory: 40636kb
Test #49:
score: 15
Accepted
time: 4852ms
memory: 40632kb
Test #50:
score: 15
Accepted
time: 4835ms
memory: 40764kb