Submission #342010

# Submission time Handle Problem Language Result Execution time Memory
342010 2021-01-01T02:52:59 Z wwdd Birthday gift (IZhO18_treearray) C++14
100 / 100
1233 ms 79072 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
const int MN = 200200;
const int LOG = 18;
vvi g;
int pa[MN][LOG];
int dord;
int en[MN],ex[MN];
void dfs(int u, int p) {
	en[u] = dord;dord++;
	pa[u][0] = p;
	for(int i=0;i<g[u].size();i++) {
		int v = g[u][i];
		if(v == p) {continue;}
		dfs(v,u);
	}
	ex[u] = dord;dord++;
}
void proc() {
	dord = 0;
	dfs(0,0);
	for(int j=1;j<LOG;j++) {
		for(int i=0;i<g.size();i++) {
			pa[i][j] = pa[pa[i][j-1]][j-1];
		}
	}
}
bool anc(int a, int b) {
	return en[a] <= en[b] && ex[a] >= ex[b];
}
int lca(int a, int b) {
	if(anc(a,b)) {return a;}
	if(anc(b,a)) {return b;}
	for(int i=LOG-1;i>=0;i--) {
		if(!anc(pa[a][i],b)) {a = pa[a][i];}
	}
	return pa[a][0];
}
vi wa;
set<int> sa[MN],da[MN];
void up(int idx, int u) {
	sa[wa[idx]].erase(idx);
	if(idx < wa.size()-1) {
		int ol = lca(wa[idx],wa[idx+1]);
		da[ol].erase(idx);
		int nl = lca(u,wa[idx+1]);
		da[nl].insert(idx);
	}
	if(idx > 0) {
		int ol = lca(wa[idx-1],wa[idx]);
		da[ol].erase(idx-1);
		int nl = lca(u,wa[idx-1]);
		da[nl].insert(idx-1);
	}
	wa[idx] = u;
	sa[u].insert(idx);
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	ll n,m,q;
	cin >> n >> m >> q;
	g.assign(n,vi());
	for(int i=1;i<n;i++) {
		ll a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	proc();
	for(int i=0;i<m;i++) {
		ll t;
		cin >> t;
		t--;
		wa.push_back(t);
		sa[t].insert(i);
	}
	for(int i=0;i<m-1;i++) {
		da[(lca(wa[i],wa[i+1]))].insert(i);
	}
	while(q--) {
		ll op;
		cin >> op;
		if(op == 1) {
			ll id, u;
			cin >> id >> u;
			id--;u--;
			up(id,u);
		} else {
			ll l,r,u;
			cin >> l >> r >> u;
			l--;r--;u--;
			auto sal = (sa[u].lower_bound(l));
			auto dal = (da[u].lower_bound(l));
			ii ans = {-1,-1};
			if(sal != sa[u].end() && *sal <= r) {
				ll re = *sal;
				ans = {re+1,re+1};
			}
			if(dal != da[u].end() && *dal <= r-1) {
				ll re = *dal;
				ans = {re+1,re+2};
			}
			cout << ans.first << " " << ans.second << '\n';
		}
	}
}

Compilation message

treearray.cpp: In function 'void dfs(int, int)':
treearray.cpp:16:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for(int i=0;i<g[u].size();i++) {
      |              ~^~~~~~~~~~~~
treearray.cpp: In function 'void proc()':
treearray.cpp:27:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |   for(int i=0;i<g.size();i++) {
      |               ~^~~~~~~~~
treearray.cpp: In function 'void up(int, int)':
treearray.cpp:47:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  if(idx < wa.size()-1) {
      |     ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19180 KB n=5
2 Correct 12 ms 19180 KB n=100
3 Correct 12 ms 19180 KB n=100
4 Correct 12 ms 19180 KB n=100
5 Correct 12 ms 19180 KB n=100
6 Correct 12 ms 19180 KB n=100
7 Correct 12 ms 19180 KB n=100
8 Correct 12 ms 19180 KB n=100
9 Correct 12 ms 19180 KB n=100
10 Correct 12 ms 19180 KB n=100
11 Correct 12 ms 19180 KB n=100
12 Correct 12 ms 19180 KB n=100
13 Correct 12 ms 19200 KB n=100
14 Correct 12 ms 19180 KB n=100
15 Correct 12 ms 19180 KB n=100
16 Correct 12 ms 19180 KB n=100
17 Correct 12 ms 19180 KB n=100
18 Correct 12 ms 19180 KB n=100
19 Correct 12 ms 19180 KB n=100
20 Correct 12 ms 19180 KB n=100
21 Correct 12 ms 19180 KB n=100
22 Correct 12 ms 19180 KB n=100
23 Correct 12 ms 19180 KB n=100
24 Correct 12 ms 19180 KB n=100
25 Correct 12 ms 19180 KB n=100
26 Correct 12 ms 19180 KB n=12
27 Correct 12 ms 19180 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19180 KB n=5
2 Correct 12 ms 19180 KB n=100
3 Correct 12 ms 19180 KB n=100
4 Correct 12 ms 19180 KB n=100
5 Correct 12 ms 19180 KB n=100
6 Correct 12 ms 19180 KB n=100
7 Correct 12 ms 19180 KB n=100
8 Correct 12 ms 19180 KB n=100
9 Correct 12 ms 19180 KB n=100
10 Correct 12 ms 19180 KB n=100
11 Correct 12 ms 19180 KB n=100
12 Correct 12 ms 19180 KB n=100
13 Correct 12 ms 19200 KB n=100
14 Correct 12 ms 19180 KB n=100
15 Correct 12 ms 19180 KB n=100
16 Correct 12 ms 19180 KB n=100
17 Correct 12 ms 19180 KB n=100
18 Correct 12 ms 19180 KB n=100
19 Correct 12 ms 19180 KB n=100
20 Correct 12 ms 19180 KB n=100
21 Correct 12 ms 19180 KB n=100
22 Correct 12 ms 19180 KB n=100
23 Correct 12 ms 19180 KB n=100
24 Correct 12 ms 19180 KB n=100
25 Correct 12 ms 19180 KB n=100
26 Correct 12 ms 19180 KB n=12
27 Correct 12 ms 19180 KB n=100
28 Correct 13 ms 19308 KB n=500
29 Correct 12 ms 19308 KB n=500
30 Correct 13 ms 19308 KB n=500
31 Correct 13 ms 19328 KB n=500
32 Correct 13 ms 19308 KB n=500
33 Correct 13 ms 19308 KB n=500
34 Correct 13 ms 19308 KB n=500
35 Correct 12 ms 19328 KB n=500
36 Correct 13 ms 19308 KB n=500
37 Correct 13 ms 19308 KB n=500
38 Correct 12 ms 19308 KB n=500
39 Correct 13 ms 19308 KB n=500
40 Correct 13 ms 19328 KB n=500
41 Correct 13 ms 19308 KB n=500
42 Correct 13 ms 19436 KB n=500
43 Correct 13 ms 19308 KB n=500
44 Correct 13 ms 19308 KB n=500
45 Correct 13 ms 19308 KB n=500
46 Correct 12 ms 19308 KB n=500
47 Correct 12 ms 19308 KB n=500
48 Correct 13 ms 19308 KB n=500
49 Correct 12 ms 19308 KB n=500
50 Correct 13 ms 19308 KB n=500
51 Correct 13 ms 19308 KB n=500
52 Correct 13 ms 19308 KB n=500
53 Correct 13 ms 19308 KB n=500
54 Correct 12 ms 19308 KB n=500
55 Correct 12 ms 19308 KB n=278
56 Correct 13 ms 19308 KB n=500
57 Correct 12 ms 19308 KB n=500
58 Correct 12 ms 19308 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19180 KB n=5
2 Correct 12 ms 19180 KB n=100
3 Correct 12 ms 19180 KB n=100
4 Correct 12 ms 19180 KB n=100
5 Correct 12 ms 19180 KB n=100
6 Correct 12 ms 19180 KB n=100
7 Correct 12 ms 19180 KB n=100
8 Correct 12 ms 19180 KB n=100
9 Correct 12 ms 19180 KB n=100
10 Correct 12 ms 19180 KB n=100
11 Correct 12 ms 19180 KB n=100
12 Correct 12 ms 19180 KB n=100
13 Correct 12 ms 19200 KB n=100
14 Correct 12 ms 19180 KB n=100
15 Correct 12 ms 19180 KB n=100
16 Correct 12 ms 19180 KB n=100
17 Correct 12 ms 19180 KB n=100
18 Correct 12 ms 19180 KB n=100
19 Correct 12 ms 19180 KB n=100
20 Correct 12 ms 19180 KB n=100
21 Correct 12 ms 19180 KB n=100
22 Correct 12 ms 19180 KB n=100
23 Correct 12 ms 19180 KB n=100
24 Correct 12 ms 19180 KB n=100
25 Correct 12 ms 19180 KB n=100
26 Correct 12 ms 19180 KB n=12
27 Correct 12 ms 19180 KB n=100
28 Correct 13 ms 19308 KB n=500
29 Correct 12 ms 19308 KB n=500
30 Correct 13 ms 19308 KB n=500
31 Correct 13 ms 19328 KB n=500
32 Correct 13 ms 19308 KB n=500
33 Correct 13 ms 19308 KB n=500
34 Correct 13 ms 19308 KB n=500
35 Correct 12 ms 19328 KB n=500
36 Correct 13 ms 19308 KB n=500
37 Correct 13 ms 19308 KB n=500
38 Correct 12 ms 19308 KB n=500
39 Correct 13 ms 19308 KB n=500
40 Correct 13 ms 19328 KB n=500
41 Correct 13 ms 19308 KB n=500
42 Correct 13 ms 19436 KB n=500
43 Correct 13 ms 19308 KB n=500
44 Correct 13 ms 19308 KB n=500
45 Correct 13 ms 19308 KB n=500
46 Correct 12 ms 19308 KB n=500
47 Correct 12 ms 19308 KB n=500
48 Correct 13 ms 19308 KB n=500
49 Correct 12 ms 19308 KB n=500
50 Correct 13 ms 19308 KB n=500
51 Correct 13 ms 19308 KB n=500
52 Correct 13 ms 19308 KB n=500
53 Correct 13 ms 19308 KB n=500
54 Correct 12 ms 19308 KB n=500
55 Correct 12 ms 19308 KB n=278
56 Correct 13 ms 19308 KB n=500
57 Correct 12 ms 19308 KB n=500
58 Correct 12 ms 19308 KB n=500
59 Correct 16 ms 19692 KB n=2000
60 Correct 15 ms 19692 KB n=2000
61 Correct 15 ms 19820 KB n=2000
62 Correct 16 ms 19692 KB n=2000
63 Correct 16 ms 19692 KB n=2000
64 Correct 16 ms 19692 KB n=2000
65 Correct 16 ms 19692 KB n=2000
66 Correct 15 ms 19692 KB n=2000
67 Correct 16 ms 19692 KB n=2000
68 Correct 15 ms 19692 KB n=2000
69 Correct 15 ms 19692 KB n=2000
70 Correct 15 ms 19692 KB n=2000
71 Correct 15 ms 19692 KB n=2000
72 Correct 15 ms 19692 KB n=2000
73 Correct 14 ms 19692 KB n=2000
74 Correct 15 ms 19564 KB n=1844
75 Correct 16 ms 19692 KB n=2000
76 Correct 17 ms 19584 KB n=2000
77 Correct 16 ms 19692 KB n=2000
78 Correct 18 ms 19692 KB n=2000
79 Correct 17 ms 19692 KB n=2000
80 Correct 15 ms 19692 KB n=2000
81 Correct 15 ms 19692 KB n=2000
82 Correct 16 ms 19692 KB n=2000
83 Correct 15 ms 19692 KB n=2000
84 Correct 16 ms 19692 KB n=2000
85 Correct 15 ms 19692 KB n=2000
86 Correct 16 ms 19692 KB n=2000
87 Correct 16 ms 19692 KB n=2000
88 Correct 14 ms 19692 KB n=2000
89 Correct 16 ms 19820 KB n=2000
90 Correct 15 ms 19692 KB n=2000
91 Correct 15 ms 19692 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19180 KB n=5
2 Correct 12 ms 19180 KB n=100
3 Correct 12 ms 19180 KB n=100
4 Correct 12 ms 19180 KB n=100
5 Correct 12 ms 19180 KB n=100
6 Correct 12 ms 19180 KB n=100
7 Correct 12 ms 19180 KB n=100
8 Correct 12 ms 19180 KB n=100
9 Correct 12 ms 19180 KB n=100
10 Correct 12 ms 19180 KB n=100
11 Correct 12 ms 19180 KB n=100
12 Correct 12 ms 19180 KB n=100
13 Correct 12 ms 19200 KB n=100
14 Correct 12 ms 19180 KB n=100
15 Correct 12 ms 19180 KB n=100
16 Correct 12 ms 19180 KB n=100
17 Correct 12 ms 19180 KB n=100
18 Correct 12 ms 19180 KB n=100
19 Correct 12 ms 19180 KB n=100
20 Correct 12 ms 19180 KB n=100
21 Correct 12 ms 19180 KB n=100
22 Correct 12 ms 19180 KB n=100
23 Correct 12 ms 19180 KB n=100
24 Correct 12 ms 19180 KB n=100
25 Correct 12 ms 19180 KB n=100
26 Correct 12 ms 19180 KB n=12
27 Correct 12 ms 19180 KB n=100
28 Correct 13 ms 19308 KB n=500
29 Correct 12 ms 19308 KB n=500
30 Correct 13 ms 19308 KB n=500
31 Correct 13 ms 19328 KB n=500
32 Correct 13 ms 19308 KB n=500
33 Correct 13 ms 19308 KB n=500
34 Correct 13 ms 19308 KB n=500
35 Correct 12 ms 19328 KB n=500
36 Correct 13 ms 19308 KB n=500
37 Correct 13 ms 19308 KB n=500
38 Correct 12 ms 19308 KB n=500
39 Correct 13 ms 19308 KB n=500
40 Correct 13 ms 19328 KB n=500
41 Correct 13 ms 19308 KB n=500
42 Correct 13 ms 19436 KB n=500
43 Correct 13 ms 19308 KB n=500
44 Correct 13 ms 19308 KB n=500
45 Correct 13 ms 19308 KB n=500
46 Correct 12 ms 19308 KB n=500
47 Correct 12 ms 19308 KB n=500
48 Correct 13 ms 19308 KB n=500
49 Correct 12 ms 19308 KB n=500
50 Correct 13 ms 19308 KB n=500
51 Correct 13 ms 19308 KB n=500
52 Correct 13 ms 19308 KB n=500
53 Correct 13 ms 19308 KB n=500
54 Correct 12 ms 19308 KB n=500
55 Correct 12 ms 19308 KB n=278
56 Correct 13 ms 19308 KB n=500
57 Correct 12 ms 19308 KB n=500
58 Correct 12 ms 19308 KB n=500
59 Correct 16 ms 19692 KB n=2000
60 Correct 15 ms 19692 KB n=2000
61 Correct 15 ms 19820 KB n=2000
62 Correct 16 ms 19692 KB n=2000
63 Correct 16 ms 19692 KB n=2000
64 Correct 16 ms 19692 KB n=2000
65 Correct 16 ms 19692 KB n=2000
66 Correct 15 ms 19692 KB n=2000
67 Correct 16 ms 19692 KB n=2000
68 Correct 15 ms 19692 KB n=2000
69 Correct 15 ms 19692 KB n=2000
70 Correct 15 ms 19692 KB n=2000
71 Correct 15 ms 19692 KB n=2000
72 Correct 15 ms 19692 KB n=2000
73 Correct 14 ms 19692 KB n=2000
74 Correct 15 ms 19564 KB n=1844
75 Correct 16 ms 19692 KB n=2000
76 Correct 17 ms 19584 KB n=2000
77 Correct 16 ms 19692 KB n=2000
78 Correct 18 ms 19692 KB n=2000
79 Correct 17 ms 19692 KB n=2000
80 Correct 15 ms 19692 KB n=2000
81 Correct 15 ms 19692 KB n=2000
82 Correct 16 ms 19692 KB n=2000
83 Correct 15 ms 19692 KB n=2000
84 Correct 16 ms 19692 KB n=2000
85 Correct 15 ms 19692 KB n=2000
86 Correct 16 ms 19692 KB n=2000
87 Correct 16 ms 19692 KB n=2000
88 Correct 14 ms 19692 KB n=2000
89 Correct 16 ms 19820 KB n=2000
90 Correct 15 ms 19692 KB n=2000
91 Correct 15 ms 19692 KB n=2000
92 Correct 798 ms 67424 KB n=200000
93 Correct 913 ms 72784 KB n=200000
94 Correct 682 ms 77152 KB n=200000
95 Correct 797 ms 67424 KB n=200000
96 Correct 785 ms 67296 KB n=200000
97 Correct 985 ms 71500 KB n=200000
98 Correct 788 ms 67296 KB n=200000
99 Correct 968 ms 66788 KB n=200000
100 Correct 797 ms 67424 KB n=200000
101 Correct 627 ms 78816 KB n=200000
102 Correct 478 ms 68320 KB n=200000
103 Correct 469 ms 68192 KB n=200000
104 Correct 472 ms 68184 KB n=200000
105 Correct 485 ms 67936 KB n=200000
106 Correct 475 ms 68064 KB n=200000
107 Correct 478 ms 67940 KB n=200000
108 Correct 848 ms 66912 KB n=200000
109 Correct 861 ms 66912 KB n=200000
110 Correct 870 ms 66880 KB n=200000
111 Correct 843 ms 67564 KB n=200000
112 Correct 668 ms 77476 KB n=200000
113 Correct 960 ms 71392 KB n=200000
114 Correct 846 ms 67168 KB n=200000
115 Correct 1233 ms 68660 KB n=200000
116 Correct 753 ms 67300 KB n=200000
117 Correct 624 ms 77880 KB n=200000
118 Correct 1072 ms 69872 KB n=200000
119 Correct 746 ms 67092 KB n=200000
120 Correct 579 ms 78452 KB n=200000
121 Correct 578 ms 78816 KB n=200000
122 Correct 584 ms 79072 KB n=200000
123 Correct 496 ms 67552 KB n=200000
124 Correct 185 ms 32996 KB n=25264