QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#564900#8950. 树据结构Kevin5307#16 755ms372996kbC++232.7kb2024-09-15 16:53:082024-09-15 16:53:09

Judging History

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

  • [2024-09-15 16:53:09]
  • 评测
  • 测评结果:16
  • 用时:755ms
  • 内存:372996kb
  • [2024-09-15 16:53:08]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n,q;
int p[100100],d[100100],c[100100],maxd;
int op[100100],x[100100],y[100100];
int po[100100],tot;
int in[100100][455],out[100100][455];
int ans[100100];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	for(int i=2;i<=n;i++)
		cin>>p[i];
	for(int i=1;i<=n;i++)
	{
		d[i]=d[p[i]]+1;
		c[d[i]]++;
	}
	maxd=*max_element(d+1,d+n+1);
	for(int i=1;i<=q;i++)
	{
		cin>>op[i];
		if(op[i]==1)
			cin>>x[i]>>y[i];
	}
	for(int i=1;i<=maxd;i++)
		if(c[i]!=c[i-1])
			po[++tot]=i;
	po[++tot]=maxd+1;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=tot;j++)
			in[i][j]=inf;
	for(int i=n;i>=1;i--)
	{
		for(int j=1;j<=tot;j++)
			if(po[j]==d[i])
				in[i][j]=out[i][j]=i;
		if(i>1)
			for(int j=1;j<=tot;j++)
			{
				in[p[i]][j]=min(in[p[i]][j],in[i][j]);
				out[p[i]][j]=max(out[p[i]][j],out[i][j]);
			}
	}
	for(int i=1;i<tot;i++)
	{
		int C=c[po[i]];
		vector<vector<int>> delta((n+n)/C+1);
		for(auto &vd:delta)
			vd.resize(C+1);
		int rot=0;
		for(int j=1;j<=q;j++)
			if(op[j]==2)
				rot=(rot+1)%n;
			else
			{
				int u=x[j],val=y[j];
				if(d[u]>=po[i+1])
					continue;
				int st=in[u][i]-1,nd=out[u][i]-1;
				int layer=po[i+1]-po[i];
				if(d[u]>po[i])
				{
					st=nd=u-1;
					layer=po[i+1]-d[u];
				}
				st=(st+n-rot)%n;
				nd=(nd+n-rot)%n;
				if(st/C==nd/C)
				{
					delta[st/C][st%C]+=val;
					delta[st/C][nd%C+1]-=val;
					delta[st/C+layer][st%C]-=val;
					delta[st/C+layer][nd%C+1]+=val;
				}
				else
				{
					delta[st/C][st%C]+=val;
					delta[nd/C][0]+=val;
					delta[nd/C][nd%C+1]-=val;
					delta[st/C+layer][st%C]-=val;
					delta[nd/C+layer][0]-=val;
					delta[nd/C+layer][nd%C+1]+=val;
				}
			}
		for(int i=1;i<sz(delta);i++)
			for(int j=0;j<sz(delta[i]);j++)
				delta[i][j]+=delta[i-1][j];
		for(int i=0;i<sz(delta);i++)
		{
			for(int j=1;j<sz(delta[i]);j++)
				delta[i][j]+=delta[i][j-1];
			for(int j=0;j<C;j++)
				ans[(i*C+j)%n]+=delta[i][j];
		}
	}
	int tot=0;
	for(int i=0;i<n;i++)
		tot^=ans[i];
	cout<<tot<<endl;
	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: 3ms
memory: 9872kb

input:

994 980
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 88 89 90 91 92 93 94 95 96 97 9...

output:

1815245

result:

wrong answer 1st lines differ - expected: '1003408', found: '1815245'

Subtask #2:

score: 8
Accepted

Test #13:

score: 8
Accepted
time: 641ms
memory: 365196kb

input:

98132 98277
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

188162172

result:

ok single line: '188162172'

Test #14:

score: 8
Accepted
time: 686ms
memory: 371352kb

input:

99751 99440
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

169515090

result:

ok single line: '169515090'

Test #15:

score: 8
Accepted
time: 631ms
memory: 370480kb

input:

99609 98360
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

412537241

result:

ok single line: '412537241'

Test #16:

score: 8
Accepted
time: 751ms
memory: 368448kb

input:

98363 99114
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

183252481

result:

ok single line: '183252481'

Test #17:

score: 8
Accepted
time: 715ms
memory: 368696kb

input:

98704 99147
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

120152794

result:

ok single line: '120152794'

Test #18:

score: 8
Accepted
time: 755ms
memory: 367244kb

input:

98020 99452
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

162858889

result:

ok single line: '162858889'

Test #19:

score: 8
Accepted
time: 611ms
memory: 372560kb

input:

99584 98111
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

159936259

result:

ok single line: '159936259'

Test #20:

score: 8
Accepted
time: 673ms
memory: 370832kb

input:

99368 99321
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

174561123

result:

ok single line: '174561123'

Test #21:

score: 8
Accepted
time: 642ms
memory: 368648kb

input:

98465 99667
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

381178251

result:

ok single line: '381178251'

Test #22:

score: 8
Accepted
time: 595ms
memory: 368180kb

input:

98881 98689
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

19190818

result:

ok single line: '19190818'

Test #23:

score: 8
Accepted
time: 680ms
memory: 365604kb

input:

98155 98945
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

22837713

result:

ok single line: '22837713'

Test #24:

score: 8
Accepted
time: 68ms
memory: 370792kb

input:

99058 99670
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

208248759

result:

ok single line: '208248759'

Subtask #3:

score: 8
Accepted

Test #25:

score: 8
Accepted
time: 39ms
memory: 371576kb

input:

98694 98643
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

1233260

result:

ok single line: '1233260'

Test #26:

score: 8
Accepted
time: 44ms
memory: 370576kb

input:

99200 99039
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

16711663

result:

ok single line: '16711663'

Test #27:

score: 8
Accepted
time: 31ms
memory: 368492kb

input:

98478 99308
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

56434171

result:

ok single line: '56434171'

Test #28:

score: 8
Accepted
time: 53ms
memory: 369064kb

input:

98176 98655
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

64451660

result:

ok single line: '64451660'

Test #29:

score: 8
Accepted
time: 51ms
memory: 369976kb

input:

99264 98305
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

8074498

result:

ok single line: '8074498'

Test #30:

score: 8
Accepted
time: 39ms
memory: 369308kb

input:

98217 99102
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

230402545

result:

ok single line: '230402545'

Test #31:

score: 8
Accepted
time: 43ms
memory: 370324kb

input:

98380 98622
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

462226140

result:

ok single line: '462226140'

Test #32:

score: 8
Accepted
time: 48ms
memory: 371704kb

input:

99576 99220
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

315932215

result:

ok single line: '315932215'

Test #33:

score: 8
Accepted
time: 31ms
memory: 371736kb

input:

99549 98210
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

166790458

result:

ok single line: '166790458'

Test #34:

score: 8
Accepted
time: 28ms
memory: 371228kb

input:

98893 99868
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

179140940

result:

ok single line: '179140940'

Test #35:

score: 8
Accepted
time: 44ms
memory: 371296kb

input:

99409 98962
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

228593512

result:

ok single line: '228593512'

Test #36:

score: 8
Accepted
time: 28ms
memory: 372996kb

input:

99988 98174
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

116635119

result:

ok single line: '116635119'

Subtask #4:

score: 0
Wrong Answer

Test #37:

score: 0
Wrong Answer
time: 47ms
memory: 246924kb

input:

65535 98062
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...

output:

3811181

result:

wrong answer 1st lines differ - expected: '5623100', found: '3811181'

Subtask #5:

score: 0
Wrong Answer

Test #49:

score: 13
Accepted
time: 107ms
memory: 372764kb

input:

99562 98687
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

9056060

result:

ok single line: '9056060'

Test #50:

score: 0
Wrong Answer
time: 84ms
memory: 371584kb

input:

99213 98116
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

415481713

result:

wrong answer 1st lines differ - expected: '424634871', found: '415481713'

Subtask #6:

score: 0
Wrong Answer

Test #61:

score: 0
Wrong Answer
time: 218ms
memory: 190380kb

input:

49861 49257
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

150797903

result:

wrong answer 1st lines differ - expected: '150839800', found: '150797903'

Subtask #7:

score: 0
Wrong Answer

Test #73:

score: 0
Wrong Answer
time: 669ms
memory: 369280kb

input:

98390 98942
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 ...

output:

4951276

result:

wrong answer 1st lines differ - expected: '5600403', found: '4951276'