# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
672478 | 2022-12-16T10:23:26 Z | Cutebol | Birthday gift (IZhO18_treearray) | C++17 | 1118 ms | 102284 KB |
#include <bits/stdc++.h> using namespace std; void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} #define Scaramouche ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0); #define int long long #define itn int #define endl "\n" #define ff first #define ss second const int N = 2e5 + 5 ; const int mod = 1e9 + 7 ; const int inf = 1e12 ; int n , m , q , l = 1 , timer ; int tin[N] , tout[N] , a[N] ; vector <int> g[N] , up[N] ; set <int> par[N] , st[N] ; void dfs( int v , int p = 1 ){ tin[v] = ++timer ; up[v][0] = p ; for ( int i = 1 ; i <= l ; i ++ ) up[v][i] = up[up[v][i-1]][i-1] ; for ( auto to : g[v] ){ 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 = l ; i >= 0 ; i -- ) if ( !upper(up[a][i] , b) ) a = up[a][i] ; return up[a][0] ; } void solve(){ cin >> n >> m >> q ; while ( ( 1 << l ) <= n ) l ++ ; for ( int i = 0 ; i <= n ; i ++ ) up[i].resize(l+1) ; for ( int i = 1 ; i < n ; i ++ ){ int x , y ; cin >> x >> y ; g[x].push_back(y) ; g[y].push_back(x) ; } for ( int i = 1 ; i <= m ; i ++ ){ cin >> a[i] ; st[a[i]].insert(i) ;} dfs(1) ; for ( int i = 2 ; i <= m ; i ++ ) par[lca(a[i],a[i-1])].insert(i-1) ; while ( q -- ){ int tt ; cin >> tt ; if ( tt == 1 ){ int ind , val ; cin >> ind >> val ; st[a[ind]].erase(ind) ; st[val].insert(ind) ; if ( ind > 1 ){ par[lca(a[ind],a[ind-1])].erase(ind-1) ; par[lca(val,a[ind-1])].insert(ind-1) ; } if ( ind < m ){ par[lca(a[ind],a[ind+1])].erase(ind) ; par[lca(val,a[ind+1])].insert(ind) ; } a[ind] = val ; } else{ int l , r , v ; cin >> l >> r >> v ; auto f = st[v].lower_bound(l) ; if ( f != st[v].end() && *f <= r ){ cout << *f << ' ' << *f << endl ; continue ; } f = par[v].lower_bound(l) ; if ( f != par[v].end() && *f < r ) cout << *f << ' ' << *f+1 << endl ; else cout << "-1 -1\n" ; } } } signed main(){ // fopn("blocks") ; Scaramouche ; int t = 1 ; // cin >> t ; while ( t -- ) solve() ; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 28500 KB | n=5 |
2 | Correct | 14 ms | 28500 KB | n=100 |
3 | Correct | 13 ms | 28460 KB | n=100 |
4 | Correct | 14 ms | 28452 KB | n=100 |
5 | Correct | 14 ms | 28500 KB | n=100 |
6 | Correct | 14 ms | 28536 KB | n=100 |
7 | Correct | 13 ms | 28464 KB | n=100 |
8 | Correct | 13 ms | 28512 KB | n=100 |
9 | Correct | 17 ms | 28500 KB | n=100 |
10 | Correct | 14 ms | 28480 KB | n=100 |
11 | Correct | 14 ms | 28500 KB | n=100 |
12 | Correct | 14 ms | 28448 KB | n=100 |
13 | Correct | 14 ms | 28500 KB | n=100 |
14 | Correct | 14 ms | 28520 KB | n=100 |
15 | Correct | 14 ms | 28500 KB | n=100 |
16 | Correct | 15 ms | 28428 KB | n=100 |
17 | Correct | 13 ms | 28536 KB | n=100 |
18 | Correct | 16 ms | 28500 KB | n=100 |
19 | Correct | 13 ms | 28424 KB | n=100 |
20 | Correct | 13 ms | 28476 KB | n=100 |
21 | Correct | 14 ms | 28500 KB | n=100 |
22 | Correct | 14 ms | 28524 KB | n=100 |
23 | Correct | 14 ms | 28436 KB | n=100 |
24 | Correct | 14 ms | 28448 KB | n=100 |
25 | Correct | 15 ms | 28432 KB | n=100 |
26 | Correct | 14 ms | 28456 KB | n=12 |
27 | Correct | 14 ms | 28500 KB | n=100 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 28500 KB | n=5 |
2 | Correct | 14 ms | 28500 KB | n=100 |
3 | Correct | 13 ms | 28460 KB | n=100 |
4 | Correct | 14 ms | 28452 KB | n=100 |
5 | Correct | 14 ms | 28500 KB | n=100 |
6 | Correct | 14 ms | 28536 KB | n=100 |
7 | Correct | 13 ms | 28464 KB | n=100 |
8 | Correct | 13 ms | 28512 KB | n=100 |
9 | Correct | 17 ms | 28500 KB | n=100 |
10 | Correct | 14 ms | 28480 KB | n=100 |
11 | Correct | 14 ms | 28500 KB | n=100 |
12 | Correct | 14 ms | 28448 KB | n=100 |
13 | Correct | 14 ms | 28500 KB | n=100 |
14 | Correct | 14 ms | 28520 KB | n=100 |
15 | Correct | 14 ms | 28500 KB | n=100 |
16 | Correct | 15 ms | 28428 KB | n=100 |
17 | Correct | 13 ms | 28536 KB | n=100 |
18 | Correct | 16 ms | 28500 KB | n=100 |
19 | Correct | 13 ms | 28424 KB | n=100 |
20 | Correct | 13 ms | 28476 KB | n=100 |
21 | Correct | 14 ms | 28500 KB | n=100 |
22 | Correct | 14 ms | 28524 KB | n=100 |
23 | Correct | 14 ms | 28436 KB | n=100 |
24 | Correct | 14 ms | 28448 KB | n=100 |
25 | Correct | 15 ms | 28432 KB | n=100 |
26 | Correct | 14 ms | 28456 KB | n=12 |
27 | Correct | 14 ms | 28500 KB | n=100 |
28 | Correct | 15 ms | 28684 KB | n=500 |
29 | Correct | 15 ms | 28632 KB | n=500 |
30 | Correct | 15 ms | 28628 KB | n=500 |
31 | Correct | 14 ms | 28644 KB | n=500 |
32 | Correct | 14 ms | 28628 KB | n=500 |
33 | Correct | 15 ms | 28596 KB | n=500 |
34 | Correct | 14 ms | 28620 KB | n=500 |
35 | Correct | 14 ms | 28628 KB | n=500 |
36 | Correct | 13 ms | 28652 KB | n=500 |
37 | Correct | 15 ms | 28648 KB | n=500 |
38 | Correct | 16 ms | 28588 KB | n=500 |
39 | Correct | 14 ms | 28628 KB | n=500 |
40 | Correct | 14 ms | 28628 KB | n=500 |
41 | Correct | 14 ms | 28628 KB | n=500 |
42 | Correct | 14 ms | 28568 KB | n=500 |
43 | Correct | 14 ms | 28628 KB | n=500 |
44 | Correct | 15 ms | 28576 KB | n=500 |
45 | Correct | 17 ms | 28628 KB | n=500 |
46 | Correct | 15 ms | 28628 KB | n=500 |
47 | Correct | 15 ms | 28628 KB | n=500 |
48 | Correct | 15 ms | 28636 KB | n=500 |
49 | Correct | 15 ms | 28772 KB | n=500 |
50 | Correct | 15 ms | 28656 KB | n=500 |
51 | Correct | 14 ms | 28540 KB | n=500 |
52 | Correct | 15 ms | 28660 KB | n=500 |
53 | Correct | 16 ms | 28600 KB | n=500 |
54 | Correct | 14 ms | 28628 KB | n=500 |
55 | Correct | 15 ms | 28508 KB | n=278 |
56 | Correct | 15 ms | 28628 KB | n=500 |
57 | Correct | 16 ms | 28616 KB | n=500 |
58 | Correct | 15 ms | 28584 KB | n=500 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 28500 KB | n=5 |
2 | Correct | 14 ms | 28500 KB | n=100 |
3 | Correct | 13 ms | 28460 KB | n=100 |
4 | Correct | 14 ms | 28452 KB | n=100 |
5 | Correct | 14 ms | 28500 KB | n=100 |
6 | Correct | 14 ms | 28536 KB | n=100 |
7 | Correct | 13 ms | 28464 KB | n=100 |
8 | Correct | 13 ms | 28512 KB | n=100 |
9 | Correct | 17 ms | 28500 KB | n=100 |
10 | Correct | 14 ms | 28480 KB | n=100 |
11 | Correct | 14 ms | 28500 KB | n=100 |
12 | Correct | 14 ms | 28448 KB | n=100 |
13 | Correct | 14 ms | 28500 KB | n=100 |
14 | Correct | 14 ms | 28520 KB | n=100 |
15 | Correct | 14 ms | 28500 KB | n=100 |
16 | Correct | 15 ms | 28428 KB | n=100 |
17 | Correct | 13 ms | 28536 KB | n=100 |
18 | Correct | 16 ms | 28500 KB | n=100 |
19 | Correct | 13 ms | 28424 KB | n=100 |
20 | Correct | 13 ms | 28476 KB | n=100 |
21 | Correct | 14 ms | 28500 KB | n=100 |
22 | Correct | 14 ms | 28524 KB | n=100 |
23 | Correct | 14 ms | 28436 KB | n=100 |
24 | Correct | 14 ms | 28448 KB | n=100 |
25 | Correct | 15 ms | 28432 KB | n=100 |
26 | Correct | 14 ms | 28456 KB | n=12 |
27 | Correct | 14 ms | 28500 KB | n=100 |
28 | Correct | 15 ms | 28684 KB | n=500 |
29 | Correct | 15 ms | 28632 KB | n=500 |
30 | Correct | 15 ms | 28628 KB | n=500 |
31 | Correct | 14 ms | 28644 KB | n=500 |
32 | Correct | 14 ms | 28628 KB | n=500 |
33 | Correct | 15 ms | 28596 KB | n=500 |
34 | Correct | 14 ms | 28620 KB | n=500 |
35 | Correct | 14 ms | 28628 KB | n=500 |
36 | Correct | 13 ms | 28652 KB | n=500 |
37 | Correct | 15 ms | 28648 KB | n=500 |
38 | Correct | 16 ms | 28588 KB | n=500 |
39 | Correct | 14 ms | 28628 KB | n=500 |
40 | Correct | 14 ms | 28628 KB | n=500 |
41 | Correct | 14 ms | 28628 KB | n=500 |
42 | Correct | 14 ms | 28568 KB | n=500 |
43 | Correct | 14 ms | 28628 KB | n=500 |
44 | Correct | 15 ms | 28576 KB | n=500 |
45 | Correct | 17 ms | 28628 KB | n=500 |
46 | Correct | 15 ms | 28628 KB | n=500 |
47 | Correct | 15 ms | 28628 KB | n=500 |
48 | Correct | 15 ms | 28636 KB | n=500 |
49 | Correct | 15 ms | 28772 KB | n=500 |
50 | Correct | 15 ms | 28656 KB | n=500 |
51 | Correct | 14 ms | 28540 KB | n=500 |
52 | Correct | 15 ms | 28660 KB | n=500 |
53 | Correct | 16 ms | 28600 KB | n=500 |
54 | Correct | 14 ms | 28628 KB | n=500 |
55 | Correct | 15 ms | 28508 KB | n=278 |
56 | Correct | 15 ms | 28628 KB | n=500 |
57 | Correct | 16 ms | 28616 KB | n=500 |
58 | Correct | 15 ms | 28584 KB | n=500 |
59 | Correct | 17 ms | 29012 KB | n=2000 |
60 | Correct | 17 ms | 29012 KB | n=2000 |
61 | Correct | 16 ms | 29012 KB | n=2000 |
62 | Correct | 17 ms | 29012 KB | n=2000 |
63 | Correct | 20 ms | 29116 KB | n=2000 |
64 | Correct | 19 ms | 29012 KB | n=2000 |
65 | Correct | 18 ms | 29080 KB | n=2000 |
66 | Correct | 16 ms | 29012 KB | n=2000 |
67 | Correct | 17 ms | 29012 KB | n=2000 |
68 | Correct | 18 ms | 29012 KB | n=2000 |
69 | Correct | 17 ms | 29056 KB | n=2000 |
70 | Correct | 16 ms | 29016 KB | n=2000 |
71 | Correct | 16 ms | 29012 KB | n=2000 |
72 | Correct | 17 ms | 29012 KB | n=2000 |
73 | Correct | 16 ms | 29052 KB | n=2000 |
74 | Correct | 17 ms | 28924 KB | n=1844 |
75 | Correct | 16 ms | 29012 KB | n=2000 |
76 | Correct | 17 ms | 28956 KB | n=2000 |
77 | Correct | 18 ms | 28956 KB | n=2000 |
78 | Correct | 17 ms | 29060 KB | n=2000 |
79 | Correct | 16 ms | 29064 KB | n=2000 |
80 | Correct | 16 ms | 29040 KB | n=2000 |
81 | Correct | 16 ms | 29048 KB | n=2000 |
82 | Correct | 17 ms | 29012 KB | n=2000 |
83 | Correct | 17 ms | 29080 KB | n=2000 |
84 | Correct | 16 ms | 28944 KB | n=2000 |
85 | Correct | 17 ms | 29028 KB | n=2000 |
86 | Correct | 17 ms | 29076 KB | n=2000 |
87 | Correct | 17 ms | 29012 KB | n=2000 |
88 | Correct | 17 ms | 29104 KB | n=2000 |
89 | Correct | 16 ms | 29100 KB | n=2000 |
90 | Correct | 16 ms | 29124 KB | n=2000 |
91 | Correct | 19 ms | 29020 KB | n=2000 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 28500 KB | n=5 |
2 | Correct | 14 ms | 28500 KB | n=100 |
3 | Correct | 13 ms | 28460 KB | n=100 |
4 | Correct | 14 ms | 28452 KB | n=100 |
5 | Correct | 14 ms | 28500 KB | n=100 |
6 | Correct | 14 ms | 28536 KB | n=100 |
7 | Correct | 13 ms | 28464 KB | n=100 |
8 | Correct | 13 ms | 28512 KB | n=100 |
9 | Correct | 17 ms | 28500 KB | n=100 |
10 | Correct | 14 ms | 28480 KB | n=100 |
11 | Correct | 14 ms | 28500 KB | n=100 |
12 | Correct | 14 ms | 28448 KB | n=100 |
13 | Correct | 14 ms | 28500 KB | n=100 |
14 | Correct | 14 ms | 28520 KB | n=100 |
15 | Correct | 14 ms | 28500 KB | n=100 |
16 | Correct | 15 ms | 28428 KB | n=100 |
17 | Correct | 13 ms | 28536 KB | n=100 |
18 | Correct | 16 ms | 28500 KB | n=100 |
19 | Correct | 13 ms | 28424 KB | n=100 |
20 | Correct | 13 ms | 28476 KB | n=100 |
21 | Correct | 14 ms | 28500 KB | n=100 |
22 | Correct | 14 ms | 28524 KB | n=100 |
23 | Correct | 14 ms | 28436 KB | n=100 |
24 | Correct | 14 ms | 28448 KB | n=100 |
25 | Correct | 15 ms | 28432 KB | n=100 |
26 | Correct | 14 ms | 28456 KB | n=12 |
27 | Correct | 14 ms | 28500 KB | n=100 |
28 | Correct | 15 ms | 28684 KB | n=500 |
29 | Correct | 15 ms | 28632 KB | n=500 |
30 | Correct | 15 ms | 28628 KB | n=500 |
31 | Correct | 14 ms | 28644 KB | n=500 |
32 | Correct | 14 ms | 28628 KB | n=500 |
33 | Correct | 15 ms | 28596 KB | n=500 |
34 | Correct | 14 ms | 28620 KB | n=500 |
35 | Correct | 14 ms | 28628 KB | n=500 |
36 | Correct | 13 ms | 28652 KB | n=500 |
37 | Correct | 15 ms | 28648 KB | n=500 |
38 | Correct | 16 ms | 28588 KB | n=500 |
39 | Correct | 14 ms | 28628 KB | n=500 |
40 | Correct | 14 ms | 28628 KB | n=500 |
41 | Correct | 14 ms | 28628 KB | n=500 |
42 | Correct | 14 ms | 28568 KB | n=500 |
43 | Correct | 14 ms | 28628 KB | n=500 |
44 | Correct | 15 ms | 28576 KB | n=500 |
45 | Correct | 17 ms | 28628 KB | n=500 |
46 | Correct | 15 ms | 28628 KB | n=500 |
47 | Correct | 15 ms | 28628 KB | n=500 |
48 | Correct | 15 ms | 28636 KB | n=500 |
49 | Correct | 15 ms | 28772 KB | n=500 |
50 | Correct | 15 ms | 28656 KB | n=500 |
51 | Correct | 14 ms | 28540 KB | n=500 |
52 | Correct | 15 ms | 28660 KB | n=500 |
53 | Correct | 16 ms | 28600 KB | n=500 |
54 | Correct | 14 ms | 28628 KB | n=500 |
55 | Correct | 15 ms | 28508 KB | n=278 |
56 | Correct | 15 ms | 28628 KB | n=500 |
57 | Correct | 16 ms | 28616 KB | n=500 |
58 | Correct | 15 ms | 28584 KB | n=500 |
59 | Correct | 17 ms | 29012 KB | n=2000 |
60 | Correct | 17 ms | 29012 KB | n=2000 |
61 | Correct | 16 ms | 29012 KB | n=2000 |
62 | Correct | 17 ms | 29012 KB | n=2000 |
63 | Correct | 20 ms | 29116 KB | n=2000 |
64 | Correct | 19 ms | 29012 KB | n=2000 |
65 | Correct | 18 ms | 29080 KB | n=2000 |
66 | Correct | 16 ms | 29012 KB | n=2000 |
67 | Correct | 17 ms | 29012 KB | n=2000 |
68 | Correct | 18 ms | 29012 KB | n=2000 |
69 | Correct | 17 ms | 29056 KB | n=2000 |
70 | Correct | 16 ms | 29016 KB | n=2000 |
71 | Correct | 16 ms | 29012 KB | n=2000 |
72 | Correct | 17 ms | 29012 KB | n=2000 |
73 | Correct | 16 ms | 29052 KB | n=2000 |
74 | Correct | 17 ms | 28924 KB | n=1844 |
75 | Correct | 16 ms | 29012 KB | n=2000 |
76 | Correct | 17 ms | 28956 KB | n=2000 |
77 | Correct | 18 ms | 28956 KB | n=2000 |
78 | Correct | 17 ms | 29060 KB | n=2000 |
79 | Correct | 16 ms | 29064 KB | n=2000 |
80 | Correct | 16 ms | 29040 KB | n=2000 |
81 | Correct | 16 ms | 29048 KB | n=2000 |
82 | Correct | 17 ms | 29012 KB | n=2000 |
83 | Correct | 17 ms | 29080 KB | n=2000 |
84 | Correct | 16 ms | 28944 KB | n=2000 |
85 | Correct | 17 ms | 29028 KB | n=2000 |
86 | Correct | 17 ms | 29076 KB | n=2000 |
87 | Correct | 17 ms | 29012 KB | n=2000 |
88 | Correct | 17 ms | 29104 KB | n=2000 |
89 | Correct | 16 ms | 29100 KB | n=2000 |
90 | Correct | 16 ms | 29124 KB | n=2000 |
91 | Correct | 19 ms | 29020 KB | n=2000 |
92 | Correct | 664 ms | 94688 KB | n=200000 |
93 | Correct | 848 ms | 98352 KB | n=200000 |
94 | Correct | 616 ms | 101184 KB | n=200000 |
95 | Correct | 659 ms | 94516 KB | n=200000 |
96 | Correct | 642 ms | 94440 KB | n=200000 |
97 | Correct | 937 ms | 97456 KB | n=200000 |
98 | Correct | 664 ms | 94528 KB | n=200000 |
99 | Correct | 804 ms | 94144 KB | n=200000 |
100 | Correct | 683 ms | 94648 KB | n=200000 |
101 | Correct | 565 ms | 102176 KB | n=200000 |
102 | Correct | 441 ms | 95640 KB | n=200000 |
103 | Correct | 459 ms | 95852 KB | n=200000 |
104 | Correct | 454 ms | 95592 KB | n=200000 |
105 | Correct | 465 ms | 95376 KB | n=200000 |
106 | Correct | 457 ms | 95344 KB | n=200000 |
107 | Correct | 497 ms | 95356 KB | n=200000 |
108 | Correct | 736 ms | 94420 KB | n=200000 |
109 | Correct | 734 ms | 94296 KB | n=200000 |
110 | Correct | 756 ms | 94324 KB | n=200000 |
111 | Correct | 677 ms | 94468 KB | n=200000 |
112 | Correct | 601 ms | 101420 KB | n=200000 |
113 | Correct | 909 ms | 97516 KB | n=200000 |
114 | Correct | 666 ms | 94380 KB | n=200000 |
115 | Correct | 1118 ms | 95432 KB | n=200000 |
116 | Correct | 647 ms | 94176 KB | n=200000 |
117 | Correct | 568 ms | 101592 KB | n=200000 |
118 | Correct | 1052 ms | 96324 KB | n=200000 |
119 | Correct | 639 ms | 94212 KB | n=200000 |
120 | Correct | 539 ms | 101776 KB | n=200000 |
121 | Correct | 505 ms | 101756 KB | n=200000 |
122 | Correct | 554 ms | 102284 KB | n=200000 |
123 | Correct | 521 ms | 94940 KB | n=200000 |
124 | Correct | 163 ms | 44320 KB | n=25264 |