QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561479#7839. 虹DaiRuiChen0070 580ms678036kbC++172.9kb2024-09-12 22:57:512024-09-12 22:57:51

Judging History

你现在查看的是最新测评结果

  • [2024-09-12 22:57:51]
  • 评测
  • 测评结果:0
  • 用时:580ms
  • 内存:678036kb
  • [2024-09-12 22:57:51]
  • 提交

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;
	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) {
			LCA[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<=n;++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>=lp[o];--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: 0
Wrong Answer
time: 11ms
memory: 29548kb

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 404th lines differ - expected: '15661762', found: '16001796'

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 580ms
memory: 678036kb

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
10328983
8758851
10321536
169420
11866041
11189204
12737561
19347243
2837601
12524391
16522132
8890301
19477828
19631288
14433359
4501771
15087340
13397893

result:

wrong answer 3rd lines differ - expected: '9988949', found: '10328983'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%