QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#353968#7839. 虹NATURAL60 520ms697152kbC++144.0kb2024-03-14 19:59:272024-03-14 19:59:27

Judging History

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

  • [2024-03-14 19:59:27]
  • 评测
  • 测评结果:0
  • 用时:520ms
  • 内存:697152kb
  • [2024-03-14 19:59:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int qread()
{
	int a=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){(a*=10)+=(ch^48);ch=getchar();}
	return a*f;
}
int n,m,a[80010],OP[80010],L[80010],R[80010],vis[80010];
int cl,c[80010],ed[80010];
int dep[80010],fa[80010],st[17][80010],F[17][80010],ST[17][80010];
int gcd[80010],P,pri[80010];
vector<int>e[80010],Q[80010],Qs[80010];
vector< pair<int,int> >pre[80010],suf[80010];
bitset<80001>S[80001],cx,Z;
inline int cmp(int x,int y){return dep[x]<dep[y]?x:y;}
inline void U(int x,int p)
{
	if(x==1)return ;
	for(int i=x;i<=n;i+=x)Z[i]=a[gcd[i]*=p]&1;
	return ;
}
inline void M(int x,int p)
{ 
	if(x==1)return ;
	for(int i=x;i<=n;i+=x)Z[i]=a[gcd[i]/=p]&1;
	return ;
}
inline void dfs(int x,int h)
{
	if(!vis[x])
	{
		for(int i:Qs[x])S[i]=Z;
		vis[x]=1;
	}
	if(h==P+1)return ;
	if(1ll*x*pri[h]>n)return ;
	for(long long y=1;1ll*x*y<=n;y*=pri[h])
	{
		U(y,pri[h]);
		dfs(x*y,h+1);
	}
	for(long long y=1;1ll*x*y<=n;y*=pri[h])M(y,pri[h]);
	return ;
}
inline void dfss(int rt,int da)
{
	dep[rt]=dep[da]+1;
	st[0][rt]=rt;fa[rt]=da;
	F[0][rt]=da;ST[0][rt]=rt;
	for(int i=1;i<=16;++i)F[i][rt]=F[i-1][F[i-1][rt]];
	for(int i:e[rt])
	{
		if(i==da)continue;
		dfss(i,rt);
	}
	return ;
}
inline int get_lca(int x,int y)
{
	if(!x||!y)return x|y;
	if(dep[x]<dep[y])swap(x,y);
	for(int i=16;~i;--i)while(dep[F[i][x]]>=dep[y])x=F[i][x];
	if(x==y)return x;
	for(int i=16;~i;--i)while(F[i][x]^F[i][y])x=F[i][x],y=F[i][y];
	return F[0][x];
}
inline void dfsss(int rt,int da)
{
	cx.set(rt);
	for(int i:Q[rt])S[i]=S[i]^cx;
	for(int i:e[rt])
	{
		if(i==da)continue;
		dfsss(i,rt);
	}
	cx.reset(rt);
	return ;
}
inline int get_min(int l,int r)
{
	int s=31-__builtin_clz(r-l+1);
	return cmp(st[s][l],st[s][r-(1<<s)+1]);
}
inline int get_range_lca(int l,int r)
{
	int s=31-__builtin_clz(r-l+1);
	return get_lca(ST[s][l],ST[s][r-(1<<s)+1]);
}
signed main()
{
	n=qread(),m=qread();
	cl=min(n,(int)sqrt(n)+1);
//	cl=n;
	for(int i=1;i<=n;++i)a[i]=qread(),ed[c[i]=(i-1)/cl+1]=i;
	for(int i=1,u,v;i<n;++i)
	{
		u=qread(),v=qread();
		e[u].emplace_back(v);
		e[v].emplace_back(u);
	}
	dfss(1,0);
	for(int i=1;i<=16;++i)for(int j=1;j+(1<<i)-1<=n;++j)
	{
		st[i][j]=cmp(st[i-1][j],st[i-1][j+(1<<(i-1))]);
		ST[i][j]=get_lca(ST[i-1][j],ST[i-1][j+(1<<(i-1))]);
	}
	for(int i=1;i<=m;++i)
	{
		OP[i]=qread();L[i]=qread();R[i]=qread();
		if(OP[i]==2)Qs[qread()].emplace_back(i);
		else
		{
			Q[fa[get_range_lca(L[i],R[i])]].emplace_back(i);
			if(c[L[i]]==c[R[i]])
			{
				cx.reset();
				for(int j=L[i],p;j<=R[i];++j)
				{
					p=j;
					while(!cx[p])cx.set(p),p=fa[p];
				}
				S[i]=cx;
			}
			else
			{
				pre[ed[c[L[i]]]].emplace_back(make_pair(L[i],i));
				suf[ed[c[L[i]]]].emplace_back(make_pair(R[i],i));
			}
		}
	}
	for(int I=1,i,lp,p;I<=c[n];++I)
	{
		i=ed[I];
		sort(pre[i].begin(),pre[i].end());
		sort(suf[i].begin(),suf[i].end());
		reverse(pre[i].begin(),pre[i].end());
		cx.reset();lp=p=i;
		while(!cx[p])cx.set(p),p=fa[p];
		for(pair<int,int>j:pre[i])
		{
			if(lp>j.first)
			{
				while(lp>j.first)
				{
					p=--lp;
					while(!cx[p])cx.set(p),p=fa[p];
				}
			}
			S[j.second]=S[j.second]|cx;
		}
		cx.reset();lp=p=i;
		while(!cx[p])cx.set(p),p=fa[p];
		for(pair<int,int>j:suf[i])
		{
			if(lp<j.first)
			{
				while(lp<j.first)
				{
					p=++lp;
					while(!cx[p])cx.set(p),p=fa[p];
				}
			}
			S[j.second]=S[j.second]|cx;
		}
	}
	cx.reset();
	dfsss(1,0);
	for(int i=2;i<=n;++i)
	{
		if(!vis[i])pri[++P]=i;
		for(int j=1;j<=P&&pri[j]*i<=n;++j)
		{
			vis[pri[j]*i]=1;
			if(i%pri[j]==0)break;
		}
	}
	for(int i=1;i<=n;++i)Z[i]=a[1]&1,vis[i]=0;
	dfs(1,1);
	cx.reset();
	for(int i=1,x;i<=m;++i)
	{
//		for(int j=1;j<=n;++j)cerr<<S[i][j];puts("");
		if(OP[i]==1)cx^=S[i];
		else 
		{
			x=(((cx&S[i])>>(L[i]-1))<<(80000-R[i]+L[i]-1)).count();
			printf("%lld\n",(1ll*19901991*x+(R[i]-L[i]+1-x))%20242024);
		}
	} 
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 40768kb

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:

138
17182328
21
153
363
689
763
16161736
3240463
316
6501168
159
469
8201402
913
204
19222108
1380891
553
368
523
10561863
240
656
234
65
62
13961591
11061743
426
12421418
437
195
423
382
13
201
18922317
19562341
19602871
18902292
158
100
18882291
115
75
2
14301752
670
45
12281721
449
114
698
100613...

result:

wrong answer 1st lines differ - expected: '16521790', found: '138'

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 520ms
memory: 697152kb

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:

1856
19904668
19909941
19579933
19242428
29406
19246779
8086
56293
45313
3857703
43143
480
9413
16557536
19571282
15493465
21323
19927824
14357989

result:

wrong answer 1st lines differ - expected: '2662122', found: '1856'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%