QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136164#4891. 树上的孤独1kri0 10ms65284kbC++144.3kb2023-08-07 14:45:082023-08-07 14:45:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-07 14:45:11]
  • 评测
  • 测评结果:0
  • 用时:10ms
  • 内存:65284kb
  • [2023-08-07 14:45:08]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cstring>
using namespace std;
int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	return x;
}
int n1,n2,m;
int o[1000005],a[1000005],b[1000005],c[1000005],d[1000005];
int qwq_col[25];
vector<int> qid[1000005];
int qwq[1000005][25],D[1000005][25];
struct Tree{
	int n,m,u[400005],v[400005],first[200005],nxt[400005];
	int col[200005];
	vector<int> e[200005];
	void add(int a,int b){
		int i=++m;
		u[i]=a,v[i]=b;
		nxt[i]=first[u[i]],first[u[i]]=i;
		return;
	}
	void get_e(int now,int fa){
		for (int i=first[now];i;i=nxt[i])
			if (v[i]!=fa){
				e[now].push_back(v[i]);
				get_e(v[i],now);
			}
		return;
	}
	void init(){
		get_e(1,0);
		return;
	}
	int dis[200005],head,tail,q[200005];
	vector<int> get_id(int x,int d){
		vector<int> qwq;
		for (int i=1;i<=n;i++)dis[i]=-1;
		dis[x]=0;
		head=tail=1;
		q[1]=x;
		while(head<=tail){
			int now=q[head];
			head++;
			qwq.push_back(now);
			if (dis[now]==d)continue;
			for (int i=0;i<(int)e[now].size();i++){
				dis[e[now][i]]=dis[now]+1;
				q[++tail]=e[now][i];
			}
		}
		return qwq;
	}
}T1,T2;
namespace DS_1{
	int book[200005];
	int ask(int x,int d){
		int ans=0;
		vector<int> id=T1.get_id(x,d);
		for (int i=0;i<(int)id.size();i++)
			if (book[T1.col[id[i]]]==0){
				ans++;
				book[T1.col[id[i]]]=1;
			}
		for (int i=0;i<(int)id.size();i++)book[T1.col[id[i]]]=0;
		return ans;
	}
}
namespace DS_2{
	int book[200005];
	int ask(int x,int d){
		int ans=0;
		vector<int> id=T2.get_id(x,d);
		for (int i=0;i<(int)id.size();i++)
			if (book[T2.col[id[i]]]==0){
				ans++;
				book[T2.col[id[i]]]=1;
			}
		for (int i=0;i<(int)id.size();i++)book[T2.col[id[i]]]=0;
		return ans;
	}
}
namespace DS_12{
	int depth[200005],sz[200005],son[200005];
	void dfs1(int now,int d){
		depth[now]=d,sz[now]=1,son[now]=0;
		for (int i=0;i<(int)T2.e[now].size();i++){
			int v=T2.e[now][i];
			dfs1(v,d+1);
			sz[now]+=sz[v];
			if (son[now]==0||sz[v]>sz[son[now]])son[now]=v;
		}
		return;
	}
	int mn[200005];
	int tot,sta[200005][2];
	void upd(int x,int y){
		++tot;
		sta[tot][0]=x,sta[tot][1]=mn[x];
		mn[x]=min(mn[x],y);
		return;
	}
	void dfs3(int now){
		upd(T2.col[now],depth[now]);
		for (int i=0;i<(int)T2.e[now].size();i++){
			int v=T2.e[now][i];
			dfs3(v);
		}
		return;
	}
	void dfs2(int now,int ish){
		int _tot=tot;
		for (int i=0;i<(int)T2.e[now].size();i++){
			int v=T2.e[now][i];
			if (v!=son[now])dfs2(v,0);
		}
		if (son[now]!=0)dfs2(son[now],1);
		upd(T2.col[now],depth[now]);		
		for (int i=0;i<(int)T2.e[now].size();i++){
			int v=T2.e[now][i];
			if (v!=son[now])dfs3(v);
		}
		for (int i=0;i<(int)qid[now].size();i++){
			int id=qid[now][i];
			for (int j=1;j<=T1.n;j++)D[id][j]=mn[qwq[id][j]]-depth[now];
		}
		if (ish==0){
			while(tot>_tot){
				mn[sta[tot][0]]=sta[tot][1];
				tot--;
			}
		}
		return;
	}
	void work(){
		dfs1(1,1);
		memset(mn,0x3f,sizeof(mn));
		dfs2(1,0);
		return;
	}
}
int book[200005];
int main(){
	n1=read(),n2=read(),m=read();
	T1.n=n1;
	for (int i=1;i<n1;i++){
		int u=read(),v=read();
		T1.add(u,v),T1.add(v,u);
	}
	T2.n=n2;
	for (int i=1;i<n2;i++){
		int u=read(),v=read();
		T2.add(u,v),T2.add(v,u);
	}
	for (int i=1;i<=n1;i++)T1.col[i]=read();
	for (int i=1;i<=n2;i++)T2.col[i]=read();
	T1.init(),T2.init();
	for (int i=1;i<=m;i++){
		o[i]=read();
		if (o[i]==1)a[i]=read(),b[i]=read(),c[i]=read(),d[i]=read();
		if (o[i]==2)a[i]=read(),b[i]=read();
	}
	for (int i=1;i<=T1.n;i++)qwq_col[i]=T1.col[i];
	for (int i=1;i<=m;i++){
		if (o[i]==1){
			qid[b[i]].push_back(i);
			for (int j=1;j<=T1.n;j++)qwq[i][j]=qwq_col[j];
		}
		else qwq_col[a[i]]=b[i];
	}
	DS_12::work();
	int lt=0;
	for (int i=1;i<=m;i++){
		if (o[i]==1){
			c[i]^=lt,d[i]^=lt;
			lt=DS_1::ask(a[i],c[i])+DS_2::ask(b[i],d[i]);
			vector<int> id=T1.get_id(b[i],d[i]);
			for (int j=0;j<(int)id.size();j++){
				if (book[T1.col[id[j]]]==1)continue;
				book[T1.col[id[j]]]=1;
				if (D[i][id[j]]<=d[i])lt--;
			}
			for (int j=0;j<(int)id.size();j++)book[T1.col[id[j]]]=0;
			printf("%d\n",lt);
		}
		else T1.col[a[i]]=b[i];
	}
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 10ms
memory: 65284kb

input:

20 2000 2000
8 15
8 13
14 8
14 7
12 14
12 1
9 13
9 4
5 9
5 10
2 5
2 19
6 19
6 16
11 7
11 20
18 2
18 17
3 6
1395 1783
1395 1735
1735 457
457 739
739 438
438 101
101 441
441 1879
1879 1238
1238 501
501 1732
1732 1910
1910 2000
2000 834
834 917
917 111
111 780
780 1966
1966 1604
1604 623
623 1748
1748 ...

output:

105
93
2
44
18
55
210
24
69
20
22
210
71
93
137
33
71
71
56
44
21
10
24
83
63
100
27
218
41
75
103
21
93
35
216
69
29
49
10
19
57
62
24
5
109
157
23
21
14
110
44
115
26
82
163
93
29
147
144
8
137
32
113
150
130
71
35
68
17
45
56
50
59
14
36
148
117
148
156
204
22
89
79
26
72
25
28
40
164
54
62
53
10...

result:

wrong answer 5th numbers differ - expected: '19', found: '18'

Subtask #2:

score: 0
Time Limit Exceeded

Test #3:

score: 0
Time Limit Exceeded

input:

20 200000 500000
8 18
8 4
2 4
2 14
13 4
13 16
6 4
6 3
1 4
1 17
15 6
15 19
7 17
7 11
5 14
5 10
20 7
12 15
9 8
165302 77239
165302 198189
165302 180850
165302 192738
165302 173589
165302 194087
165302 191990
165302 167370
165302 101092
165302 92553
165302 163654
165302 122381
165302 152105
165302 1919...

output:

2
17597
3899
3423
15
517
5138
11355
21
7340
20
18347
15774
6643
513
1183
6110
1889
6246
662
16737
13243
1597
5445
6078
2387
6265
2
21
282
3516
1807
1236
1038
17821
4658
5539
4632
4547
20
243
2703
1
4609
8577
3970
20
13498
5650
2054
3489
4869
5828
801
2071
1495
13231
2595
938
16769
2
17623
354
5
21
7...

result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #7:

score: 0
Time Limit Exceeded

input:

20 100000 100000
16 12
16 20
6 12
6 18
2 16
2 8
5 20
5 13
3 6
3 11
19 11
19 17
9 12
9 15
4 15
4 7
10 5
14 15
14 1
85812 94626
85812 91172
91172 93788
93788 96567
96567 75524
75524 23275
23275 98340
98340 81608
81608 91480
91480 75108
75108 56605
56605 93317
93317 41617
41617 77160
77160 727
727 7559...

output:

2568
611
8348
9003
3568
9199
699
300
2479
7309
2687
1172
1402
1269
8228
4412
108
2698
640
4485
3171
9201
20
8996
2092
9950
8021
9944
20
5042
89
2041
1880
18
1294
2184
335
1093
9386
3480
7726
1956
2741
1259
2334
716
20
545
20
447
698
2337
498
18
37
1423
2324
692
2466
20
2319
715
10018
7
183
1365
8952...

result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #13:

score: 0
Time Limit Exceeded

input:

1 200000 500000
189127 137023
189127 199761
199761 160701
160701 130639
130639 190908
190908 176819
176819 193363
193363 188021
188021 182446
182446 186028
186028 198828
198828 190792
190792 155378
155378 189428
189428 177276
177276 146159
146159 175923
175923 188073
188073 182206
182206 131072
1310...

output:

3781
1772
770
7328
18160
19394
1951
1
5498
1
2861
3368
7392
5130
5706
1
5996
19866
1
5123
1
12549
1496
4836
7770
16333
18175
5925
17983
19707
3820
17709
17093
4225
3823
575
5637
3659
4971
15672
1
18776
28
5066
16605
2275
16601
4545
597
841
19976
7054
881
163
2743
1682
6748
5090
1631
5108
2930
2777
1...

result:


Subtask #5:

score: 0
Time Limit Exceeded

Test #15:

score: 0
Time Limit Exceeded

input:

20 200000 1000000
13 10
13 5
19 5
19 20
15 10
15 6
12 6
12 3
8 10
8 2
1 20
1 11
14 10
14 16
18 3
18 7
4 3
9 10
9 17
194055 154514
194055 148156
148156 115271
115271 198116
198116 179433
179433 171975
171975 196600
196600 167194
167194 185078
185078 191409
191409 163496
163496 178243
178243 154093
15...

output:

459
5820
10128
7655
4898
19496
3578
16029
2834
7537
1130
9930
18498
498
11889
2115
9858
7579
7286
110
1853
7398
3350
6103
19507
16464
6208
1724
5926
5597
3822
1918
717
3321
2716
19896
5600
633
752
1300
16010
2974
1673
14673
5223
2646
117
1895
3267
1937
14604
4577
7218
5910
11044
4391
7462
9759
19651...

result: