# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334921 | 2020-12-10T09:14:08 Z | beksultan04 | Birthday gift (IZhO18_treearray) | C++14 | 1469 ms | 128364 KB |
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define OK puts("OK"); #define fr first #define sc second #define ret return #define scan1(a) scanf("%lld",&a); #define scan2(a,b) scanf("%lld %lld",&a, &b); #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c); #define all(s) s.begin(),s.end() #define pb push_back #define endi puts(""); const int N = 2e5+12,INF=1e9+7; int q[N],z[N],up[N][40],tin[N],tout[N],cnt; vector <int> g[N]; set <int> s[N],ans[N]; void dfs(int x,int p){ int i; tin[x]=++cnt; up[x][0]=p; for (i=1;i<20;++i) up[x][i]= up[up[x][i-1]][i-1]; for (i=0;i<g[x].size();++i){ if (g[x][i] != p){ dfs(g[x][i],x); } } tout[x] = ++cnt; } bool upper(int a,int b){ ret (tin[a] <= tin[b] && tout[a] >= tout[b]); } int lca(int a,int b){ int i; if (upper(a,b))ret a; if (upper(b,a))ret b; for(i=19;i>=0;--i){ if (!upper(up[a][i],b)){ a = up[a][i]; } } ret up[a][0]; } main(){ int n,m,t,i,j; scan3(n,m,t) for (i=1;i<n;++i){ int x,y; scan2(x,y) g[x].pb(y); g[y].pb(x); } dfs(1,1); for (i=1;i<=m;++i) scan1(q[i]) for (i=1;i<=m;++i){ s[q[i]].insert(i); z[i]=q[i]; } for (i=1;i<m;++i){ int c = lca(q[i],q[i+1]); ans[c].insert(i); } while (t--){ int type; scan1(type) if (type == 1){ int a,b; scan2(a,b) if (a > 1){ int lc = lca(z[a],z[a-1]); ans[lc].erase(a-1); } if (a < m){ int lc = lca(z[a],z[a+1]); ans[lc].erase(a); } s[z[a]].erase(a); z[a] = b; if (a > 1){ int lc = lca(z[a],z[a-1]); ans[lc].insert(a-1); } if (a < m){ int lc = lca(z[a],z[a+1]); ans[lc].insert(a); } s[z[a]].insert(a); } else { int l,r,v,ll=-1,rr=-1; scan3(l,r,v) auto it = ans[v].lower_bound(l); if (it != ans[v].end()){ if (*it < r){ ll = *it; rr = ll+1; } } it = s[v].lower_bound(l); if (it != s[v].end() && *it <= r){ ll = rr = *it; } cout <<ll<<" "<<rr<<"\n"; } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 23788 KB | n=5 |
2 | Correct | 15 ms | 23916 KB | n=100 |
3 | Correct | 15 ms | 23916 KB | n=100 |
4 | Correct | 17 ms | 23916 KB | n=100 |
5 | Correct | 15 ms | 23916 KB | n=100 |
6 | Correct | 17 ms | 23916 KB | n=100 |
7 | Correct | 17 ms | 23916 KB | n=100 |
8 | Correct | 18 ms | 23948 KB | n=100 |
9 | Correct | 16 ms | 23916 KB | n=100 |
10 | Correct | 17 ms | 23916 KB | n=100 |
11 | Correct | 15 ms | 23916 KB | n=100 |
12 | Correct | 16 ms | 23916 KB | n=100 |
13 | Correct | 16 ms | 23916 KB | n=100 |
14 | Correct | 19 ms | 23916 KB | n=100 |
15 | Correct | 16 ms | 23916 KB | n=100 |
16 | Correct | 18 ms | 24060 KB | n=100 |
17 | Correct | 15 ms | 23916 KB | n=100 |
18 | Correct | 15 ms | 23916 KB | n=100 |
19 | Correct | 16 ms | 23916 KB | n=100 |
20 | Correct | 18 ms | 23916 KB | n=100 |
21 | Correct | 16 ms | 23916 KB | n=100 |
22 | Correct | 16 ms | 23916 KB | n=100 |
23 | Correct | 16 ms | 23916 KB | n=100 |
24 | Correct | 15 ms | 23916 KB | n=100 |
25 | Correct | 15 ms | 23916 KB | n=100 |
26 | Correct | 15 ms | 23808 KB | n=12 |
27 | Correct | 15 ms | 23916 KB | n=100 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 23788 KB | n=5 |
2 | Correct | 15 ms | 23916 KB | n=100 |
3 | Correct | 15 ms | 23916 KB | n=100 |
4 | Correct | 17 ms | 23916 KB | n=100 |
5 | Correct | 15 ms | 23916 KB | n=100 |
6 | Correct | 17 ms | 23916 KB | n=100 |
7 | Correct | 17 ms | 23916 KB | n=100 |
8 | Correct | 18 ms | 23948 KB | n=100 |
9 | Correct | 16 ms | 23916 KB | n=100 |
10 | Correct | 17 ms | 23916 KB | n=100 |
11 | Correct | 15 ms | 23916 KB | n=100 |
12 | Correct | 16 ms | 23916 KB | n=100 |
13 | Correct | 16 ms | 23916 KB | n=100 |
14 | Correct | 19 ms | 23916 KB | n=100 |
15 | Correct | 16 ms | 23916 KB | n=100 |
16 | Correct | 18 ms | 24060 KB | n=100 |
17 | Correct | 15 ms | 23916 KB | n=100 |
18 | Correct | 15 ms | 23916 KB | n=100 |
19 | Correct | 16 ms | 23916 KB | n=100 |
20 | Correct | 18 ms | 23916 KB | n=100 |
21 | Correct | 16 ms | 23916 KB | n=100 |
22 | Correct | 16 ms | 23916 KB | n=100 |
23 | Correct | 16 ms | 23916 KB | n=100 |
24 | Correct | 15 ms | 23916 KB | n=100 |
25 | Correct | 15 ms | 23916 KB | n=100 |
26 | Correct | 15 ms | 23808 KB | n=12 |
27 | Correct | 15 ms | 23916 KB | n=100 |
28 | Correct | 17 ms | 24044 KB | n=500 |
29 | Correct | 22 ms | 24044 KB | n=500 |
30 | Correct | 16 ms | 24044 KB | n=500 |
31 | Correct | 19 ms | 24044 KB | n=500 |
32 | Correct | 19 ms | 24044 KB | n=500 |
33 | Correct | 17 ms | 24044 KB | n=500 |
34 | Correct | 17 ms | 24044 KB | n=500 |
35 | Correct | 16 ms | 24044 KB | n=500 |
36 | Correct | 17 ms | 24044 KB | n=500 |
37 | Correct | 17 ms | 24064 KB | n=500 |
38 | Correct | 16 ms | 24044 KB | n=500 |
39 | Correct | 16 ms | 24044 KB | n=500 |
40 | Correct | 16 ms | 24044 KB | n=500 |
41 | Correct | 16 ms | 24044 KB | n=500 |
42 | Correct | 17 ms | 24044 KB | n=500 |
43 | Correct | 16 ms | 24044 KB | n=500 |
44 | Correct | 17 ms | 24044 KB | n=500 |
45 | Correct | 17 ms | 24044 KB | n=500 |
46 | Correct | 16 ms | 24044 KB | n=500 |
47 | Correct | 16 ms | 24044 KB | n=500 |
48 | Correct | 17 ms | 24044 KB | n=500 |
49 | Correct | 16 ms | 24044 KB | n=500 |
50 | Correct | 17 ms | 24044 KB | n=500 |
51 | Correct | 18 ms | 24044 KB | n=500 |
52 | Correct | 17 ms | 24044 KB | n=500 |
53 | Correct | 18 ms | 24044 KB | n=500 |
54 | Correct | 16 ms | 24044 KB | n=500 |
55 | Correct | 21 ms | 23916 KB | n=278 |
56 | Correct | 17 ms | 24044 KB | n=500 |
57 | Correct | 16 ms | 24044 KB | n=500 |
58 | Correct | 17 ms | 24044 KB | n=500 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 23788 KB | n=5 |
2 | Correct | 15 ms | 23916 KB | n=100 |
3 | Correct | 15 ms | 23916 KB | n=100 |
4 | Correct | 17 ms | 23916 KB | n=100 |
5 | Correct | 15 ms | 23916 KB | n=100 |
6 | Correct | 17 ms | 23916 KB | n=100 |
7 | Correct | 17 ms | 23916 KB | n=100 |
8 | Correct | 18 ms | 23948 KB | n=100 |
9 | Correct | 16 ms | 23916 KB | n=100 |
10 | Correct | 17 ms | 23916 KB | n=100 |
11 | Correct | 15 ms | 23916 KB | n=100 |
12 | Correct | 16 ms | 23916 KB | n=100 |
13 | Correct | 16 ms | 23916 KB | n=100 |
14 | Correct | 19 ms | 23916 KB | n=100 |
15 | Correct | 16 ms | 23916 KB | n=100 |
16 | Correct | 18 ms | 24060 KB | n=100 |
17 | Correct | 15 ms | 23916 KB | n=100 |
18 | Correct | 15 ms | 23916 KB | n=100 |
19 | Correct | 16 ms | 23916 KB | n=100 |
20 | Correct | 18 ms | 23916 KB | n=100 |
21 | Correct | 16 ms | 23916 KB | n=100 |
22 | Correct | 16 ms | 23916 KB | n=100 |
23 | Correct | 16 ms | 23916 KB | n=100 |
24 | Correct | 15 ms | 23916 KB | n=100 |
25 | Correct | 15 ms | 23916 KB | n=100 |
26 | Correct | 15 ms | 23808 KB | n=12 |
27 | Correct | 15 ms | 23916 KB | n=100 |
28 | Correct | 17 ms | 24044 KB | n=500 |
29 | Correct | 22 ms | 24044 KB | n=500 |
30 | Correct | 16 ms | 24044 KB | n=500 |
31 | Correct | 19 ms | 24044 KB | n=500 |
32 | Correct | 19 ms | 24044 KB | n=500 |
33 | Correct | 17 ms | 24044 KB | n=500 |
34 | Correct | 17 ms | 24044 KB | n=500 |
35 | Correct | 16 ms | 24044 KB | n=500 |
36 | Correct | 17 ms | 24044 KB | n=500 |
37 | Correct | 17 ms | 24064 KB | n=500 |
38 | Correct | 16 ms | 24044 KB | n=500 |
39 | Correct | 16 ms | 24044 KB | n=500 |
40 | Correct | 16 ms | 24044 KB | n=500 |
41 | Correct | 16 ms | 24044 KB | n=500 |
42 | Correct | 17 ms | 24044 KB | n=500 |
43 | Correct | 16 ms | 24044 KB | n=500 |
44 | Correct | 17 ms | 24044 KB | n=500 |
45 | Correct | 17 ms | 24044 KB | n=500 |
46 | Correct | 16 ms | 24044 KB | n=500 |
47 | Correct | 16 ms | 24044 KB | n=500 |
48 | Correct | 17 ms | 24044 KB | n=500 |
49 | Correct | 16 ms | 24044 KB | n=500 |
50 | Correct | 17 ms | 24044 KB | n=500 |
51 | Correct | 18 ms | 24044 KB | n=500 |
52 | Correct | 17 ms | 24044 KB | n=500 |
53 | Correct | 18 ms | 24044 KB | n=500 |
54 | Correct | 16 ms | 24044 KB | n=500 |
55 | Correct | 21 ms | 23916 KB | n=278 |
56 | Correct | 17 ms | 24044 KB | n=500 |
57 | Correct | 16 ms | 24044 KB | n=500 |
58 | Correct | 17 ms | 24044 KB | n=500 |
59 | Correct | 21 ms | 24812 KB | n=2000 |
60 | Correct | 21 ms | 24812 KB | n=2000 |
61 | Correct | 20 ms | 24812 KB | n=2000 |
62 | Correct | 25 ms | 24960 KB | n=2000 |
63 | Correct | 20 ms | 24812 KB | n=2000 |
64 | Correct | 24 ms | 24812 KB | n=2000 |
65 | Correct | 20 ms | 24812 KB | n=2000 |
66 | Correct | 19 ms | 24812 KB | n=2000 |
67 | Correct | 20 ms | 24812 KB | n=2000 |
68 | Correct | 20 ms | 24812 KB | n=2000 |
69 | Correct | 19 ms | 24812 KB | n=2000 |
70 | Correct | 19 ms | 24812 KB | n=2000 |
71 | Correct | 19 ms | 24812 KB | n=2000 |
72 | Correct | 19 ms | 24812 KB | n=2000 |
73 | Correct | 19 ms | 24812 KB | n=2000 |
74 | Correct | 20 ms | 24556 KB | n=1844 |
75 | Correct | 19 ms | 24812 KB | n=2000 |
76 | Correct | 20 ms | 24812 KB | n=2000 |
77 | Correct | 20 ms | 24812 KB | n=2000 |
78 | Correct | 20 ms | 24812 KB | n=2000 |
79 | Correct | 20 ms | 24812 KB | n=2000 |
80 | Correct | 19 ms | 24812 KB | n=2000 |
81 | Correct | 20 ms | 24812 KB | n=2000 |
82 | Correct | 20 ms | 24828 KB | n=2000 |
83 | Correct | 19 ms | 24812 KB | n=2000 |
84 | Correct | 20 ms | 24812 KB | n=2000 |
85 | Correct | 20 ms | 24812 KB | n=2000 |
86 | Correct | 21 ms | 24876 KB | n=2000 |
87 | Correct | 20 ms | 24812 KB | n=2000 |
88 | Correct | 19 ms | 24812 KB | n=2000 |
89 | Correct | 19 ms | 24812 KB | n=2000 |
90 | Correct | 19 ms | 24812 KB | n=2000 |
91 | Correct | 19 ms | 24812 KB | n=2000 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 23788 KB | n=5 |
2 | Correct | 15 ms | 23916 KB | n=100 |
3 | Correct | 15 ms | 23916 KB | n=100 |
4 | Correct | 17 ms | 23916 KB | n=100 |
5 | Correct | 15 ms | 23916 KB | n=100 |
6 | Correct | 17 ms | 23916 KB | n=100 |
7 | Correct | 17 ms | 23916 KB | n=100 |
8 | Correct | 18 ms | 23948 KB | n=100 |
9 | Correct | 16 ms | 23916 KB | n=100 |
10 | Correct | 17 ms | 23916 KB | n=100 |
11 | Correct | 15 ms | 23916 KB | n=100 |
12 | Correct | 16 ms | 23916 KB | n=100 |
13 | Correct | 16 ms | 23916 KB | n=100 |
14 | Correct | 19 ms | 23916 KB | n=100 |
15 | Correct | 16 ms | 23916 KB | n=100 |
16 | Correct | 18 ms | 24060 KB | n=100 |
17 | Correct | 15 ms | 23916 KB | n=100 |
18 | Correct | 15 ms | 23916 KB | n=100 |
19 | Correct | 16 ms | 23916 KB | n=100 |
20 | Correct | 18 ms | 23916 KB | n=100 |
21 | Correct | 16 ms | 23916 KB | n=100 |
22 | Correct | 16 ms | 23916 KB | n=100 |
23 | Correct | 16 ms | 23916 KB | n=100 |
24 | Correct | 15 ms | 23916 KB | n=100 |
25 | Correct | 15 ms | 23916 KB | n=100 |
26 | Correct | 15 ms | 23808 KB | n=12 |
27 | Correct | 15 ms | 23916 KB | n=100 |
28 | Correct | 17 ms | 24044 KB | n=500 |
29 | Correct | 22 ms | 24044 KB | n=500 |
30 | Correct | 16 ms | 24044 KB | n=500 |
31 | Correct | 19 ms | 24044 KB | n=500 |
32 | Correct | 19 ms | 24044 KB | n=500 |
33 | Correct | 17 ms | 24044 KB | n=500 |
34 | Correct | 17 ms | 24044 KB | n=500 |
35 | Correct | 16 ms | 24044 KB | n=500 |
36 | Correct | 17 ms | 24044 KB | n=500 |
37 | Correct | 17 ms | 24064 KB | n=500 |
38 | Correct | 16 ms | 24044 KB | n=500 |
39 | Correct | 16 ms | 24044 KB | n=500 |
40 | Correct | 16 ms | 24044 KB | n=500 |
41 | Correct | 16 ms | 24044 KB | n=500 |
42 | Correct | 17 ms | 24044 KB | n=500 |
43 | Correct | 16 ms | 24044 KB | n=500 |
44 | Correct | 17 ms | 24044 KB | n=500 |
45 | Correct | 17 ms | 24044 KB | n=500 |
46 | Correct | 16 ms | 24044 KB | n=500 |
47 | Correct | 16 ms | 24044 KB | n=500 |
48 | Correct | 17 ms | 24044 KB | n=500 |
49 | Correct | 16 ms | 24044 KB | n=500 |
50 | Correct | 17 ms | 24044 KB | n=500 |
51 | Correct | 18 ms | 24044 KB | n=500 |
52 | Correct | 17 ms | 24044 KB | n=500 |
53 | Correct | 18 ms | 24044 KB | n=500 |
54 | Correct | 16 ms | 24044 KB | n=500 |
55 | Correct | 21 ms | 23916 KB | n=278 |
56 | Correct | 17 ms | 24044 KB | n=500 |
57 | Correct | 16 ms | 24044 KB | n=500 |
58 | Correct | 17 ms | 24044 KB | n=500 |
59 | Correct | 21 ms | 24812 KB | n=2000 |
60 | Correct | 21 ms | 24812 KB | n=2000 |
61 | Correct | 20 ms | 24812 KB | n=2000 |
62 | Correct | 25 ms | 24960 KB | n=2000 |
63 | Correct | 20 ms | 24812 KB | n=2000 |
64 | Correct | 24 ms | 24812 KB | n=2000 |
65 | Correct | 20 ms | 24812 KB | n=2000 |
66 | Correct | 19 ms | 24812 KB | n=2000 |
67 | Correct | 20 ms | 24812 KB | n=2000 |
68 | Correct | 20 ms | 24812 KB | n=2000 |
69 | Correct | 19 ms | 24812 KB | n=2000 |
70 | Correct | 19 ms | 24812 KB | n=2000 |
71 | Correct | 19 ms | 24812 KB | n=2000 |
72 | Correct | 19 ms | 24812 KB | n=2000 |
73 | Correct | 19 ms | 24812 KB | n=2000 |
74 | Correct | 20 ms | 24556 KB | n=1844 |
75 | Correct | 19 ms | 24812 KB | n=2000 |
76 | Correct | 20 ms | 24812 KB | n=2000 |
77 | Correct | 20 ms | 24812 KB | n=2000 |
78 | Correct | 20 ms | 24812 KB | n=2000 |
79 | Correct | 20 ms | 24812 KB | n=2000 |
80 | Correct | 19 ms | 24812 KB | n=2000 |
81 | Correct | 20 ms | 24812 KB | n=2000 |
82 | Correct | 20 ms | 24828 KB | n=2000 |
83 | Correct | 19 ms | 24812 KB | n=2000 |
84 | Correct | 20 ms | 24812 KB | n=2000 |
85 | Correct | 20 ms | 24812 KB | n=2000 |
86 | Correct | 21 ms | 24876 KB | n=2000 |
87 | Correct | 20 ms | 24812 KB | n=2000 |
88 | Correct | 19 ms | 24812 KB | n=2000 |
89 | Correct | 19 ms | 24812 KB | n=2000 |
90 | Correct | 19 ms | 24812 KB | n=2000 |
91 | Correct | 19 ms | 24812 KB | n=2000 |
92 | Correct | 934 ms | 120808 KB | n=200000 |
93 | Correct | 1143 ms | 124508 KB | n=200000 |
94 | Correct | 820 ms | 127212 KB | n=200000 |
95 | Correct | 920 ms | 120540 KB | n=200000 |
96 | Correct | 911 ms | 120500 KB | n=200000 |
97 | Correct | 1241 ms | 123628 KB | n=200000 |
98 | Correct | 921 ms | 120608 KB | n=200000 |
99 | Correct | 1078 ms | 120172 KB | n=200000 |
100 | Correct | 914 ms | 120532 KB | n=200000 |
101 | Correct | 720 ms | 128236 KB | n=200000 |
102 | Correct | 573 ms | 121712 KB | n=200000 |
103 | Correct | 572 ms | 121580 KB | n=200000 |
104 | Correct | 571 ms | 121580 KB | n=200000 |
105 | Correct | 570 ms | 121580 KB | n=200000 |
106 | Correct | 559 ms | 121452 KB | n=200000 |
107 | Correct | 570 ms | 121452 KB | n=200000 |
108 | Correct | 965 ms | 120432 KB | n=200000 |
109 | Correct | 982 ms | 120548 KB | n=200000 |
110 | Correct | 976 ms | 120324 KB | n=200000 |
111 | Correct | 924 ms | 120412 KB | n=200000 |
112 | Correct | 780 ms | 127368 KB | n=200000 |
113 | Correct | 1195 ms | 123636 KB | n=200000 |
114 | Correct | 960 ms | 120444 KB | n=200000 |
115 | Correct | 1469 ms | 121708 KB | n=200000 |
116 | Correct | 864 ms | 120156 KB | n=200000 |
117 | Correct | 752 ms | 127596 KB | n=200000 |
118 | Correct | 1321 ms | 122480 KB | n=200000 |
119 | Correct | 851 ms | 120156 KB | n=200000 |
120 | Correct | 671 ms | 127724 KB | n=200000 |
121 | Correct | 670 ms | 127980 KB | n=200000 |
122 | Correct | 702 ms | 128364 KB | n=200000 |
123 | Correct | 592 ms | 121196 KB | n=200000 |
124 | Correct | 219 ms | 44136 KB | n=25264 |