답안 #495920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
495920 2021-12-20T07:53:11 Z Ierus Birthday gift (IZhO18_treearray) C++17
100 / 100
1051 ms 80476 KB
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 2e5+77;
const int MOD = 1e9+7;
const int LG = 18;
int n, m, que, a[N], timer;
int tin[N], tout[N], up[N][LG+2];
vector<int> g[N];
set<int> st[N], o[N];
void dfs(int v, int p){
	tin[v] = ++timer;
	up[v][0] = p;
	for(int i = 1; i <= LG; ++i){
		up[v][i] = up[up[v][i-1]][i-1];
	}
	for(int to : g[v]){
		if(to != p){
			dfs(to, v);	
		}
	}
	tout[v] = timer;
}
bool upper(int v, int u){
	return tin[v] <= tin[u] && tout[u] <= tout[v];
}
int lca(int v, int u){
	if(upper(v, u)) return v;
	if(upper(u, v)) return u;
	for(int i = LG; i >= 0; --i){
		if(!upper(up[v][i], u)){
			v = up[v][i];
		}
	}
	return up[v][0];
}
inline void update(int pos, int v){
	o[a[pos]].erase(pos);
	if(pos < m){
		if(a[pos] && a[pos+1]){
			st[lca(a[pos],a[pos+1])].erase(pos+1);
		}
	}
	if(pos > 1){
		if(a[pos] && a[pos-1]){
			st[lca(a[pos],a[pos-1])].erase(pos);
		}
	}
	a[pos] = v;
	o[a[pos]].insert(pos);
	if(pos > 1){
		if(a[pos] && a[pos-1]){
			st[lca(a[pos],a[pos-1])].insert(pos);
		}
	}
	if(pos < m){
		if(a[pos] && a[pos+1]){
			st[lca(a[pos],a[pos+1])].insert(pos+1);
		}
	}
}
inline pair<int,int> get(int L, int R, int v){
	auto it = st[v].upper_bound(L);
	auto it1 = o[v].lower_bound(L);
	if(it1 != o[v].end() && *it1 <= R) return {*it1, *it1};
	if(it == st[v].end() || *it > R) return {-1, -1};
	return {*it-1, *it};
}
int main(){NFS;
	cin >> n >> m >> que;
	for(int i = 1, u, v; i < n; ++i){
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1, 1);
	for(int i = 1, val; i <= m; ++i){
		cin >> val;
		update(i, val);
	}
	for(int type,l,r,v; que--;){
		cin >> type;
		if(type == 1){
			cin >> l >> v;
			update(l, v);
		}else{
			cin >> l >> r >> v;
			pair<int,int> res = get(l, r, v);
			cout << res.F << ' '  << res.S << '\n';
		}
	}
}











# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23756 KB n=5
2 Correct 16 ms 23756 KB n=100
3 Correct 12 ms 23756 KB n=100
4 Correct 12 ms 23756 KB n=100
5 Correct 13 ms 23756 KB n=100
6 Correct 13 ms 23756 KB n=100
7 Correct 13 ms 23812 KB n=100
8 Correct 13 ms 23744 KB n=100
9 Correct 11 ms 23756 KB n=100
10 Correct 15 ms 23756 KB n=100
11 Correct 12 ms 23848 KB n=100
12 Correct 15 ms 23756 KB n=100
13 Correct 14 ms 23852 KB n=100
14 Correct 13 ms 23772 KB n=100
15 Correct 13 ms 23756 KB n=100
16 Correct 13 ms 23756 KB n=100
17 Correct 12 ms 23756 KB n=100
18 Correct 12 ms 23736 KB n=100
19 Correct 13 ms 23772 KB n=100
20 Correct 14 ms 23772 KB n=100
21 Correct 12 ms 23756 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 15 ms 23756 KB n=100
24 Correct 13 ms 23756 KB n=100
25 Correct 12 ms 23756 KB n=100
26 Correct 12 ms 23756 KB n=12
27 Correct 12 ms 23776 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23756 KB n=5
2 Correct 16 ms 23756 KB n=100
3 Correct 12 ms 23756 KB n=100
4 Correct 12 ms 23756 KB n=100
5 Correct 13 ms 23756 KB n=100
6 Correct 13 ms 23756 KB n=100
7 Correct 13 ms 23812 KB n=100
8 Correct 13 ms 23744 KB n=100
9 Correct 11 ms 23756 KB n=100
10 Correct 15 ms 23756 KB n=100
11 Correct 12 ms 23848 KB n=100
12 Correct 15 ms 23756 KB n=100
13 Correct 14 ms 23852 KB n=100
14 Correct 13 ms 23772 KB n=100
15 Correct 13 ms 23756 KB n=100
16 Correct 13 ms 23756 KB n=100
17 Correct 12 ms 23756 KB n=100
18 Correct 12 ms 23736 KB n=100
19 Correct 13 ms 23772 KB n=100
20 Correct 14 ms 23772 KB n=100
21 Correct 12 ms 23756 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 15 ms 23756 KB n=100
24 Correct 13 ms 23756 KB n=100
25 Correct 12 ms 23756 KB n=100
26 Correct 12 ms 23756 KB n=12
27 Correct 12 ms 23776 KB n=100
28 Correct 14 ms 23848 KB n=500
29 Correct 13 ms 23884 KB n=500
30 Correct 12 ms 23884 KB n=500
31 Correct 15 ms 23960 KB n=500
32 Correct 16 ms 23924 KB n=500
33 Correct 17 ms 23884 KB n=500
34 Correct 14 ms 23948 KB n=500
35 Correct 15 ms 23992 KB n=500
36 Correct 12 ms 23884 KB n=500
37 Correct 13 ms 23872 KB n=500
38 Correct 13 ms 23860 KB n=500
39 Correct 12 ms 23884 KB n=500
40 Correct 12 ms 23884 KB n=500
41 Correct 12 ms 23916 KB n=500
42 Correct 17 ms 23932 KB n=500
43 Correct 16 ms 23884 KB n=500
44 Correct 13 ms 23852 KB n=500
45 Correct 12 ms 23884 KB n=500
46 Correct 12 ms 23884 KB n=500
47 Correct 14 ms 23972 KB n=500
48 Correct 12 ms 23920 KB n=500
49 Correct 14 ms 23880 KB n=500
50 Correct 12 ms 23944 KB n=500
51 Correct 16 ms 23884 KB n=500
52 Correct 14 ms 24012 KB n=500
53 Correct 15 ms 23884 KB n=500
54 Correct 17 ms 23908 KB n=500
55 Correct 11 ms 23884 KB n=278
56 Correct 13 ms 23884 KB n=500
57 Correct 13 ms 23932 KB n=500
58 Correct 12 ms 23884 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23756 KB n=5
2 Correct 16 ms 23756 KB n=100
3 Correct 12 ms 23756 KB n=100
4 Correct 12 ms 23756 KB n=100
5 Correct 13 ms 23756 KB n=100
6 Correct 13 ms 23756 KB n=100
7 Correct 13 ms 23812 KB n=100
8 Correct 13 ms 23744 KB n=100
9 Correct 11 ms 23756 KB n=100
10 Correct 15 ms 23756 KB n=100
11 Correct 12 ms 23848 KB n=100
12 Correct 15 ms 23756 KB n=100
13 Correct 14 ms 23852 KB n=100
14 Correct 13 ms 23772 KB n=100
15 Correct 13 ms 23756 KB n=100
16 Correct 13 ms 23756 KB n=100
17 Correct 12 ms 23756 KB n=100
18 Correct 12 ms 23736 KB n=100
19 Correct 13 ms 23772 KB n=100
20 Correct 14 ms 23772 KB n=100
21 Correct 12 ms 23756 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 15 ms 23756 KB n=100
24 Correct 13 ms 23756 KB n=100
25 Correct 12 ms 23756 KB n=100
26 Correct 12 ms 23756 KB n=12
27 Correct 12 ms 23776 KB n=100
28 Correct 14 ms 23848 KB n=500
29 Correct 13 ms 23884 KB n=500
30 Correct 12 ms 23884 KB n=500
31 Correct 15 ms 23960 KB n=500
32 Correct 16 ms 23924 KB n=500
33 Correct 17 ms 23884 KB n=500
34 Correct 14 ms 23948 KB n=500
35 Correct 15 ms 23992 KB n=500
36 Correct 12 ms 23884 KB n=500
37 Correct 13 ms 23872 KB n=500
38 Correct 13 ms 23860 KB n=500
39 Correct 12 ms 23884 KB n=500
40 Correct 12 ms 23884 KB n=500
41 Correct 12 ms 23916 KB n=500
42 Correct 17 ms 23932 KB n=500
43 Correct 16 ms 23884 KB n=500
44 Correct 13 ms 23852 KB n=500
45 Correct 12 ms 23884 KB n=500
46 Correct 12 ms 23884 KB n=500
47 Correct 14 ms 23972 KB n=500
48 Correct 12 ms 23920 KB n=500
49 Correct 14 ms 23880 KB n=500
50 Correct 12 ms 23944 KB n=500
51 Correct 16 ms 23884 KB n=500
52 Correct 14 ms 24012 KB n=500
53 Correct 15 ms 23884 KB n=500
54 Correct 17 ms 23908 KB n=500
55 Correct 11 ms 23884 KB n=278
56 Correct 13 ms 23884 KB n=500
57 Correct 13 ms 23932 KB n=500
58 Correct 12 ms 23884 KB n=500
59 Correct 15 ms 24268 KB n=2000
60 Correct 14 ms 24396 KB n=2000
61 Correct 15 ms 24268 KB n=2000
62 Correct 16 ms 24252 KB n=2000
63 Correct 20 ms 24280 KB n=2000
64 Correct 16 ms 24268 KB n=2000
65 Correct 14 ms 24228 KB n=2000
66 Correct 15 ms 24268 KB n=2000
67 Correct 15 ms 24268 KB n=2000
68 Correct 14 ms 24336 KB n=2000
69 Correct 14 ms 24296 KB n=2000
70 Correct 15 ms 24212 KB n=2000
71 Correct 17 ms 24216 KB n=2000
72 Correct 16 ms 24272 KB n=2000
73 Correct 15 ms 24296 KB n=2000
74 Correct 16 ms 24196 KB n=1844
75 Correct 18 ms 24268 KB n=2000
76 Correct 15 ms 24268 KB n=2000
77 Correct 18 ms 24276 KB n=2000
78 Correct 19 ms 24268 KB n=2000
79 Correct 16 ms 24268 KB n=2000
80 Correct 14 ms 24268 KB n=2000
81 Correct 14 ms 24268 KB n=2000
82 Correct 16 ms 24192 KB n=2000
83 Correct 18 ms 24268 KB n=2000
84 Correct 18 ms 24284 KB n=2000
85 Correct 15 ms 24268 KB n=2000
86 Correct 16 ms 24308 KB n=2000
87 Correct 15 ms 24268 KB n=2000
88 Correct 14 ms 24400 KB n=2000
89 Correct 14 ms 24344 KB n=2000
90 Correct 15 ms 24396 KB n=2000
91 Correct 15 ms 24268 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 23756 KB n=5
2 Correct 16 ms 23756 KB n=100
3 Correct 12 ms 23756 KB n=100
4 Correct 12 ms 23756 KB n=100
5 Correct 13 ms 23756 KB n=100
6 Correct 13 ms 23756 KB n=100
7 Correct 13 ms 23812 KB n=100
8 Correct 13 ms 23744 KB n=100
9 Correct 11 ms 23756 KB n=100
10 Correct 15 ms 23756 KB n=100
11 Correct 12 ms 23848 KB n=100
12 Correct 15 ms 23756 KB n=100
13 Correct 14 ms 23852 KB n=100
14 Correct 13 ms 23772 KB n=100
15 Correct 13 ms 23756 KB n=100
16 Correct 13 ms 23756 KB n=100
17 Correct 12 ms 23756 KB n=100
18 Correct 12 ms 23736 KB n=100
19 Correct 13 ms 23772 KB n=100
20 Correct 14 ms 23772 KB n=100
21 Correct 12 ms 23756 KB n=100
22 Correct 12 ms 23756 KB n=100
23 Correct 15 ms 23756 KB n=100
24 Correct 13 ms 23756 KB n=100
25 Correct 12 ms 23756 KB n=100
26 Correct 12 ms 23756 KB n=12
27 Correct 12 ms 23776 KB n=100
28 Correct 14 ms 23848 KB n=500
29 Correct 13 ms 23884 KB n=500
30 Correct 12 ms 23884 KB n=500
31 Correct 15 ms 23960 KB n=500
32 Correct 16 ms 23924 KB n=500
33 Correct 17 ms 23884 KB n=500
34 Correct 14 ms 23948 KB n=500
35 Correct 15 ms 23992 KB n=500
36 Correct 12 ms 23884 KB n=500
37 Correct 13 ms 23872 KB n=500
38 Correct 13 ms 23860 KB n=500
39 Correct 12 ms 23884 KB n=500
40 Correct 12 ms 23884 KB n=500
41 Correct 12 ms 23916 KB n=500
42 Correct 17 ms 23932 KB n=500
43 Correct 16 ms 23884 KB n=500
44 Correct 13 ms 23852 KB n=500
45 Correct 12 ms 23884 KB n=500
46 Correct 12 ms 23884 KB n=500
47 Correct 14 ms 23972 KB n=500
48 Correct 12 ms 23920 KB n=500
49 Correct 14 ms 23880 KB n=500
50 Correct 12 ms 23944 KB n=500
51 Correct 16 ms 23884 KB n=500
52 Correct 14 ms 24012 KB n=500
53 Correct 15 ms 23884 KB n=500
54 Correct 17 ms 23908 KB n=500
55 Correct 11 ms 23884 KB n=278
56 Correct 13 ms 23884 KB n=500
57 Correct 13 ms 23932 KB n=500
58 Correct 12 ms 23884 KB n=500
59 Correct 15 ms 24268 KB n=2000
60 Correct 14 ms 24396 KB n=2000
61 Correct 15 ms 24268 KB n=2000
62 Correct 16 ms 24252 KB n=2000
63 Correct 20 ms 24280 KB n=2000
64 Correct 16 ms 24268 KB n=2000
65 Correct 14 ms 24228 KB n=2000
66 Correct 15 ms 24268 KB n=2000
67 Correct 15 ms 24268 KB n=2000
68 Correct 14 ms 24336 KB n=2000
69 Correct 14 ms 24296 KB n=2000
70 Correct 15 ms 24212 KB n=2000
71 Correct 17 ms 24216 KB n=2000
72 Correct 16 ms 24272 KB n=2000
73 Correct 15 ms 24296 KB n=2000
74 Correct 16 ms 24196 KB n=1844
75 Correct 18 ms 24268 KB n=2000
76 Correct 15 ms 24268 KB n=2000
77 Correct 18 ms 24276 KB n=2000
78 Correct 19 ms 24268 KB n=2000
79 Correct 16 ms 24268 KB n=2000
80 Correct 14 ms 24268 KB n=2000
81 Correct 14 ms 24268 KB n=2000
82 Correct 16 ms 24192 KB n=2000
83 Correct 18 ms 24268 KB n=2000
84 Correct 18 ms 24284 KB n=2000
85 Correct 15 ms 24268 KB n=2000
86 Correct 16 ms 24308 KB n=2000
87 Correct 15 ms 24268 KB n=2000
88 Correct 14 ms 24400 KB n=2000
89 Correct 14 ms 24344 KB n=2000
90 Correct 15 ms 24396 KB n=2000
91 Correct 15 ms 24268 KB n=2000
92 Correct 744 ms 68932 KB n=200000
93 Correct 808 ms 74044 KB n=200000
94 Correct 570 ms 78648 KB n=200000
95 Correct 735 ms 68684 KB n=200000
96 Correct 716 ms 68668 KB n=200000
97 Correct 936 ms 73028 KB n=200000
98 Correct 773 ms 68684 KB n=200000
99 Correct 908 ms 68228 KB n=200000
100 Correct 772 ms 68820 KB n=200000
101 Correct 522 ms 80196 KB n=200000
102 Correct 435 ms 69664 KB n=200000
103 Correct 419 ms 69628 KB n=200000
104 Correct 441 ms 69604 KB n=200000
105 Correct 462 ms 69320 KB n=200000
106 Correct 462 ms 69436 KB n=200000
107 Correct 433 ms 69428 KB n=200000
108 Correct 749 ms 68372 KB n=200000
109 Correct 738 ms 68504 KB n=200000
110 Correct 758 ms 68376 KB n=200000
111 Correct 864 ms 68668 KB n=200000
112 Correct 584 ms 78796 KB n=200000
113 Correct 946 ms 72772 KB n=200000
114 Correct 862 ms 68672 KB n=200000
115 Correct 1050 ms 70108 KB n=200000
116 Correct 718 ms 68384 KB n=200000
117 Correct 534 ms 79276 KB n=200000
118 Correct 1051 ms 71236 KB n=200000
119 Correct 693 ms 68636 KB n=200000
120 Correct 533 ms 79996 KB n=200000
121 Correct 541 ms 80088 KB n=200000
122 Correct 502 ms 80476 KB n=200000
123 Correct 469 ms 69052 KB n=200000
124 Correct 196 ms 37192 KB n=25264