QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561504 | #7839. 虹 | DaiRuiChen007 | 0 | 534ms | 677936kb | C++17 | 3.0kb | 2024-09-12 23:13:09 | 2024-09-12 23:13:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN=8e4+5,B=282,X=19901991,Y=20242024;
int n,q,z[MAXN],bel[MAXN],lp[MAXN],rp[MAXN];
vector <int> G[MAXN];
int fa[MAXN],dfn[MAXN],dcnt,st[MAXN][18],dl[MAXN][18],dr[MAXN][18];
int bit(int x) { return 1<<x; }
int cmp(int x,int y) { return dfn[x]<dfn[y]?x:y; }
int qdl(int l,int r) {
int k=__lg(r-l+1);
return min(dl[l][k],dl[r-bit(k)+1][k]);
}
int qdr(int l,int r) {
int k=__lg(r-l+1);
return max(dr[l][k],dr[r-bit(k)+1][k]);
}
int lca(int l,int r) {
int k=__lg(r-l+1);
return cmp(st[l][k],st[r-bit(k)+1][k]);
}
void dfs0(int u,int fz) {
fa[u]=fz,dl[u][0]=dr[u][0]=dfn[u]=++dcnt,st[dcnt][0]=fz;
for(int v:G[u]) if(v^fz) dfs0(v,u);
}
int op[MAXN],ql[MAXN],qr[MAXN];
bitset <MAXN> F[MAXN],S;
vector <int> wl[MAXN],wr[MAXN],wx[MAXN],LCA[MAXN];
void add(bitset<MAXN>&s,int u) { for(;u&&!s[u];u=fa[u]) s.set(u); }
void dfs1(int u) {
S.set(u);
for(int i:LCA[u]) F[i]^=S,cout<<u<<" -> "<<i<<"\n";
for(int v:G[u]) if(v^fa[u]) dfs1(v);
S.reset(u);
}
int pr[MAXN],tot,g[MAXN];
bool isc[MAXN];
void dfs2(int o,int x,int y) {
for(int i:wx[x]) F[i]&=S;
for(int i=o;i<=tot&&1ll*x*pr[i]<=n;++i) {
int p=pr[i],w=(i==o?y*p:p);
for(int j=w;j<=n;j+=w) S[j]=z[g[j]*=p];
dfs2(i,x*pr[i],w);
for(int j=w;j<=n;j+=w) S[j]=z[g[j]/=p];
}
}
signed main() {
ios::sync_with_stdio(false);
cin>>n>>q;
for(int i=1;i<=n;++i) cin>>z[i],z[i]%=2;
for(int i=1;(i-1)*B+1<=n;++i) {
lp[i]=(i-1)*B+1,rp[i]=min(i*B,n);
fill(bel+lp[i],bel+rp[i]+1,i);
}
for(int i=1,u,v;i<n;++i) cin>>u>>v,G[u].push_back(v),G[v].push_back(u);
dfs0(1,0);
for(int k=1;k<18;++k) for(int i=1;i+bit(k)-1<=n;++i) {
st[i][k]=cmp(st[i][k-1],st[i+bit(k-1)][k-1]);
dl[i][k]=min(dl[i][k-1],dl[i+bit(k-1)][k-1]);
dr[i][k]=max(dr[i][k-1],dr[i+bit(k-1)][k-1]);
}
for(int i=1,x;i<=q;++i) {
cin>>op[i]>>ql[i]>>qr[i];
if(op[i]==1) {
if(ql[i]==qr[i]) LCA[fa[ql[i]]].push_back(i);
else LCA[fa[lca(qdl(ql[i],qr[i])+1,qdr(ql[i],qr[i]))]].push_back(i);
if(bel[ql[i]]==bel[qr[i]]) for(int u=ql[i];u<=qr[i];++u) add(F[i],u);
else wl[bel[ql[i]]].push_back(i),wr[bel[ql[i]]+1].push_back(i);
} else cin>>x,wx[x].push_back(i);
}
for(int o=1;o<=bel[n];++o) {
sort(wl[o].begin(),wl[o].end(),[&](int x,int y){ return ql[x]>ql[y]; });
sort(wr[o].begin(),wr[o].end(),[&](int x,int y){ return qr[x]<qr[y]; });
S.reset();
for(int i=lp[o],j=0,s=wr[o].size();j<s;++i) {
add(S,i);
while(j<s&&qr[wr[o][j]]==i) F[wr[o][j++]]|=S;
}
S.reset();
for(int i=rp[o],j=0,s=wl[o].size();j<s;--i) {
add(S,i);
while(j<s&&ql[wl[o][j]]==i) F[wl[o][j++]]|=S;
}
}
S.reset(),dfs1(1);
for(int i=1;i<=q;++i) F[i]^=F[i-1];
for(int i=2;i<=n;++i) if(!isc[i]) {
pr[++tot]=i;
for(int j=2*i;j<=n;j+=i) isc[j]=true;
}
S.reset();
for(int i=1;i<=n;++i) S[i]=z[g[i]=1];
dfs2(1,1,1);
for(int i=1;i<=q;++i) if(op[i]==2) {
int l=ql[i],r=qr[i];
F[i]>>=l,F[i]<<=(MAXN-(r-l+1));
int s=F[i].count();
cout<<(1ll*s*(X-1)+r-l+1)%Y<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 6ms
memory: 33312kb
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
Wrong Answer
time: 6ms
memory: 35912kb
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:
1 -> 37 1 -> 136 1 -> 155 1 -> 202 1 -> 359 1 -> 390 1 -> 439 1 -> 592 1 -> 646 1 -> 697 1 -> 746 1 -> 785 1 -> 828 1 -> 838 1 -> 869 1 -> 899 1 -> 905 1 -> 914 1 -> 928 1 -> 957 225 -> 214 215 -> 215 215 -> 384 432 -> 110 840 -> 109 840 -> 120 840 -> 162 840 -> 336 840 -> 377 840 -> 380 840 -> 393 ...
result:
wrong answer 1st lines differ - expected: '13621441', found: '1 -> 37'
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 534ms
memory: 677936kb
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:
28069 -> 24918 23425 -> 60464 5066 -> 30902 33319 -> 20983 12375 -> 62859 2662122 12263904 9988949 9098885 10661570 169420 12206075 11189204 12737561 19687277 3177635 12864425 16522132 8890301 19817862 19631288 14433359 4841805 15087340 13737927
result:
wrong answer 1st lines differ - expected: '2662122', found: '28069 -> 24918'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%