QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#849285 | #4405. 普罗霍洛夫卡 | 275307894a | 100 ✓ | 10582ms | 14992kb | C++14 | 4.1kb | 2025-01-09 14:14:21 | 2025-01-09 14:14:26 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=4e5+5,M=N*40+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,m,A[N],L[N],ap[N];
struct ques{int l,r,ans,id;}Q[N];
const int Bl=512,k=9;
namespace Block{
int bg,len;
int A[Bl],B[Bl],ans,sum;
int pt;
int vis[Bl],id[Bl];
short f[Bl],g[N];
void work(short *g,int op){
if(op){
for(int i=k-2;~i;i--){
for(int j=(1<<i);j<(1<<i+1);j++) g[j]=g[j+(1<<i)]^g[j+(2<<i)];
}
}else{
for(int i=0;i<k-1;i++){
for(int j=(1<<i);j<(1<<i+1);j++) g[j+(1<<i)]^=g[j],g[j+(2<<i)]^=g[j];
}
}
}
void push(){
Me(f,0);
for(int i=0;i<=pt;i++) f[Bl/2+(i&Bl/2-1)]^=g[i];
for(int i=1;i<=pt;i++) g[i]^=g[i-1];
for(int i=0;i<len;i++){
int o=0;
for(int j=Bl/2-1-(A[i]&Bl/2-1);;j+=Bl/2){
if(g[min(j,pt)]^o) B[i]^=(A[i]+j>>k-1)<<k-1;
if(j>pt) break;
o=g[j];
}
}
work(f,1);
for(int i=1;i<k;i++){
static int dp[Bl];
copy(f+(1<<i),f+(1<<i+1),dp);
int res=0;for(int j=(1<<i-1);j<(1<<i);j++) res^=dp[j];
int R=(1<<i-1);
for(int j=0;j<(1<<i);j++){
f[j+(1<<i)]=res<<i-1;
--R;if(R<0) R+=(1<<i);
res^=dp[R]^dp[(1<<i)-1-j];
}
}
f[1]=0;
work(f,0);
for(int i=0;i<len;i++) B[i]^=f[Bl/2+(A[i]&Bl/2-1)],A[i]+=pt;
/*for(int i=0;i<len;i++){
for(int j=0;j<=pt&&j<Bl/2;j++) if(f[j]) B[i]^=A[i]+j&Bl/2-1;
A[i]+=pt;
}*/
fill(g,g+pt+1,0);pt=0;
}
void rebuild(){
Me(vis,0);Me(id,-1);Me(f,0);
for(int i=0;i<len;i++) vis[A[i]&Bl-1]^=1,id[A[i]&Bl-1]=A[i];
for(int i=0;i<len;i++) f[Bl/2+(A[i]&Bl/2-1)]^=1;
work(f,1);
for(int i=0;i<k;i++){
reverse(f+(1<<i)+1,f+(1<<i+1));
for(int j=(1<<i);j<(1<<i+1);j++) f[j]<<=i;
}
work(f,0);
}
void build(int l,int r){
bg=l;len=r-l+1;ans=sum=0;
Me(A,0);Me(B,0);fill(g,g+pt+1,0);pt=0;
rebuild();
}
void add(){
pt++;
sum^=f[Bl/2+(pt&Bl/2-1)];
int x=(Bl-(pt&Bl-1))&Bl-1;
if(~id[x]&&vis[x]){
int sw=((1<<__builtin_ctz(pt+id[x])+1)-1>>k)<<k;
sum^=sw;
}
// for(int i=0;i<len;i++) sum^=(1<<__builtin_ctz(pt+A[i])+1)-1;
}
void add_range(int l,int r){
l-=bg;r-=bg;push();
for(int i=l;i<=r;i++) sum^=A[i],A[i]++,sum^=A[i];
rebuild();
}
void modify(){
ans^=sum;
g[pt]^=1;
}
int qry(int l,int r){
l-=bg;r-=bg;
push();
int res=0;
for(int i=l;i<=r;i++) res^=B[i];
rebuild();
return res;
}
}
void Solve(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&A[i]);
for(int i=1;i<=n;i++) L[i]=ap[A[i]]+1,ap[A[i]]=i;
for(int i=1;i<=m;i++) scanf("%d%d",&Q[i].l,&Q[i].r),Q[i].id=i;
sort(Q+1,Q+m+1,[](ques x,ques y){return x.r<y.r;});
for(int l=1,r;l<=n;l=r+1){
r=min(n,l+Bl-1);
Block::build(l,r);
int R=1;
for(int j=1;j<=n;j++){
if(L[j]<=l&&r<=j) Block::add();
else if(L[j]<=r&&l<=j) Block::add_range(max(l,L[j]),min(r,j));
Block::modify();
while(R<=m&&Q[R].r==j){
if(Q[R].l<=l&&r<=Q[R].r) Q[R].ans^=Block::ans;
else if(Q[R].l<=r&&l<=Q[R].r) Q[R].ans^=Block::qry(max(l,Q[R].l),min(r,Q[R].r));
R++;
}
}
}
sort(Q+1,Q+m+1,[](ques x,ques y){return x.id<y.id;});
for(int i=1;i<=m;i++) printf("%d\n",Q[i].ans);
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 1ms
memory: 4080kb
Test #2:
score: 5
Accepted
time: 1ms
memory: 4060kb
Test #3:
score: 5
Accepted
time: 1ms
memory: 3964kb
Test #4:
score: 5
Accepted
time: 1ms
memory: 4060kb
Test #5:
score: 5
Accepted
time: 1ms
memory: 4004kb
Subtask #2:
score: 5
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 5
Accepted
time: 68ms
memory: 4224kb
Test #7:
score: 5
Accepted
time: 69ms
memory: 4232kb
Test #8:
score: 5
Accepted
time: 68ms
memory: 4204kb
Test #9:
score: 5
Accepted
time: 75ms
memory: 4192kb
Test #10:
score: 5
Accepted
time: 68ms
memory: 6276kb
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 10
Accepted
time: 1727ms
memory: 6672kb
Test #12:
score: 10
Accepted
time: 1721ms
memory: 8472kb
Test #13:
score: 10
Accepted
time: 1725ms
memory: 8060kb
Test #14:
score: 10
Accepted
time: 1712ms
memory: 8192kb
Test #15:
score: 10
Accepted
time: 1716ms
memory: 8328kb
Subtask #4:
score: 10
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 10
Accepted
time: 4056ms
memory: 9536kb
Test #17:
score: 10
Accepted
time: 4060ms
memory: 9532kb
Test #18:
score: 10
Accepted
time: 4109ms
memory: 9524kb
Test #19:
score: 10
Accepted
time: 4061ms
memory: 9488kb
Test #20:
score: 10
Accepted
time: 4082ms
memory: 9404kb
Subtask #5:
score: 10
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 10
Accepted
time: 7010ms
memory: 12292kb
Test #22:
score: 10
Accepted
time: 6990ms
memory: 12264kb
Test #23:
score: 10
Accepted
time: 7010ms
memory: 12288kb
Test #24:
score: 10
Accepted
time: 6987ms
memory: 12684kb
Test #25:
score: 10
Accepted
time: 6992ms
memory: 12292kb
Subtask #6:
score: 10
Accepted
Dependency #5:
100%
Accepted
Test #26:
score: 10
Accepted
time: 8681ms
memory: 13636kb
Test #27:
score: 10
Accepted
time: 8709ms
memory: 13636kb
Test #28:
score: 10
Accepted
time: 8662ms
memory: 13636kb
Test #29:
score: 10
Accepted
time: 8680ms
memory: 13912kb
Test #30:
score: 10
Accepted
time: 8754ms
memory: 13592kb
Subtask #7:
score: 10
Accepted
Test #31:
score: 10
Accepted
time: 1979ms
memory: 10292kb
Test #32:
score: 10
Accepted
time: 1971ms
memory: 10288kb
Test #33:
score: 10
Accepted
time: 1977ms
memory: 10244kb
Test #34:
score: 10
Accepted
time: 1963ms
memory: 10148kb
Test #35:
score: 10
Accepted
time: 1981ms
memory: 10296kb
Subtask #8:
score: 10
Accepted
Test #36:
score: 10
Accepted
time: 9179ms
memory: 13304kb
Test #37:
score: 10
Accepted
time: 9248ms
memory: 13440kb
Test #38:
score: 10
Accepted
time: 9209ms
memory: 13388kb
Test #39:
score: 10
Accepted
time: 9181ms
memory: 13396kb
Test #40:
score: 10
Accepted
time: 9199ms
memory: 13448kb
Subtask #9:
score: 10
Accepted
Dependency #8:
100%
Accepted
Test #41:
score: 10
Accepted
time: 9348ms
memory: 13436kb
Test #42:
score: 10
Accepted
time: 9394ms
memory: 13496kb
Test #43:
score: 10
Accepted
time: 9445ms
memory: 13452kb
Test #44:
score: 10
Accepted
time: 9374ms
memory: 13448kb
Test #45:
score: 10
Accepted
time: 9321ms
memory: 13440kb
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: 10582ms
memory: 14960kb
Test #47:
score: 15
Accepted
time: 10575ms
memory: 14984kb
Test #48:
score: 15
Accepted
time: 10515ms
memory: 14992kb
Test #49:
score: 15
Accepted
time: 10515ms
memory: 14844kb
Test #50:
score: 15
Accepted
time: 10514ms
memory: 14920kb