Submission #1100179

# Submission time Handle Problem Language Result Execution time Memory
1100179 2024-10-13T08:42:44 Z vjudge1 Birthday gift (IZhO18_treearray) C++17
100 / 100
789 ms 134220 KB
//UNSTOPPABLE
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define tpii pair <pair <int,int> , int>
#define bruh cout << "NO\n"
using namespace std;
using namespace __gnu_pbds;
const int N = 3e5 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,m,q,a[N],up[21][N],tin[N],tout[N],timer;
vector <int> g[N];
void dfs(int v , int p = 0){
	tin[v] = ++timer;
	up[0][v] = p;
	for(int i = 1 ; i <= 20 ; i++){
		up[i][v] = up[i - 1][up[i - 1][v]];
	}
	for(auto to : g[v]){
		if(to == p) continue;
		dfs(to , v);
	}
	tout[v] = timer;
}
bool upper(int a , int b){
	return tin[a] <= tin[b] && tout[b] <= tout[a];
}
int lca(int a , int b){
	if(upper(a , b)) return a;
	if(upper(b , a)) return b;
	for(int i = 20 ; i >= 0 ; i--){
		if(!up[i][a]) continue;
		if(!upper(up[i][a] , b)) a = up[i][a];
	}
	return up[0][a];
}
set <int> st[N] , st1[N];
void Goldik(){
	cin >> n >> m >> q;
	for(int i = 1 ; i < n ; i++){
		int u,v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1);
	for(int i = 1 ; i <= m ; i++){
		cin >> a[i];
	}
	for(int i = 1 ; i <= m ; i++){
		if(i < m) st[lca(a[i] , a[i + 1])].insert(i);
		st1[a[i]].insert(i);
	}
	for(int i = 1 ; i <= q ; i++){
		int tp;
		cin >> tp;
		if(tp == 1){
			int pos,x;
			cin >> pos >> x;
			if(pos < m){
				int lc = lca(a[pos] , a[pos + 1]);
				st[lc].erase(st[lc].find(pos));
			}
			if(pos > 1){
				int lc = lca(a[pos - 1] , a[pos]);
				st[lc].erase(st[lc].find(pos - 1));
			}
			st1[a[pos]].erase(st1[a[pos]].find(pos));
			a[pos] = x;
			if(pos < m){
				int lc = lca(a[pos] , a[pos + 1]);
				st[lc].insert(pos);
			}
			if(pos > 1){
				int lc = lca(a[pos - 1] , a[pos]);
				st[lc].insert(pos - 1);
			}
			st1[a[pos]].insert(pos);
		}
		else{
			int l,r,v;
			cin >> l >> r >> v;
			if(st1[v].size()){
				auto it = st1[v].lower_bound(l);
				if(it != st1[v].end() && (*it) >= l && (*it) <= r){
					cout << (*it) << ' ' << (*it) << '\n';
					continue;
				}
			}
			if(st[v].size()){
				auto it = st[v].lower_bound(l);
				if(it != st[v].end() && (*it) >= l && (*it) < r){
					cout << (*it) << ' ' << (*it) + 1 << '\n';
					continue;
				}
			}
			cout << "-1 -1\n";
		}
	}
}
//rewai mnogo zadach vozmozhno odna iz nih gde to popadetsya
//returning winter prime?
//chem prowe tem luchshe
signed main(/*AZ AZDAN UZDIKSIZ*/){
	//freopen("txt.in","r",stdin);
	//freopen("txt.out","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	srand(time(0));
	int TT = 1;
	// cin >> TT;
	for(int i = 1 ; i <= TT ; i++){
		//cout << "Case " << i << ": ";
		Goldik();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 84564 KB n=5
2 Correct 12 ms 84732 KB n=100
3 Correct 12 ms 84564 KB n=100
4 Correct 11 ms 84720 KB n=100
5 Correct 13 ms 84564 KB n=100
6 Correct 12 ms 84564 KB n=100
7 Correct 12 ms 84564 KB n=100
8 Correct 15 ms 84564 KB n=100
9 Correct 12 ms 84564 KB n=100
10 Correct 13 ms 84564 KB n=100
11 Correct 12 ms 84564 KB n=100
12 Correct 12 ms 84780 KB n=100
13 Correct 12 ms 84564 KB n=100
14 Correct 15 ms 84564 KB n=100
15 Correct 12 ms 84728 KB n=100
16 Correct 11 ms 84564 KB n=100
17 Correct 12 ms 84564 KB n=100
18 Correct 14 ms 84564 KB n=100
19 Correct 12 ms 84672 KB n=100
20 Correct 15 ms 84564 KB n=100
21 Correct 12 ms 84564 KB n=100
22 Correct 11 ms 84564 KB n=100
23 Correct 11 ms 84748 KB n=100
24 Correct 13 ms 84564 KB n=100
25 Correct 12 ms 84564 KB n=100
26 Correct 15 ms 84564 KB n=12
27 Correct 13 ms 84564 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 13 ms 84564 KB n=5
2 Correct 12 ms 84732 KB n=100
3 Correct 12 ms 84564 KB n=100
4 Correct 11 ms 84720 KB n=100
5 Correct 13 ms 84564 KB n=100
6 Correct 12 ms 84564 KB n=100
7 Correct 12 ms 84564 KB n=100
8 Correct 15 ms 84564 KB n=100
9 Correct 12 ms 84564 KB n=100
10 Correct 13 ms 84564 KB n=100
11 Correct 12 ms 84564 KB n=100
12 Correct 12 ms 84780 KB n=100
13 Correct 12 ms 84564 KB n=100
14 Correct 15 ms 84564 KB n=100
15 Correct 12 ms 84728 KB n=100
16 Correct 11 ms 84564 KB n=100
17 Correct 12 ms 84564 KB n=100
18 Correct 14 ms 84564 KB n=100
19 Correct 12 ms 84672 KB n=100
20 Correct 15 ms 84564 KB n=100
21 Correct 12 ms 84564 KB n=100
22 Correct 11 ms 84564 KB n=100
23 Correct 11 ms 84748 KB n=100
24 Correct 13 ms 84564 KB n=100
25 Correct 12 ms 84564 KB n=100
26 Correct 15 ms 84564 KB n=12
27 Correct 13 ms 84564 KB n=100
28 Correct 15 ms 84820 KB n=500
29 Correct 14 ms 84868 KB n=500
30 Correct 13 ms 84820 KB n=500
31 Correct 13 ms 84820 KB n=500
32 Correct 12 ms 84820 KB n=500
33 Correct 15 ms 84760 KB n=500
34 Correct 12 ms 84820 KB n=500
35 Correct 12 ms 84712 KB n=500
36 Correct 13 ms 84820 KB n=500
37 Correct 13 ms 84832 KB n=500
38 Correct 12 ms 84820 KB n=500
39 Correct 12 ms 84836 KB n=500
40 Correct 11 ms 84820 KB n=500
41 Correct 13 ms 84820 KB n=500
42 Correct 14 ms 84764 KB n=500
43 Correct 13 ms 84820 KB n=500
44 Correct 12 ms 84820 KB n=500
45 Correct 14 ms 84820 KB n=500
46 Correct 13 ms 84820 KB n=500
47 Correct 15 ms 84820 KB n=500
48 Correct 14 ms 84820 KB n=500
49 Correct 12 ms 84820 KB n=500
50 Correct 12 ms 84704 KB n=500
51 Correct 14 ms 84692 KB n=500
52 Correct 15 ms 84820 KB n=500
53 Correct 12 ms 84984 KB n=500
54 Correct 13 ms 84832 KB n=500
55 Correct 12 ms 84820 KB n=278
56 Correct 12 ms 84820 KB n=500
57 Correct 11 ms 84820 KB n=500
58 Correct 11 ms 84792 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 13 ms 84564 KB n=5
2 Correct 12 ms 84732 KB n=100
3 Correct 12 ms 84564 KB n=100
4 Correct 11 ms 84720 KB n=100
5 Correct 13 ms 84564 KB n=100
6 Correct 12 ms 84564 KB n=100
7 Correct 12 ms 84564 KB n=100
8 Correct 15 ms 84564 KB n=100
9 Correct 12 ms 84564 KB n=100
10 Correct 13 ms 84564 KB n=100
11 Correct 12 ms 84564 KB n=100
12 Correct 12 ms 84780 KB n=100
13 Correct 12 ms 84564 KB n=100
14 Correct 15 ms 84564 KB n=100
15 Correct 12 ms 84728 KB n=100
16 Correct 11 ms 84564 KB n=100
17 Correct 12 ms 84564 KB n=100
18 Correct 14 ms 84564 KB n=100
19 Correct 12 ms 84672 KB n=100
20 Correct 15 ms 84564 KB n=100
21 Correct 12 ms 84564 KB n=100
22 Correct 11 ms 84564 KB n=100
23 Correct 11 ms 84748 KB n=100
24 Correct 13 ms 84564 KB n=100
25 Correct 12 ms 84564 KB n=100
26 Correct 15 ms 84564 KB n=12
27 Correct 13 ms 84564 KB n=100
28 Correct 15 ms 84820 KB n=500
29 Correct 14 ms 84868 KB n=500
30 Correct 13 ms 84820 KB n=500
31 Correct 13 ms 84820 KB n=500
32 Correct 12 ms 84820 KB n=500
33 Correct 15 ms 84760 KB n=500
34 Correct 12 ms 84820 KB n=500
35 Correct 12 ms 84712 KB n=500
36 Correct 13 ms 84820 KB n=500
37 Correct 13 ms 84832 KB n=500
38 Correct 12 ms 84820 KB n=500
39 Correct 12 ms 84836 KB n=500
40 Correct 11 ms 84820 KB n=500
41 Correct 13 ms 84820 KB n=500
42 Correct 14 ms 84764 KB n=500
43 Correct 13 ms 84820 KB n=500
44 Correct 12 ms 84820 KB n=500
45 Correct 14 ms 84820 KB n=500
46 Correct 13 ms 84820 KB n=500
47 Correct 15 ms 84820 KB n=500
48 Correct 14 ms 84820 KB n=500
49 Correct 12 ms 84820 KB n=500
50 Correct 12 ms 84704 KB n=500
51 Correct 14 ms 84692 KB n=500
52 Correct 15 ms 84820 KB n=500
53 Correct 12 ms 84984 KB n=500
54 Correct 13 ms 84832 KB n=500
55 Correct 12 ms 84820 KB n=278
56 Correct 12 ms 84820 KB n=500
57 Correct 11 ms 84820 KB n=500
58 Correct 11 ms 84792 KB n=500
59 Correct 12 ms 85240 KB n=2000
60 Correct 13 ms 85176 KB n=2000
61 Correct 15 ms 85088 KB n=2000
62 Correct 13 ms 85088 KB n=2000
63 Correct 15 ms 85088 KB n=2000
64 Correct 13 ms 85088 KB n=2000
65 Correct 15 ms 85088 KB n=2000
66 Correct 13 ms 85088 KB n=2000
67 Correct 12 ms 85244 KB n=2000
68 Correct 12 ms 85076 KB n=2000
69 Correct 13 ms 85088 KB n=2000
70 Correct 16 ms 85076 KB n=2000
71 Correct 16 ms 85076 KB n=2000
72 Correct 15 ms 85076 KB n=2000
73 Correct 12 ms 84968 KB n=2000
74 Correct 13 ms 85076 KB n=1844
75 Correct 13 ms 85076 KB n=2000
76 Correct 15 ms 84840 KB n=2000
77 Correct 12 ms 85076 KB n=2000
78 Correct 15 ms 85076 KB n=2000
79 Correct 13 ms 85076 KB n=2000
80 Correct 14 ms 85076 KB n=2000
81 Correct 17 ms 85076 KB n=2000
82 Correct 15 ms 85100 KB n=2000
83 Correct 15 ms 85088 KB n=2000
84 Correct 15 ms 85244 KB n=2000
85 Correct 14 ms 85076 KB n=2000
86 Correct 18 ms 85076 KB n=2000
87 Correct 17 ms 85088 KB n=2000
88 Correct 14 ms 85076 KB n=2000
89 Correct 14 ms 85076 KB n=2000
90 Correct 14 ms 85076 KB n=2000
91 Correct 18 ms 85076 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 13 ms 84564 KB n=5
2 Correct 12 ms 84732 KB n=100
3 Correct 12 ms 84564 KB n=100
4 Correct 11 ms 84720 KB n=100
5 Correct 13 ms 84564 KB n=100
6 Correct 12 ms 84564 KB n=100
7 Correct 12 ms 84564 KB n=100
8 Correct 15 ms 84564 KB n=100
9 Correct 12 ms 84564 KB n=100
10 Correct 13 ms 84564 KB n=100
11 Correct 12 ms 84564 KB n=100
12 Correct 12 ms 84780 KB n=100
13 Correct 12 ms 84564 KB n=100
14 Correct 15 ms 84564 KB n=100
15 Correct 12 ms 84728 KB n=100
16 Correct 11 ms 84564 KB n=100
17 Correct 12 ms 84564 KB n=100
18 Correct 14 ms 84564 KB n=100
19 Correct 12 ms 84672 KB n=100
20 Correct 15 ms 84564 KB n=100
21 Correct 12 ms 84564 KB n=100
22 Correct 11 ms 84564 KB n=100
23 Correct 11 ms 84748 KB n=100
24 Correct 13 ms 84564 KB n=100
25 Correct 12 ms 84564 KB n=100
26 Correct 15 ms 84564 KB n=12
27 Correct 13 ms 84564 KB n=100
28 Correct 15 ms 84820 KB n=500
29 Correct 14 ms 84868 KB n=500
30 Correct 13 ms 84820 KB n=500
31 Correct 13 ms 84820 KB n=500
32 Correct 12 ms 84820 KB n=500
33 Correct 15 ms 84760 KB n=500
34 Correct 12 ms 84820 KB n=500
35 Correct 12 ms 84712 KB n=500
36 Correct 13 ms 84820 KB n=500
37 Correct 13 ms 84832 KB n=500
38 Correct 12 ms 84820 KB n=500
39 Correct 12 ms 84836 KB n=500
40 Correct 11 ms 84820 KB n=500
41 Correct 13 ms 84820 KB n=500
42 Correct 14 ms 84764 KB n=500
43 Correct 13 ms 84820 KB n=500
44 Correct 12 ms 84820 KB n=500
45 Correct 14 ms 84820 KB n=500
46 Correct 13 ms 84820 KB n=500
47 Correct 15 ms 84820 KB n=500
48 Correct 14 ms 84820 KB n=500
49 Correct 12 ms 84820 KB n=500
50 Correct 12 ms 84704 KB n=500
51 Correct 14 ms 84692 KB n=500
52 Correct 15 ms 84820 KB n=500
53 Correct 12 ms 84984 KB n=500
54 Correct 13 ms 84832 KB n=500
55 Correct 12 ms 84820 KB n=278
56 Correct 12 ms 84820 KB n=500
57 Correct 11 ms 84820 KB n=500
58 Correct 11 ms 84792 KB n=500
59 Correct 12 ms 85240 KB n=2000
60 Correct 13 ms 85176 KB n=2000
61 Correct 15 ms 85088 KB n=2000
62 Correct 13 ms 85088 KB n=2000
63 Correct 15 ms 85088 KB n=2000
64 Correct 13 ms 85088 KB n=2000
65 Correct 15 ms 85088 KB n=2000
66 Correct 13 ms 85088 KB n=2000
67 Correct 12 ms 85244 KB n=2000
68 Correct 12 ms 85076 KB n=2000
69 Correct 13 ms 85088 KB n=2000
70 Correct 16 ms 85076 KB n=2000
71 Correct 16 ms 85076 KB n=2000
72 Correct 15 ms 85076 KB n=2000
73 Correct 12 ms 84968 KB n=2000
74 Correct 13 ms 85076 KB n=1844
75 Correct 13 ms 85076 KB n=2000
76 Correct 15 ms 84840 KB n=2000
77 Correct 12 ms 85076 KB n=2000
78 Correct 15 ms 85076 KB n=2000
79 Correct 13 ms 85076 KB n=2000
80 Correct 14 ms 85076 KB n=2000
81 Correct 17 ms 85076 KB n=2000
82 Correct 15 ms 85100 KB n=2000
83 Correct 15 ms 85088 KB n=2000
84 Correct 15 ms 85244 KB n=2000
85 Correct 14 ms 85076 KB n=2000
86 Correct 18 ms 85076 KB n=2000
87 Correct 17 ms 85088 KB n=2000
88 Correct 14 ms 85076 KB n=2000
89 Correct 14 ms 85076 KB n=2000
90 Correct 14 ms 85076 KB n=2000
91 Correct 18 ms 85076 KB n=2000
92 Correct 577 ms 125532 KB n=200000
93 Correct 666 ms 130332 KB n=200000
94 Correct 443 ms 133196 KB n=200000
95 Correct 551 ms 126096 KB n=200000
96 Correct 537 ms 126080 KB n=200000
97 Correct 712 ms 129516 KB n=200000
98 Correct 504 ms 126396 KB n=200000
99 Correct 624 ms 125772 KB n=200000
100 Correct 445 ms 125308 KB n=200000
101 Correct 280 ms 134220 KB n=200000
102 Correct 312 ms 126684 KB n=200000
103 Correct 268 ms 126796 KB n=200000
104 Correct 321 ms 126624 KB n=200000
105 Correct 372 ms 127140 KB n=200000
106 Correct 303 ms 127052 KB n=200000
107 Correct 327 ms 127044 KB n=200000
108 Correct 567 ms 125724 KB n=200000
109 Correct 511 ms 125700 KB n=200000
110 Correct 627 ms 125572 KB n=200000
111 Correct 498 ms 125552 KB n=200000
112 Correct 378 ms 133576 KB n=200000
113 Correct 671 ms 129440 KB n=200000
114 Correct 429 ms 125628 KB n=200000
115 Correct 719 ms 127568 KB n=200000
116 Correct 615 ms 126292 KB n=200000
117 Correct 349 ms 133708 KB n=200000
118 Correct 789 ms 128412 KB n=200000
119 Correct 480 ms 126140 KB n=200000
120 Correct 329 ms 133196 KB n=200000
121 Correct 337 ms 133212 KB n=200000
122 Correct 294 ms 133436 KB n=200000
123 Correct 360 ms 126896 KB n=200000
124 Correct 110 ms 103364 KB n=25264