QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#341279 | #4405. 普罗霍洛夫卡 | zjy0001 | 100 ✓ | 12166ms | 53948kb | C++17 | 2.8kb | 2024-02-29 17:19:34 | 2024-02-29 17:19:34 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=4e5+5;
int n,q,a[N],lst[N],ans[N],bl[N],pos[N],rv[256];
tuple<int,int,int>Q[N];
inline void trans(int*F){
static int X[512],Y[512];
for(int i=0;i<256;++i)X[rv[i]|256]=F[i];
for(int i=256;--i;)X[i]=X[i*2]^X[i*2+1];
for(int i=1;i<512;++i)Y[i]=X[i]<<__lg(i)^Y[i>>1];
for(int i=0;i<256;++i)F[i]=Y[rv[i]|256]^(F[i]*511);
}
struct Block{
int n,tg,ans[2],a[256],b[2][256],F[256],H[2][256];vector<int>vec[256];
inline void pushdown(){
for(int k=0;k<2;++k){
trans(H[k]);
for(int i=0;i<n;++i)b[k][i]^=H[k][a[i]&255];
}
memset(H,0,sizeof(H));
for(int i=0;i<n;++i)a[i]+=tg;
tg=0;
}
inline void build(){
for(int i=0;i<256;++i)vec[i].clear();
for(int i=0;i<n;++i)vec[a[i]&255].emplace_back(i);
for(int i=0;i<256;++i)F[i]=vec[i].size()&1;
trans(F);
}
inline void add(const int&t){
const int v=(255-tg)&255;
for(auto i:vec[v])
b[t][i]^=(a[i]+tg)^(a[i]+tg+1),ans[t]^=(a[i]+tg)^(a[i]+tg+1);
ans[t]^=F[v],H[t][v]^=1,++tg;
}
inline void badd(const int&t,int l,int r){
if(tg)pushdown();
for(int i=l;i<=r;++i)
b[t][i]^=a[i]^(a[i]+1),ans[t]^=a[i]^(a[i]+1),++a[i];
build();
}
inline int bqry(const int&t,int l,int r){
if(tg)pushdown(),build();
int z=0;
for(int i=l;i<=r;++i)z^=b[t][i];
return z;
}
}A[1570];
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>q;
for(int i=1;i<=n;++i)cin>>a[i];
for(int i=1;i<=q;++i){int l,r;cin>>l>>r,Q[i]=make_tuple(r,l,i);}
sort(Q+1,Q+q+1);
for(int i=0;i<256;++i)rv[i]=(rv[i>>1]>>1)+(i&1)*128;
for(int i=1;i<=(n-1)/256+1;++i){
int l=(i-1)*256+1,r=min(i*256,n);
for(int j=l;j<=r;++j)bl[j]=i,pos[j]=j-l;
A[i].n=r-l+1,A[i].build();
}
for(int r=1,j=1;j<=q;++r){
int l=lst[a[r]]+1;lst[a[r]]=r;
if(bl[l]!=bl[r]){
A[bl[l]].badd(r&1,pos[l],255),A[bl[r]].badd(r&1,0,pos[r]);
for(int i=bl[l]+1;i<bl[r];++i)A[i].add(r&1);
}
else A[bl[l]].badd(r&1,pos[l],pos[r]);
for(;j<=q&&get<0>(Q[j])==r;++j){
auto [r,l,id]=Q[j];
if(bl[l]!=bl[r]){
ans[id]=A[bl[l]].bqry(r&1,pos[l],255)^A[bl[r]].bqry(r&1,0,pos[r]);
for(int i=bl[l]+1;i<bl[r];++i)ans[id]^=A[i].ans[r&1];
}
else ans[id]=A[bl[l]].bqry(r&1,pos[l],pos[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: 0ms
memory: 27792kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 29592kb
Test #3:
score: 0
Accepted
time: 3ms
memory: 28500kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 25124kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 26744kb
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 5
Accepted
time: 41ms
memory: 28024kb
Test #7:
score: 0
Accepted
time: 37ms
memory: 29848kb
Test #8:
score: 0
Accepted
time: 36ms
memory: 25468kb
Test #9:
score: 0
Accepted
time: 37ms
memory: 29060kb
Test #10:
score: 0
Accepted
time: 34ms
memory: 29036kb
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 10
Accepted
time: 1128ms
memory: 34988kb
Test #12:
score: 0
Accepted
time: 1129ms
memory: 32936kb
Test #13:
score: 0
Accepted
time: 1124ms
memory: 34212kb
Test #14:
score: 0
Accepted
time: 1111ms
memory: 33504kb
Test #15:
score: 0
Accepted
time: 1145ms
memory: 33960kb
Subtask #4:
score: 10
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 10
Accepted
time: 3216ms
memory: 39380kb
Test #17:
score: 0
Accepted
time: 3543ms
memory: 41816kb
Test #18:
score: 0
Accepted
time: 3462ms
memory: 41092kb
Test #19:
score: 0
Accepted
time: 3411ms
memory: 41100kb
Test #20:
score: 0
Accepted
time: 3276ms
memory: 41684kb
Subtask #5:
score: 10
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 10
Accepted
time: 6934ms
memory: 47688kb
Test #22:
score: 0
Accepted
time: 5770ms
memory: 48740kb
Test #23:
score: 0
Accepted
time: 7445ms
memory: 48820kb
Test #24:
score: 0
Accepted
time: 7170ms
memory: 47536kb
Test #25:
score: 0
Accepted
time: 7352ms
memory: 47332kb
Subtask #6:
score: 10
Accepted
Dependency #5:
100%
Accepted
Test #26:
score: 10
Accepted
time: 7915ms
memory: 51476kb
Test #27:
score: 0
Accepted
time: 9228ms
memory: 50992kb
Test #28:
score: 0
Accepted
time: 9838ms
memory: 50496kb
Test #29:
score: 0
Accepted
time: 8707ms
memory: 50608kb
Test #30:
score: 0
Accepted
time: 9207ms
memory: 51408kb
Subtask #7:
score: 10
Accepted
Test #31:
score: 10
Accepted
time: 93ms
memory: 33492kb
Test #32:
score: 0
Accepted
time: 92ms
memory: 34056kb
Test #33:
score: 0
Accepted
time: 89ms
memory: 33980kb
Test #34:
score: 0
Accepted
time: 96ms
memory: 33592kb
Test #35:
score: 0
Accepted
time: 98ms
memory: 34104kb
Subtask #8:
score: 10
Accepted
Test #36:
score: 10
Accepted
time: 835ms
memory: 38352kb
Test #37:
score: 0
Accepted
time: 823ms
memory: 37608kb
Test #38:
score: 0
Accepted
time: 821ms
memory: 36796kb
Test #39:
score: 0
Accepted
time: 838ms
memory: 38344kb
Test #40:
score: 0
Accepted
time: 828ms
memory: 38348kb
Subtask #9:
score: 10
Accepted
Dependency #8:
100%
Accepted
Test #41:
score: 10
Accepted
time: 864ms
memory: 38920kb
Test #42:
score: 0
Accepted
time: 862ms
memory: 39428kb
Test #43:
score: 0
Accepted
time: 864ms
memory: 37788kb
Test #44:
score: 0
Accepted
time: 867ms
memory: 37848kb
Test #45:
score: 0
Accepted
time: 869ms
memory: 39364kb
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: 12041ms
memory: 53852kb
Test #47:
score: 0
Accepted
time: 11574ms
memory: 53820kb
Test #48:
score: 0
Accepted
time: 12055ms
memory: 53924kb
Test #49:
score: 0
Accepted
time: 10827ms
memory: 53888kb
Test #50:
score: 0
Accepted
time: 12166ms
memory: 53948kb