Submission #673268

# Submission time Handle Problem Language Result Execution time Memory
673268 2022-12-20T04:22:59 Z smartmonky Birthday gift (IZhO18_treearray) C++14
100 / 100
1476 ms 109024 KB
#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long

using namespace std;

void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
const int N = 2e5 + 1;
vector <int> g[N];
int up[N][24];
int tin[N], tout[N], timer;
set <int> st[N], st2[N];
void dfs (int v, int p = 0) {
	tin[v] = ++timer;
	up[v][0] = p;
	for (int i=1; i<=20; ++i)
		up[v][i] = up[up[v][i-1]][i-1];
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (to != p)
			dfs (to, v);
	}
	tout[v] = ++timer;
}

bool upper (int a, int b) {
	return tin[a] <= tin[b] && tout[a] >= tout[b];
}

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 (! upper (up[a][i], b))
			a = up[a][i];
	return up[a][0];
}
main(){
	int n, m, q;
	cin >> n >> m >> q;
	for(int i = 0 ; i < n - 1; i++){
		int a, b;
		cin >> a >> b;
		g[b].pb(a);
		g[a].pb(b);
	}
	dfs(1, 1);
	vector <int> v(m + 1);
	for(int i = 1 ; i <= m; i++){
		cin >> v[i];
	}
	for(int i = 2; i <= m; i++){
		st[lca(v[i], v[i - 1])].insert(i - 1);
		st2[v[i]].insert(i);
	}
	while(q--){
		int t;
		cin >> t;
		if(t == 1){
			int pos, val;
			cin >> pos >> val;
			for(int i = pos ; i >= max(pos - 1, 1LL); i--){
				st[lca(v[i], v[i + 1])].erase(i);
			}
			st2[v[pos]].erase(pos);
			v[pos] = val;
			for(int i = pos ; i >= max(pos - 1, 1LL); i--){
				st[lca(v[i], v[i + 1])].insert(i);
			}
			st2[v[pos]].insert(pos);
		}else{
			//cout <<"==";
			int l, r, val;
			cin >> l >> r >> val;
			auto it = st2[val].lower_bound(l);
			if(*it <= r && it != st2[val].end()){
				cout << *it <<" " << *it << endl;
				continue;
			}
			it = st[val].lower_bound(l);
			if(*it < r && it != st[val].end()){
				cout << *it <<" " << *it + 1<< endl;
				continue;
			}
			cout <<"-1 -1" << endl;
		}
	}
}

Compilation message

treearray.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main(){
      | ^~~~
treearray.cpp: In function 'void fp(std::string)':
treearray.cpp:12:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:12:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23788 KB n=5
2 Correct 12 ms 23764 KB n=100
3 Correct 15 ms 23768 KB n=100
4 Correct 12 ms 23764 KB n=100
5 Correct 12 ms 23764 KB n=100
6 Correct 13 ms 23764 KB n=100
7 Correct 13 ms 23808 KB n=100
8 Correct 13 ms 23764 KB n=100
9 Correct 13 ms 23760 KB n=100
10 Correct 12 ms 23824 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 14 ms 23796 KB n=100
13 Correct 12 ms 23764 KB n=100
14 Correct 15 ms 23804 KB n=100
15 Correct 15 ms 23796 KB n=100
16 Correct 14 ms 23792 KB n=100
17 Correct 13 ms 23764 KB n=100
18 Correct 12 ms 23768 KB n=100
19 Correct 13 ms 23804 KB n=100
20 Correct 12 ms 23824 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 12 ms 23784 KB n=100
23 Correct 12 ms 23764 KB n=100
24 Correct 12 ms 23764 KB n=100
25 Correct 12 ms 23764 KB n=100
26 Correct 12 ms 23792 KB n=12
27 Correct 12 ms 23764 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23788 KB n=5
2 Correct 12 ms 23764 KB n=100
3 Correct 15 ms 23768 KB n=100
4 Correct 12 ms 23764 KB n=100
5 Correct 12 ms 23764 KB n=100
6 Correct 13 ms 23764 KB n=100
7 Correct 13 ms 23808 KB n=100
8 Correct 13 ms 23764 KB n=100
9 Correct 13 ms 23760 KB n=100
10 Correct 12 ms 23824 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 14 ms 23796 KB n=100
13 Correct 12 ms 23764 KB n=100
14 Correct 15 ms 23804 KB n=100
15 Correct 15 ms 23796 KB n=100
16 Correct 14 ms 23792 KB n=100
17 Correct 13 ms 23764 KB n=100
18 Correct 12 ms 23768 KB n=100
19 Correct 13 ms 23804 KB n=100
20 Correct 12 ms 23824 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 12 ms 23784 KB n=100
23 Correct 12 ms 23764 KB n=100
24 Correct 12 ms 23764 KB n=100
25 Correct 12 ms 23764 KB n=100
26 Correct 12 ms 23792 KB n=12
27 Correct 12 ms 23764 KB n=100
28 Correct 15 ms 23936 KB n=500
29 Correct 14 ms 23924 KB n=500
30 Correct 13 ms 23892 KB n=500
31 Correct 15 ms 23900 KB n=500
32 Correct 14 ms 23892 KB n=500
33 Correct 15 ms 23936 KB n=500
34 Correct 14 ms 23928 KB n=500
35 Correct 15 ms 23892 KB n=500
36 Correct 14 ms 23944 KB n=500
37 Correct 14 ms 23932 KB n=500
38 Correct 14 ms 23928 KB n=500
39 Correct 14 ms 23892 KB n=500
40 Correct 14 ms 23936 KB n=500
41 Correct 15 ms 23936 KB n=500
42 Correct 17 ms 23860 KB n=500
43 Correct 14 ms 23900 KB n=500
44 Correct 14 ms 23892 KB n=500
45 Correct 13 ms 23928 KB n=500
46 Correct 13 ms 23936 KB n=500
47 Correct 14 ms 23928 KB n=500
48 Correct 14 ms 23892 KB n=500
49 Correct 16 ms 23892 KB n=500
50 Correct 16 ms 23932 KB n=500
51 Correct 14 ms 23928 KB n=500
52 Correct 14 ms 23972 KB n=500
53 Correct 14 ms 23968 KB n=500
54 Correct 15 ms 23892 KB n=500
55 Correct 13 ms 23892 KB n=278
56 Correct 15 ms 23892 KB n=500
57 Correct 15 ms 23892 KB n=500
58 Correct 15 ms 23980 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23788 KB n=5
2 Correct 12 ms 23764 KB n=100
3 Correct 15 ms 23768 KB n=100
4 Correct 12 ms 23764 KB n=100
5 Correct 12 ms 23764 KB n=100
6 Correct 13 ms 23764 KB n=100
7 Correct 13 ms 23808 KB n=100
8 Correct 13 ms 23764 KB n=100
9 Correct 13 ms 23760 KB n=100
10 Correct 12 ms 23824 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 14 ms 23796 KB n=100
13 Correct 12 ms 23764 KB n=100
14 Correct 15 ms 23804 KB n=100
15 Correct 15 ms 23796 KB n=100
16 Correct 14 ms 23792 KB n=100
17 Correct 13 ms 23764 KB n=100
18 Correct 12 ms 23768 KB n=100
19 Correct 13 ms 23804 KB n=100
20 Correct 12 ms 23824 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 12 ms 23784 KB n=100
23 Correct 12 ms 23764 KB n=100
24 Correct 12 ms 23764 KB n=100
25 Correct 12 ms 23764 KB n=100
26 Correct 12 ms 23792 KB n=12
27 Correct 12 ms 23764 KB n=100
28 Correct 15 ms 23936 KB n=500
29 Correct 14 ms 23924 KB n=500
30 Correct 13 ms 23892 KB n=500
31 Correct 15 ms 23900 KB n=500
32 Correct 14 ms 23892 KB n=500
33 Correct 15 ms 23936 KB n=500
34 Correct 14 ms 23928 KB n=500
35 Correct 15 ms 23892 KB n=500
36 Correct 14 ms 23944 KB n=500
37 Correct 14 ms 23932 KB n=500
38 Correct 14 ms 23928 KB n=500
39 Correct 14 ms 23892 KB n=500
40 Correct 14 ms 23936 KB n=500
41 Correct 15 ms 23936 KB n=500
42 Correct 17 ms 23860 KB n=500
43 Correct 14 ms 23900 KB n=500
44 Correct 14 ms 23892 KB n=500
45 Correct 13 ms 23928 KB n=500
46 Correct 13 ms 23936 KB n=500
47 Correct 14 ms 23928 KB n=500
48 Correct 14 ms 23892 KB n=500
49 Correct 16 ms 23892 KB n=500
50 Correct 16 ms 23932 KB n=500
51 Correct 14 ms 23928 KB n=500
52 Correct 14 ms 23972 KB n=500
53 Correct 14 ms 23968 KB n=500
54 Correct 15 ms 23892 KB n=500
55 Correct 13 ms 23892 KB n=278
56 Correct 15 ms 23892 KB n=500
57 Correct 15 ms 23892 KB n=500
58 Correct 15 ms 23980 KB n=500
59 Correct 21 ms 24556 KB n=2000
60 Correct 17 ms 24660 KB n=2000
61 Correct 18 ms 24532 KB n=2000
62 Correct 19 ms 24448 KB n=2000
63 Correct 19 ms 24492 KB n=2000
64 Correct 20 ms 24532 KB n=2000
65 Correct 20 ms 24524 KB n=2000
66 Correct 18 ms 24576 KB n=2000
67 Correct 20 ms 24448 KB n=2000
68 Correct 18 ms 24576 KB n=2000
69 Correct 19 ms 24536 KB n=2000
70 Correct 20 ms 24552 KB n=2000
71 Correct 19 ms 24532 KB n=2000
72 Correct 19 ms 24448 KB n=2000
73 Correct 18 ms 24532 KB n=2000
74 Correct 20 ms 24420 KB n=1844
75 Correct 23 ms 24516 KB n=2000
76 Correct 23 ms 24452 KB n=2000
77 Correct 18 ms 24472 KB n=2000
78 Correct 18 ms 24448 KB n=2000
79 Correct 18 ms 24532 KB n=2000
80 Correct 18 ms 24568 KB n=2000
81 Correct 19 ms 24532 KB n=2000
82 Correct 18 ms 24440 KB n=2000
83 Correct 21 ms 24552 KB n=2000
84 Correct 22 ms 24440 KB n=2000
85 Correct 21 ms 24552 KB n=2000
86 Correct 18 ms 24532 KB n=2000
87 Correct 18 ms 24532 KB n=2000
88 Correct 17 ms 24576 KB n=2000
89 Correct 18 ms 24532 KB n=2000
90 Correct 17 ms 24532 KB n=2000
91 Correct 20 ms 24532 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23788 KB n=5
2 Correct 12 ms 23764 KB n=100
3 Correct 15 ms 23768 KB n=100
4 Correct 12 ms 23764 KB n=100
5 Correct 12 ms 23764 KB n=100
6 Correct 13 ms 23764 KB n=100
7 Correct 13 ms 23808 KB n=100
8 Correct 13 ms 23764 KB n=100
9 Correct 13 ms 23760 KB n=100
10 Correct 12 ms 23824 KB n=100
11 Correct 13 ms 23764 KB n=100
12 Correct 14 ms 23796 KB n=100
13 Correct 12 ms 23764 KB n=100
14 Correct 15 ms 23804 KB n=100
15 Correct 15 ms 23796 KB n=100
16 Correct 14 ms 23792 KB n=100
17 Correct 13 ms 23764 KB n=100
18 Correct 12 ms 23768 KB n=100
19 Correct 13 ms 23804 KB n=100
20 Correct 12 ms 23824 KB n=100
21 Correct 12 ms 23764 KB n=100
22 Correct 12 ms 23784 KB n=100
23 Correct 12 ms 23764 KB n=100
24 Correct 12 ms 23764 KB n=100
25 Correct 12 ms 23764 KB n=100
26 Correct 12 ms 23792 KB n=12
27 Correct 12 ms 23764 KB n=100
28 Correct 15 ms 23936 KB n=500
29 Correct 14 ms 23924 KB n=500
30 Correct 13 ms 23892 KB n=500
31 Correct 15 ms 23900 KB n=500
32 Correct 14 ms 23892 KB n=500
33 Correct 15 ms 23936 KB n=500
34 Correct 14 ms 23928 KB n=500
35 Correct 15 ms 23892 KB n=500
36 Correct 14 ms 23944 KB n=500
37 Correct 14 ms 23932 KB n=500
38 Correct 14 ms 23928 KB n=500
39 Correct 14 ms 23892 KB n=500
40 Correct 14 ms 23936 KB n=500
41 Correct 15 ms 23936 KB n=500
42 Correct 17 ms 23860 KB n=500
43 Correct 14 ms 23900 KB n=500
44 Correct 14 ms 23892 KB n=500
45 Correct 13 ms 23928 KB n=500
46 Correct 13 ms 23936 KB n=500
47 Correct 14 ms 23928 KB n=500
48 Correct 14 ms 23892 KB n=500
49 Correct 16 ms 23892 KB n=500
50 Correct 16 ms 23932 KB n=500
51 Correct 14 ms 23928 KB n=500
52 Correct 14 ms 23972 KB n=500
53 Correct 14 ms 23968 KB n=500
54 Correct 15 ms 23892 KB n=500
55 Correct 13 ms 23892 KB n=278
56 Correct 15 ms 23892 KB n=500
57 Correct 15 ms 23892 KB n=500
58 Correct 15 ms 23980 KB n=500
59 Correct 21 ms 24556 KB n=2000
60 Correct 17 ms 24660 KB n=2000
61 Correct 18 ms 24532 KB n=2000
62 Correct 19 ms 24448 KB n=2000
63 Correct 19 ms 24492 KB n=2000
64 Correct 20 ms 24532 KB n=2000
65 Correct 20 ms 24524 KB n=2000
66 Correct 18 ms 24576 KB n=2000
67 Correct 20 ms 24448 KB n=2000
68 Correct 18 ms 24576 KB n=2000
69 Correct 19 ms 24536 KB n=2000
70 Correct 20 ms 24552 KB n=2000
71 Correct 19 ms 24532 KB n=2000
72 Correct 19 ms 24448 KB n=2000
73 Correct 18 ms 24532 KB n=2000
74 Correct 20 ms 24420 KB n=1844
75 Correct 23 ms 24516 KB n=2000
76 Correct 23 ms 24452 KB n=2000
77 Correct 18 ms 24472 KB n=2000
78 Correct 18 ms 24448 KB n=2000
79 Correct 18 ms 24532 KB n=2000
80 Correct 18 ms 24568 KB n=2000
81 Correct 19 ms 24532 KB n=2000
82 Correct 18 ms 24440 KB n=2000
83 Correct 21 ms 24552 KB n=2000
84 Correct 22 ms 24440 KB n=2000
85 Correct 21 ms 24552 KB n=2000
86 Correct 18 ms 24532 KB n=2000
87 Correct 18 ms 24532 KB n=2000
88 Correct 17 ms 24576 KB n=2000
89 Correct 18 ms 24532 KB n=2000
90 Correct 17 ms 24532 KB n=2000
91 Correct 20 ms 24532 KB n=2000
92 Correct 1082 ms 100504 KB n=200000
93 Correct 1222 ms 105364 KB n=200000
94 Correct 922 ms 108188 KB n=200000
95 Correct 1042 ms 100360 KB n=200000
96 Correct 979 ms 100172 KB n=200000
97 Correct 1291 ms 104452 KB n=200000
98 Correct 1066 ms 100200 KB n=200000
99 Correct 1214 ms 100624 KB n=200000
100 Correct 1050 ms 100296 KB n=200000
101 Correct 849 ms 109024 KB n=200000
102 Correct 904 ms 101532 KB n=200000
103 Correct 887 ms 101676 KB n=200000
104 Correct 944 ms 101608 KB n=200000
105 Correct 878 ms 101988 KB n=200000
106 Correct 893 ms 101956 KB n=200000
107 Correct 897 ms 101964 KB n=200000
108 Correct 1081 ms 100524 KB n=200000
109 Correct 1072 ms 100444 KB n=200000
110 Correct 1104 ms 100444 KB n=200000
111 Correct 997 ms 99700 KB n=200000
112 Correct 952 ms 108272 KB n=200000
113 Correct 1259 ms 104336 KB n=200000
114 Correct 1031 ms 99640 KB n=200000
115 Correct 1476 ms 102476 KB n=200000
116 Correct 1000 ms 100436 KB n=200000
117 Correct 864 ms 108820 KB n=200000
118 Correct 1339 ms 103416 KB n=200000
119 Correct 990 ms 100304 KB n=200000
120 Correct 803 ms 108132 KB n=200000
121 Correct 796 ms 108072 KB n=200000
122 Correct 799 ms 108340 KB n=200000
123 Correct 886 ms 101712 KB n=200000
124 Correct 250 ms 42060 KB n=25264