QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#290917#7839. 虹zhouhuanyi0 731ms64860kbC++203.7kb2023-12-25 20:47:442023-12-25 20:47:45

Judging History

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

  • [2023-12-25 20:47:45]
  • 评测
  • 测评结果:0
  • 用时:731ms
  • 内存:64860kb
  • [2023-12-25 20:47:44]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#define N 80000
#define M 512
using namespace std;
const int sz=512;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int n,q,sl,sr,leng,block[N+1],depth[N+1],ans[N+1],lg[N+1],st[N+1],tong[N+1],length,op[N+1],l[N+1],r[N+1],u[N+1],fa[N+1][21];
bool z[N+1],nprime[N+1],used[N+1];
vector<int>E[N+1];
vector<int>p[N+1];
bitset<M+1>B[N+1];
bitset<M+1>S[N+1];
bitset<M+1>rst;
bitset<M+1>dst;
bitset<M+1>DP[M+1][M+1];
bitset<M+1>delta[N+1];
bitset<M+1>delta2[N+1];
bitset<M+1>num[N+1];
void add(int x,int y)
{
	E[x].push_back(y),E[y].push_back(x);
	return;
}
void dfs(int x)
{
	st[++leng]=x,used[x]=1;
	for (int i=0;i<E[x].size();++i)
		if (!used[E[x][i]])
			depth[E[x][i]]=depth[x]+1,fa[E[x][i]][0]=x,dfs(E[x][i]);
	return;
}
int lca(int x,int y)
{
	if (depth[x]>depth[y]) swap(x,y);
	for (int i=lg[n];i>=0;--i)
		if (depth[fa[x][i]]>=depth[y])
			x=fa[x][i];
	if (x==y) return x;
	for (int i=lg[n];i>=0;--i)
		if (fa[x][i]!=fa[y][i])
			x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
bitset<M+1>query(int l,int r)
{
	if (l<=sl&&sr<=r) return dst;
	else if (l==r)
	{
		bitset<M+1>res;
		res[l]=1;
		return res;
	}
	else if (block[l+1]==block[r])
	{
		bitset<M+1>res;
		for (int i=l+1;i<=r;++i) res|=S[i];
		return res;
	}
	else if (block[l+1]+1==block[r]) return delta[l+1]|delta2[r];
	else return delta[l+1]|DP[block[l+1]+1][block[r]-1]|delta2[r];
}
int main()
{
	int x,y,szt;
	n=read(),q=read(),szt=sqrt(n);
	for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
	for (int i=1;i<=n;++i) z[i]=read()&1,block[i]=(i-1)/szt+1;
	for (int i=1;i<=n-1;++i) x=read(),y=read(),add(x,y);
	depth[1]=1,dfs(1);
	for (int i=1;i<=lg[n];++i)
		for (int j=1;j<=n;++j)
			fa[j][i]=fa[fa[j][i-1]][i-1];
	for (int i=2;i<=n;++i) l[i]=lca(i-1,i);
	for (int i=1;i<=q;++i)
	{
		op[i]=read();
		if (op[i]==1) l[i]=read(),r[i]=read();
		else l[i]=read(),r[i]=read(),u[i]=read();
	}
	for (int i=1;i<=n;++i)
		for (int j=i;j<=n;j+=i)
			p[j].push_back(i);
	for (int i=2;i<=n;++i)
		if (!nprime[i])
		{
			tong[++length]=i;
			for (int j=(i<<1);j<=n;j+=i) nprime[j]=1;
		}
	for (int i=1;i<=n;++i)
		for (int j=(i<<1);j<=n;j+=i)
			z[j]^=z[i];
	for (int i=1;i<=n;i+=sz)
	{
		sl=i,sr=min(i+sz-1,n),rst.reset(),dst.reset();
		for (int j=sl;j<=sr;++j) dst[j-sl]=1;
		for (int j=1;j<=n;++j) B[j].reset();
		for (int j=1;j<=block[n];++j)
			for (int k=1;k<=block[n];++k)
				DP[j][k].reset();
		for (int j=sl;j<=sr;++j)
			for (int k=0;k<p[j].size();++k)
				B[p[j][k]][j-i]=1;
		for (int j=1;j<=length;++j)
			for (int k=1;k<=n/tong[j];++k)
				B[k*tong[j]]^=B[k];
		for (int j=1;j<=n;++j)
		{
			S[j]=S[fa[j][0]];
			if (sl<=j&&j<=sr) S[j][j-i]=1;
		}
		for (int j=n;j>=2;--j) S[j]^=S[j-1];
		for (int j=2;j<=n;++j) S[j][l[j]]=1;
		for (int j=1;j<=n;++j) delta[j]=delta2[j]=S[j],DP[block[j]][block[j]]=DP[block[j]][block[j]]|S[j];
		for (int j=n-1;j>=1;--j)
			if (block[j]==block[j+1])
				delta[j]|=delta[j+1];
		for (int j=2;j<=n;++j)
			if (block[j]==block[j-1])
				delta2[j]|=delta2[j-1];
		for (int j=1;j<=block[n];++j)
			for (int k=j+1;k<=block[n];++k)
				DP[j][k]=DP[j][k-1]|DP[k][k];
		num[sl-1].reset();
		for (int j=sl;j<=sr;++j) num[j]=num[j-1],num[j][j-sl]=1;
		for (int j=1;j<=q;++j)
		{
			if (op[j]==1) rst^=query(l[j],r[j]);
			else if (l[j]<=sl&&sr<=r[j]) ans[j]+=B[u[j]].count();
			else if (max(l[j],sl)<=min(r[j],sr)) ans[j]+=(B[u[j]]&(num[min(r[j],sr)]^num[max(l[j],sl)-1])).count();
		}
	}
	for (int i=1;i<=q;++i)
		if (op[i]==2)
			printf("%lld\n",(19901990ll*ans[i]+r[i]-l[i]+1)%20242024);
	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: 5ms
memory: 24764kb

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:

7320870
17942404
18201841
20082161
9741337
18602549
12482011
3760496
13461485
19762292
6381156
13281487
540523
5541136
9261839
14141618
3600546
5561309
3460899
7681136
2080731
7101517
2400480
13141970
6820916
3580423
6980760
14661661
8261463
18082234
7000876
13641801
4440639
6341057
10061388
1820183...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 731ms
memory: 64860kb

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:

12483104
4903168
3288279
9578933
3920896
13470750
8805735
16189704
17138001
6645973
2397557
18484987
8361316
8830295
16197500
9830308
8872803
17483069
6466478
7357289

result:

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

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%