QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424698 | #7839. 虹 | kkkgjyismine4 | 10 | 26ms | 45576kb | C++14 | 3.1kb | 2024-05-29 15:39:43 | 2024-05-29 15:39:44 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define ull unsigned long long
#define bi bitset<80001>
using namespace std;
const int B=300,N=80000;
int n,q,z[N+1],opt[N+5],ql[N+5],qr[N+5],qu[N+5],up[N+5][19];
bi f[N+1],g[N+1],Now,I;
int tl[300],tr[300],tt,dep[80005];
int bl(int x){return ((x-1)/B+1);}
vector<int>road[N+5],Ql[N+5],Qr[N+5],vec[N+5];
int st[19][N+5],lg[N+5];
int lca(int u,int v){
if(dep[u]<dep[v])swap(u,v);
for(int i=18;i>=0;--i)if(up[u][i]&&dep[up[u][i]]>=dep[v])u=up[u][i];
if(u==v)return u;
for(int i=18;i>=0;--i)if(up[u][i]!=up[v][i])u=up[u][i],v=up[v][i];
return up[u][0];
}
int qry(int l,int r){
int len=lg[r-l+1];
return lca(st[len][l],st[len][r-(1<<len)+1]);
}
void dfs(int u,int fa){
f[u][u]=1;
for(int i=1;(1<<i)<=dep[u];++i)up[u][i]=up[up[u][i-1]][i-1];
for(int v:road[u]){
if(v==fa)continue;
dep[v]=dep[u]+1,f[v]=f[u],up[v][0]=u;
dfs(v,u);
}
}
const int mod=20242024,sd=19901991;
int gd[N+5],Ans[N+5],prime[N+5],tot,ip[N+5];
void init(){
for(int i=2;i<=N;++i){
if(!ip[i])prime[++tot]=i;
for(int j=1;j<=tot&&prime[j]*i<=N;++j){
ip[prime[j]*i]=1;
if(i%prime[j]==0)break;
}
}
}
map<int,int>vis;
void solve(int X,int p,int lst){
for(auto v:vec[X]){
g[v]&=Now,g[v]>>=(ql[v]-1),g[v][0]=0;
int ct=(g[v]&(I>>(n-qr[v]+ql[v]-1))).count();
Ans[v]=(1ll*ct*sd+qr[v]-ql[v]+1-ct)%mod;
}
for(int i=p;i<=tot&&1ll*X*prime[i]<=N;++i){
int np=prime[i];if(i==p)np*=lst;
for(int j=np;j<=n;j+=np)gd[j]*=prime[i],Now[j]=z[gd[j]];
solve(X*prime[i],i,np);
for(int j=np;j<=n;j+=np)gd[j]/=prime[i],Now[j]=z[gd[j]];
}
}
int main(){
init(),cin>>n>>q;
for(int i=1;i<=n;++i)scanf("%d",&z[i]),st[0][i]=i,z[i]&=1,I[i]=1,gd[i]=1;
for(int i=2;i<=n;++i)lg[i]=lg[i>>1]+1;
for(int i=1;i<n;++i){
int u,v;scanf("%d%d",&u,&v);
road[u].pb(v),road[v].pb(u);
}dfs(1,-1);
for(int j=1;(1<<j)<=n;++j)
for(int i=1;i+(1<<j)-1<=n;++i)st[j][i]=lca(st[j-1][i],st[j-1][i+(1<<j-1)]);
for(int l=1;l<=n;l+=B)++tt,tl[tt]=l,tr[tt]=min(l+B-1,n);
for(int i=1;i<=q;++i){
scanf("%d",&opt[i]);
if(opt[i]&1){
scanf("%d%d",&ql[i],&qr[i]);
if(bl(ql[i])==bl(qr[i]))for(int j=ql[i];j<=qr[i];++j)g[i]|=f[j];
else{
int x=bl(ql[i]),y=bl(qr[i]);
Ql[ql[i]].pb(i),Qr[qr[i]].pb(i);
if(y-x>1)Ql[tl[x+1]].pb(i),Qr[tr[y-1]].pb(i);
}
}else scanf("%d%d%d",&ql[i],&qr[i],&qu[i]);
}
for(int i=1;i<=tt;++i){
Now.reset();
for(int j=tl[i];j<=n;++j){
int p=j;
while(p&&!Now[p])Now[p]=1,p=up[p][0];
for(auto v:Qr[j]){
if(qr[v]==j&&i==bl(j))g[v]|=Now;
if(qr[v]>j&&i==bl(ql[v])+1)g[v]|=Now;
}
}
Now.reset();
for(int j=tr[i];j>=1;--j){
int p=j;
while(p&&!Now[p])Now[p]=1,p=up[p][0];
for(auto v:Ql[j]){
if(ql[v]==j&&i==bl(j))g[v]|=Now;
if(ql[v]<j&&i==bl(qr[v])-1)g[v]|=Now;
}
}
}
Now.reset();
for(int i=1;i<=q;++i)
if(opt[i]&1){
int t=qry(ql[i],qr[i]);
if(t>1)g[i]^=f[up[t][0]];
Now^=g[i];
}else g[i]=Now,vec[qu[i]].pb(i);
Now.reset();
for(int i=1;i<=n;++i)Now[i]=z[gd[i]];
solve(1,1,1);
for(int i=1;i<=q;++i)if(opt[i]==2)printf("%d\n",Ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 20ms
memory: 45576kb
input:
998 1000 955556485 952505211 899166521 258704448 894183248 636280051 62949347 983956660 113872828 588367167 208142006 665025449 944228063 284736189 169202015 56096447 404419923 30158095 111191865 717455344 790159420 391379127 208279658 426780799 886604643 940903663 618716147 773652834 385881251 1593...
output:
16521790 13341944 16841705 2220375 880451 3621051 12662029 6300750 3240463 2400556 6501168 3580517 9221391 8381420 12982211 8001004 9361122 17262479 3600913 10401408 16202143 15022309 16341874 7861442 1560390 8340899 12421304 13961591 10421679 12101636 17361912 11781615 4780673 13641787 20102392 171...
result:
ok 490 lines
Test #2:
score: 0
Accepted
time: 26ms
memory: 45508kb
input:
1000 997 103470799 773962597 977631665 55926526 616833039 263471628 825848455 638144717 340710593 68036397 623497249 808915869 345157828 256095693 400262335 173843004 238983751 646376872 243739767 221162275 465477137 772061029 840064611 274062983 522264159 689460088 20129595 287189331 622217799 6948...
output:
13621441 17282360 11241382 15841876 17222347 1880319 12441746 10381083 18222171 7341024 10081427 2900456 2900406 13801602 17521768 19901997 8521022 13281468 2400503 17201967 19942477 14461494 19742168 14461471 12121799 2600806 18902095 1941004 19901993 10221200 8901579 9201080 19442423 720422 130019...
result:
ok 527 lines
Test #3:
score: 0
Accepted
time: 18ms
memory: 43452kb
input:
1000 1000 1697351 841785432 606301324 899151762 398181773 419939453 419455373 826820357 965555426 240847697 718049384 378823565 364137136 867089279 445499605 934770217 134914678 642584637 766848023 203338778 153291975 240768524 446186401 462123008 408740063 755064293 274502953 646610365 27815415 164...
output:
368 198 7021295 16001721 18602311 8021119 17201976 1380573 13141934 3580444 14641604 16681966 3240524 16182225 7541265 8520964 6341385 18922654 17861873 13781440 11581327 14342249 3600640 6821000 16841702 860350 16501686 3420674 18881910 6161028 17022054 3920543 4600572 6300810 3761005 11401360 8181...
result:
ok 502 lines
Subtask #2:
score: 0
Memory Limit Exceeded
Test #4:
score: 0
Memory Limit Exceeded
input:
65531 65535 968854923 932574892 192297572 866236747 654755663 148562561 273214896 947434573 938626677 992982166 219888853 229840279 676071061 383387319 372883953 729287797 601010887 31942080 990584163 823724544 181337075 918252129 896876911 768539961 357780649 890577681 819641335 320266037 55445939 ...
output:
2662122 12263904 9988949 9098885 10661570 169420 12206075 11189204 12737561 19687277 3177635 12864425 16522132 8890301 19817862 19631288 14433359 4841805 15087340 13737927
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%