Submission #245678

# Submission time Handle Problem Language Result Execution time Memory
245678 2020-07-07T06:32:13 Z Yera Birthday gift (IZhO18_treearray) C++17
100 / 100
916 ms 141204 KB
// In The Name Of God
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sagyndym_seni ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
 
const int N = 2e5+5, M = (1 << 20), p1 = 911382323, p2 = 972663749, INF = 1e9+123;
 
inline int read(){
	char c = getchar_unlocked();
	bool minus = 0;
	while (c < '0' || '9' < c){
		if(c == '-'){ minus = 1;}
		c = getchar_unlocked();
		if(c == '-'){ minus = 1;}
	}
	int res = 0;
	while ('0' <= c && c <= '9') {
		res = (res << 3) + (res << 1) + c - '0';
		c = getchar_unlocked();
	}
	if(minus){ res = (~res) + 1;}
	return res;
}
 
int n, m, q;
int pos[M], LOG[M], vec[N];
pair<int, int> st[M][20];
vector<int> g[N];
vector<pair<int, int>> order;
 
void dfs(int v, int p, int depth){
	order.pb({depth, v});
	assert(sz(order) < (N << 2));
	pos[v] = sz(order)-1;
	for(auto to : g[v]){
		if(to == p){ continue;}
		dfs(to, v, depth + 1);
		order.pb({depth, v});
	}
}
 
inline void precalc(){
	LOG[1] = 0;
	for(int i = 2; i < (N << 2); i++){
		LOG[i] = LOG[i >> 1] + 1;
	}
	for(int i = 0; i < sz(order); i++){
		assert(i < (N << 2));
		st[i][0] = order[i];
	}
	for(int j = 1; j < 30; j++){
		for(int i = 0; i + (1 << j) <= sz(order); i++){
			st[i][j] = min(st[i][j-1], st[i + (1 << (j-1))][j-1]);
		}
	}
}
 
inline int mn(int l, int r){
	if(r < l){ swap(l, r);}
	assert(r - l + 1 < (N << 2) && r < (N << 2));
	int j = LOG[r - l + 1];
	pair<int, int> res = min(st[l][j], st[r - (1 << j) + 1][j]);
	return res.s;
}

set<int> uno[N], duo[N];

int main(){
	sagyndym_seni;
	n = read(); m = read(); q = read();
	for(int i = 1; i < n; i++){
		int v = read()-1, u = read()-1;
		g[v].pb(u);
		g[u].pb(v);
	}
	for(int i = 0; i < m; i++){
		vec[i] = read()-1;
		uno[vec[i]].insert(i);
	}
	dfs(0, 0, 0);
	precalc();
	for(int i = 0; i < m - 1; i++){
		duo[mn(pos[vec[i]], pos[vec[i + 1]])].insert(i);
	}
	while(q--){
		int tp = read()-1;
		if(!tp){
			int p = read()-1, v = read()-1;
			uno[vec[p]].erase(p);
			uno[v].insert(p);
			if(p != m - 1){
				duo[mn(pos[vec[p]], pos[vec[p + 1]])].erase(p);
				duo[mn(pos[v], pos[vec[p + 1]])].insert(p);
			}
			if(p != 0){
				duo[mn(pos[vec[p - 1]], pos[vec[p]])].erase(p - 1);
				duo[mn(pos[vec[p - 1]], pos[v])].insert(p - 1);
			}
			vec[p] = v;
		}else{
			int l = read()-1, r = read()-1, p = read()-1;
			auto it = uno[p].lower_bound(l);
			if(it != uno[p].end()){
				int res = *it;
				if(l <= res && res <= r){ cout<<'\n'<<res + 1<<' '<<res+1; continue;}
			}
			it = duo[p].lower_bound(l);
			if(it != duo[p].end()){
				int res = *it;
				if(l <= res && res < r){ cout<<'\n'<<res + 1<<' '<<res + 2; continue;}
			}
			cout<<"\n-1 -1";
		}
	}
	return 0;
}
/* TIMUS: 292220YC*/
# Verdict Execution time Memory Grader output
1 Correct 20 ms 27008 KB n=5
2 Correct 20 ms 27008 KB n=100
3 Correct 24 ms 27008 KB n=100
4 Correct 21 ms 27008 KB n=100
5 Correct 21 ms 27008 KB n=100
6 Correct 21 ms 27008 KB n=100
7 Correct 20 ms 27008 KB n=100
8 Correct 20 ms 27008 KB n=100
9 Correct 24 ms 27008 KB n=100
10 Correct 20 ms 27008 KB n=100
11 Correct 20 ms 27008 KB n=100
12 Correct 20 ms 27008 KB n=100
13 Correct 21 ms 27008 KB n=100
14 Correct 20 ms 27008 KB n=100
15 Correct 20 ms 27008 KB n=100
16 Correct 28 ms 27036 KB n=100
17 Correct 23 ms 27008 KB n=100
18 Correct 20 ms 27008 KB n=100
19 Correct 28 ms 27008 KB n=100
20 Correct 20 ms 27008 KB n=100
21 Correct 23 ms 27008 KB n=100
22 Correct 23 ms 27008 KB n=100
23 Correct 21 ms 27008 KB n=100
24 Correct 21 ms 27008 KB n=100
25 Correct 23 ms 27008 KB n=100
26 Correct 20 ms 27008 KB n=12
27 Correct 21 ms 27008 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 20 ms 27008 KB n=5
2 Correct 20 ms 27008 KB n=100
3 Correct 24 ms 27008 KB n=100
4 Correct 21 ms 27008 KB n=100
5 Correct 21 ms 27008 KB n=100
6 Correct 21 ms 27008 KB n=100
7 Correct 20 ms 27008 KB n=100
8 Correct 20 ms 27008 KB n=100
9 Correct 24 ms 27008 KB n=100
10 Correct 20 ms 27008 KB n=100
11 Correct 20 ms 27008 KB n=100
12 Correct 20 ms 27008 KB n=100
13 Correct 21 ms 27008 KB n=100
14 Correct 20 ms 27008 KB n=100
15 Correct 20 ms 27008 KB n=100
16 Correct 28 ms 27036 KB n=100
17 Correct 23 ms 27008 KB n=100
18 Correct 20 ms 27008 KB n=100
19 Correct 28 ms 27008 KB n=100
20 Correct 20 ms 27008 KB n=100
21 Correct 23 ms 27008 KB n=100
22 Correct 23 ms 27008 KB n=100
23 Correct 21 ms 27008 KB n=100
24 Correct 21 ms 27008 KB n=100
25 Correct 23 ms 27008 KB n=100
26 Correct 20 ms 27008 KB n=12
27 Correct 21 ms 27008 KB n=100
28 Correct 23 ms 27392 KB n=500
29 Correct 21 ms 27264 KB n=500
30 Correct 21 ms 27264 KB n=500
31 Correct 21 ms 27264 KB n=500
32 Correct 21 ms 27264 KB n=500
33 Correct 21 ms 27264 KB n=500
34 Correct 21 ms 27264 KB n=500
35 Correct 23 ms 27264 KB n=500
36 Correct 27 ms 27276 KB n=500
37 Correct 24 ms 27264 KB n=500
38 Correct 22 ms 27264 KB n=500
39 Correct 21 ms 27264 KB n=500
40 Correct 20 ms 27264 KB n=500
41 Correct 22 ms 27264 KB n=500
42 Correct 24 ms 27256 KB n=500
43 Correct 21 ms 27264 KB n=500
44 Correct 22 ms 27264 KB n=500
45 Correct 21 ms 27264 KB n=500
46 Correct 20 ms 27264 KB n=500
47 Correct 21 ms 27392 KB n=500
48 Correct 21 ms 27264 KB n=500
49 Correct 24 ms 27264 KB n=500
50 Correct 21 ms 27264 KB n=500
51 Correct 21 ms 27264 KB n=500
52 Correct 21 ms 27264 KB n=500
53 Correct 23 ms 27392 KB n=500
54 Correct 20 ms 27264 KB n=500
55 Correct 20 ms 27136 KB n=278
56 Correct 20 ms 27264 KB n=500
57 Correct 24 ms 27264 KB n=500
58 Correct 20 ms 27264 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 20 ms 27008 KB n=5
2 Correct 20 ms 27008 KB n=100
3 Correct 24 ms 27008 KB n=100
4 Correct 21 ms 27008 KB n=100
5 Correct 21 ms 27008 KB n=100
6 Correct 21 ms 27008 KB n=100
7 Correct 20 ms 27008 KB n=100
8 Correct 20 ms 27008 KB n=100
9 Correct 24 ms 27008 KB n=100
10 Correct 20 ms 27008 KB n=100
11 Correct 20 ms 27008 KB n=100
12 Correct 20 ms 27008 KB n=100
13 Correct 21 ms 27008 KB n=100
14 Correct 20 ms 27008 KB n=100
15 Correct 20 ms 27008 KB n=100
16 Correct 28 ms 27036 KB n=100
17 Correct 23 ms 27008 KB n=100
18 Correct 20 ms 27008 KB n=100
19 Correct 28 ms 27008 KB n=100
20 Correct 20 ms 27008 KB n=100
21 Correct 23 ms 27008 KB n=100
22 Correct 23 ms 27008 KB n=100
23 Correct 21 ms 27008 KB n=100
24 Correct 21 ms 27008 KB n=100
25 Correct 23 ms 27008 KB n=100
26 Correct 20 ms 27008 KB n=12
27 Correct 21 ms 27008 KB n=100
28 Correct 23 ms 27392 KB n=500
29 Correct 21 ms 27264 KB n=500
30 Correct 21 ms 27264 KB n=500
31 Correct 21 ms 27264 KB n=500
32 Correct 21 ms 27264 KB n=500
33 Correct 21 ms 27264 KB n=500
34 Correct 21 ms 27264 KB n=500
35 Correct 23 ms 27264 KB n=500
36 Correct 27 ms 27276 KB n=500
37 Correct 24 ms 27264 KB n=500
38 Correct 22 ms 27264 KB n=500
39 Correct 21 ms 27264 KB n=500
40 Correct 20 ms 27264 KB n=500
41 Correct 22 ms 27264 KB n=500
42 Correct 24 ms 27256 KB n=500
43 Correct 21 ms 27264 KB n=500
44 Correct 22 ms 27264 KB n=500
45 Correct 21 ms 27264 KB n=500
46 Correct 20 ms 27264 KB n=500
47 Correct 21 ms 27392 KB n=500
48 Correct 21 ms 27264 KB n=500
49 Correct 24 ms 27264 KB n=500
50 Correct 21 ms 27264 KB n=500
51 Correct 21 ms 27264 KB n=500
52 Correct 21 ms 27264 KB n=500
53 Correct 23 ms 27392 KB n=500
54 Correct 20 ms 27264 KB n=500
55 Correct 20 ms 27136 KB n=278
56 Correct 20 ms 27264 KB n=500
57 Correct 24 ms 27264 KB n=500
58 Correct 20 ms 27264 KB n=500
59 Correct 25 ms 27996 KB n=2000
60 Correct 26 ms 28160 KB n=2000
61 Correct 23 ms 28032 KB n=2000
62 Correct 25 ms 28024 KB n=2000
63 Correct 24 ms 27904 KB n=2000
64 Correct 26 ms 28032 KB n=2000
65 Correct 27 ms 27904 KB n=2000
66 Correct 23 ms 28160 KB n=2000
67 Correct 23 ms 27904 KB n=2000
68 Correct 23 ms 28032 KB n=2000
69 Correct 28 ms 28032 KB n=2000
70 Correct 25 ms 28032 KB n=2000
71 Correct 23 ms 27904 KB n=2000
72 Correct 22 ms 28032 KB n=2000
73 Correct 22 ms 27904 KB n=2000
74 Correct 23 ms 27904 KB n=1844
75 Correct 25 ms 27896 KB n=2000
76 Correct 23 ms 27904 KB n=2000
77 Correct 24 ms 28032 KB n=2000
78 Correct 25 ms 28032 KB n=2000
79 Correct 24 ms 28032 KB n=2000
80 Correct 28 ms 28032 KB n=2000
81 Correct 26 ms 28032 KB n=2000
82 Correct 27 ms 27904 KB n=2000
83 Correct 23 ms 28032 KB n=2000
84 Correct 23 ms 28032 KB n=2000
85 Correct 23 ms 28032 KB n=2000
86 Correct 23 ms 28032 KB n=2000
87 Correct 23 ms 28032 KB n=2000
88 Correct 22 ms 28160 KB n=2000
89 Correct 24 ms 28160 KB n=2000
90 Correct 26 ms 28160 KB n=2000
91 Correct 26 ms 28032 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 20 ms 27008 KB n=5
2 Correct 20 ms 27008 KB n=100
3 Correct 24 ms 27008 KB n=100
4 Correct 21 ms 27008 KB n=100
5 Correct 21 ms 27008 KB n=100
6 Correct 21 ms 27008 KB n=100
7 Correct 20 ms 27008 KB n=100
8 Correct 20 ms 27008 KB n=100
9 Correct 24 ms 27008 KB n=100
10 Correct 20 ms 27008 KB n=100
11 Correct 20 ms 27008 KB n=100
12 Correct 20 ms 27008 KB n=100
13 Correct 21 ms 27008 KB n=100
14 Correct 20 ms 27008 KB n=100
15 Correct 20 ms 27008 KB n=100
16 Correct 28 ms 27036 KB n=100
17 Correct 23 ms 27008 KB n=100
18 Correct 20 ms 27008 KB n=100
19 Correct 28 ms 27008 KB n=100
20 Correct 20 ms 27008 KB n=100
21 Correct 23 ms 27008 KB n=100
22 Correct 23 ms 27008 KB n=100
23 Correct 21 ms 27008 KB n=100
24 Correct 21 ms 27008 KB n=100
25 Correct 23 ms 27008 KB n=100
26 Correct 20 ms 27008 KB n=12
27 Correct 21 ms 27008 KB n=100
28 Correct 23 ms 27392 KB n=500
29 Correct 21 ms 27264 KB n=500
30 Correct 21 ms 27264 KB n=500
31 Correct 21 ms 27264 KB n=500
32 Correct 21 ms 27264 KB n=500
33 Correct 21 ms 27264 KB n=500
34 Correct 21 ms 27264 KB n=500
35 Correct 23 ms 27264 KB n=500
36 Correct 27 ms 27276 KB n=500
37 Correct 24 ms 27264 KB n=500
38 Correct 22 ms 27264 KB n=500
39 Correct 21 ms 27264 KB n=500
40 Correct 20 ms 27264 KB n=500
41 Correct 22 ms 27264 KB n=500
42 Correct 24 ms 27256 KB n=500
43 Correct 21 ms 27264 KB n=500
44 Correct 22 ms 27264 KB n=500
45 Correct 21 ms 27264 KB n=500
46 Correct 20 ms 27264 KB n=500
47 Correct 21 ms 27392 KB n=500
48 Correct 21 ms 27264 KB n=500
49 Correct 24 ms 27264 KB n=500
50 Correct 21 ms 27264 KB n=500
51 Correct 21 ms 27264 KB n=500
52 Correct 21 ms 27264 KB n=500
53 Correct 23 ms 27392 KB n=500
54 Correct 20 ms 27264 KB n=500
55 Correct 20 ms 27136 KB n=278
56 Correct 20 ms 27264 KB n=500
57 Correct 24 ms 27264 KB n=500
58 Correct 20 ms 27264 KB n=500
59 Correct 25 ms 27996 KB n=2000
60 Correct 26 ms 28160 KB n=2000
61 Correct 23 ms 28032 KB n=2000
62 Correct 25 ms 28024 KB n=2000
63 Correct 24 ms 27904 KB n=2000
64 Correct 26 ms 28032 KB n=2000
65 Correct 27 ms 27904 KB n=2000
66 Correct 23 ms 28160 KB n=2000
67 Correct 23 ms 27904 KB n=2000
68 Correct 23 ms 28032 KB n=2000
69 Correct 28 ms 28032 KB n=2000
70 Correct 25 ms 28032 KB n=2000
71 Correct 23 ms 27904 KB n=2000
72 Correct 22 ms 28032 KB n=2000
73 Correct 22 ms 27904 KB n=2000
74 Correct 23 ms 27904 KB n=1844
75 Correct 25 ms 27896 KB n=2000
76 Correct 23 ms 27904 KB n=2000
77 Correct 24 ms 28032 KB n=2000
78 Correct 25 ms 28032 KB n=2000
79 Correct 24 ms 28032 KB n=2000
80 Correct 28 ms 28032 KB n=2000
81 Correct 26 ms 28032 KB n=2000
82 Correct 27 ms 27904 KB n=2000
83 Correct 23 ms 28032 KB n=2000
84 Correct 23 ms 28032 KB n=2000
85 Correct 23 ms 28032 KB n=2000
86 Correct 23 ms 28032 KB n=2000
87 Correct 23 ms 28032 KB n=2000
88 Correct 22 ms 28160 KB n=2000
89 Correct 24 ms 28160 KB n=2000
90 Correct 26 ms 28160 KB n=2000
91 Correct 26 ms 28032 KB n=2000
92 Correct 799 ms 124004 KB n=200000
93 Correct 762 ms 133256 KB n=200000
94 Correct 731 ms 138844 KB n=200000
95 Correct 842 ms 126372 KB n=200000
96 Correct 778 ms 126496 KB n=200000
97 Correct 766 ms 131676 KB n=200000
98 Correct 747 ms 126632 KB n=200000
99 Correct 910 ms 125792 KB n=200000
100 Correct 893 ms 126432 KB n=200000
101 Correct 725 ms 141204 KB n=200000
102 Correct 438 ms 127584 KB n=200000
103 Correct 424 ms 127584 KB n=200000
104 Correct 403 ms 127712 KB n=200000
105 Correct 428 ms 127204 KB n=200000
106 Correct 507 ms 127204 KB n=200000
107 Correct 425 ms 127336 KB n=200000
108 Correct 916 ms 125904 KB n=200000
109 Correct 866 ms 126328 KB n=200000
110 Correct 816 ms 126176 KB n=200000
111 Correct 893 ms 126368 KB n=200000
112 Correct 701 ms 139244 KB n=200000
113 Correct 830 ms 131752 KB n=200000
114 Correct 849 ms 126428 KB n=200000
115 Correct 872 ms 127964 KB n=200000
116 Correct 747 ms 125800 KB n=200000
117 Correct 702 ms 139596 KB n=200000
118 Correct 839 ms 129628 KB n=200000
119 Correct 767 ms 125716 KB n=200000
120 Correct 746 ms 140124 KB n=200000
121 Correct 786 ms 140252 KB n=200000
122 Correct 648 ms 140764 KB n=200000
123 Correct 496 ms 126304 KB n=200000
124 Correct 271 ms 48884 KB n=25264