QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#424696 | #7839. 虹 | kkkgjyismine4 | 0 | 19ms | 43468kb | C++14 | 3.1kb | 2024-05-29 15:38:47 | 2024-05-29 15:38:47 |
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 ",Ans[i]);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 19ms
memory: 43468kb
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:
wrong answer 1st lines differ - expected: '16521790', found: '16521790 13341944 16841705 222...141674 540498 18782755 6980766 '
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:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%