답안 #74508

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74508 2018-09-02T16:23:00 Z win11905 Birthday gift (IZhO18_treearray) C++11
100 / 100
1665 ms 137348 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5+5;

int n, m, q, A[N];
int par[N][18], dep[N];
vector<int> g[N];
set<int> pos[N], lca_pos[N];

void init_lca(int u, int p) {
    for(int i = 1; i < 18; ++i) par[u][i] = par[par[u][i-1]][i-1];
    for(int v : g[u]) if(v != p) par[v][0] = u, dep[v] = dep[u] + 1, init_lca(v, u);
}

int get_lca(int u, int v) {
    if(dep[u] < dep[v]) swap(u, v);
    for(int i = 17; ~i; --i) if(dep[par[u][i]] >= dep[v]) u = par[u][i];
    if(u == v) return u;
    for(int i = 17; ~i; --i) if(par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
    return par[u][0];
}

int main() {
    scanf("%d %d %d", &n, &m, &q);
    for(int i = 1, u, v; i < n; ++i) {
        scanf("%d %d", &u, &v);
        g[u].emplace_back(v), g[v].emplace_back(u);
    }
    for(int i = 1; i <= n; ++i) pos[i].emplace(m+1), lca_pos[i].emplace(m+1);
    init_lca(1, 0);
    for(int i = 1; i <= m; ++i) scanf("%d", A+i), pos[A[i]].emplace(i);
    for(int i = 1; i < m; ++i) lca_pos[get_lca(A[i], A[i+1])].emplace(i);
    for(int i = 0, tp, l, r, v; i < q; ++i) {
        scanf("%d", &tp);
        if(tp == 1) {
            scanf("%d %d", &tp, &v);
            pos[A[tp]].erase(tp);
            if(tp != 1) lca_pos[get_lca(A[tp], A[tp-1])].erase(tp-1);
            if(tp != m) lca_pos[get_lca(A[tp], A[tp+1])].erase(tp); 
            A[tp] = v;
            pos[A[tp]].emplace(tp);
            if(tp != 1) lca_pos[get_lca(A[tp], A[tp-1])].emplace(tp-1);
            if(tp != m) lca_pos[get_lca(A[tp], A[tp+1])].emplace(tp);
        } else {
            scanf("%d %d %d", &l, &r, &v);
            int a1 = *pos[v].lower_bound(l), a2 = *lca_pos[v].lower_bound(l);
            if(a1 <= r) printf("%d %d\n", a1, a1);
            else if(a2 < r) printf("%d %d\n", a2, a2+1);
            else puts("-1 -1");
        }
    } 
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &m, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
treearray.cpp:32:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= m; ++i) scanf("%d", A+i), pos[A[i]].emplace(i);
                                 ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &tp);
         ~~~~~^~~~~~~~~~~
treearray.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &tp, &v);
             ~~~~~^~~~~~~~~~~~~~~~~~
treearray.cpp:46:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d %d", &l, &r, &v);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB n=5
2 Correct 21 ms 23988 KB n=100
3 Correct 22 ms 24064 KB n=100
4 Correct 23 ms 24120 KB n=100
5 Correct 22 ms 24120 KB n=100
6 Correct 21 ms 24120 KB n=100
7 Correct 23 ms 24120 KB n=100
8 Correct 22 ms 24120 KB n=100
9 Correct 22 ms 24120 KB n=100
10 Correct 22 ms 24120 KB n=100
11 Correct 25 ms 24120 KB n=100
12 Correct 22 ms 24120 KB n=100
13 Correct 21 ms 24120 KB n=100
14 Correct 23 ms 24120 KB n=100
15 Correct 21 ms 24120 KB n=100
16 Correct 22 ms 24172 KB n=100
17 Correct 21 ms 24208 KB n=100
18 Correct 23 ms 24208 KB n=100
19 Correct 23 ms 24208 KB n=100
20 Correct 24 ms 24208 KB n=100
21 Correct 23 ms 24208 KB n=100
22 Correct 23 ms 24208 KB n=100
23 Correct 22 ms 24208 KB n=100
24 Correct 22 ms 24208 KB n=100
25 Correct 24 ms 24208 KB n=100
26 Correct 23 ms 24208 KB n=12
27 Correct 22 ms 24208 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB n=5
2 Correct 21 ms 23988 KB n=100
3 Correct 22 ms 24064 KB n=100
4 Correct 23 ms 24120 KB n=100
5 Correct 22 ms 24120 KB n=100
6 Correct 21 ms 24120 KB n=100
7 Correct 23 ms 24120 KB n=100
8 Correct 22 ms 24120 KB n=100
9 Correct 22 ms 24120 KB n=100
10 Correct 22 ms 24120 KB n=100
11 Correct 25 ms 24120 KB n=100
12 Correct 22 ms 24120 KB n=100
13 Correct 21 ms 24120 KB n=100
14 Correct 23 ms 24120 KB n=100
15 Correct 21 ms 24120 KB n=100
16 Correct 22 ms 24172 KB n=100
17 Correct 21 ms 24208 KB n=100
18 Correct 23 ms 24208 KB n=100
19 Correct 23 ms 24208 KB n=100
20 Correct 24 ms 24208 KB n=100
21 Correct 23 ms 24208 KB n=100
22 Correct 23 ms 24208 KB n=100
23 Correct 22 ms 24208 KB n=100
24 Correct 22 ms 24208 KB n=100
25 Correct 24 ms 24208 KB n=100
26 Correct 23 ms 24208 KB n=12
27 Correct 22 ms 24208 KB n=100
28 Correct 30 ms 24208 KB n=500
29 Correct 23 ms 24208 KB n=500
30 Correct 23 ms 24208 KB n=500
31 Correct 23 ms 24208 KB n=500
32 Correct 24 ms 24208 KB n=500
33 Correct 23 ms 24208 KB n=500
34 Correct 24 ms 24208 KB n=500
35 Correct 23 ms 24208 KB n=500
36 Correct 23 ms 24208 KB n=500
37 Correct 25 ms 24208 KB n=500
38 Correct 27 ms 24208 KB n=500
39 Correct 23 ms 24208 KB n=500
40 Correct 22 ms 24208 KB n=500
41 Correct 22 ms 24212 KB n=500
42 Correct 22 ms 24212 KB n=500
43 Correct 25 ms 24212 KB n=500
44 Correct 23 ms 24212 KB n=500
45 Correct 24 ms 24212 KB n=500
46 Correct 28 ms 24212 KB n=500
47 Correct 23 ms 24212 KB n=500
48 Correct 23 ms 24212 KB n=500
49 Correct 22 ms 24212 KB n=500
50 Correct 25 ms 24212 KB n=500
51 Correct 22 ms 24212 KB n=500
52 Correct 22 ms 24212 KB n=500
53 Correct 24 ms 24212 KB n=500
54 Correct 23 ms 24212 KB n=500
55 Correct 22 ms 24212 KB n=278
56 Correct 26 ms 24212 KB n=500
57 Correct 23 ms 24212 KB n=500
58 Correct 22 ms 24212 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB n=5
2 Correct 21 ms 23988 KB n=100
3 Correct 22 ms 24064 KB n=100
4 Correct 23 ms 24120 KB n=100
5 Correct 22 ms 24120 KB n=100
6 Correct 21 ms 24120 KB n=100
7 Correct 23 ms 24120 KB n=100
8 Correct 22 ms 24120 KB n=100
9 Correct 22 ms 24120 KB n=100
10 Correct 22 ms 24120 KB n=100
11 Correct 25 ms 24120 KB n=100
12 Correct 22 ms 24120 KB n=100
13 Correct 21 ms 24120 KB n=100
14 Correct 23 ms 24120 KB n=100
15 Correct 21 ms 24120 KB n=100
16 Correct 22 ms 24172 KB n=100
17 Correct 21 ms 24208 KB n=100
18 Correct 23 ms 24208 KB n=100
19 Correct 23 ms 24208 KB n=100
20 Correct 24 ms 24208 KB n=100
21 Correct 23 ms 24208 KB n=100
22 Correct 23 ms 24208 KB n=100
23 Correct 22 ms 24208 KB n=100
24 Correct 22 ms 24208 KB n=100
25 Correct 24 ms 24208 KB n=100
26 Correct 23 ms 24208 KB n=12
27 Correct 22 ms 24208 KB n=100
28 Correct 30 ms 24208 KB n=500
29 Correct 23 ms 24208 KB n=500
30 Correct 23 ms 24208 KB n=500
31 Correct 23 ms 24208 KB n=500
32 Correct 24 ms 24208 KB n=500
33 Correct 23 ms 24208 KB n=500
34 Correct 24 ms 24208 KB n=500
35 Correct 23 ms 24208 KB n=500
36 Correct 23 ms 24208 KB n=500
37 Correct 25 ms 24208 KB n=500
38 Correct 27 ms 24208 KB n=500
39 Correct 23 ms 24208 KB n=500
40 Correct 22 ms 24208 KB n=500
41 Correct 22 ms 24212 KB n=500
42 Correct 22 ms 24212 KB n=500
43 Correct 25 ms 24212 KB n=500
44 Correct 23 ms 24212 KB n=500
45 Correct 24 ms 24212 KB n=500
46 Correct 28 ms 24212 KB n=500
47 Correct 23 ms 24212 KB n=500
48 Correct 23 ms 24212 KB n=500
49 Correct 22 ms 24212 KB n=500
50 Correct 25 ms 24212 KB n=500
51 Correct 22 ms 24212 KB n=500
52 Correct 22 ms 24212 KB n=500
53 Correct 24 ms 24212 KB n=500
54 Correct 23 ms 24212 KB n=500
55 Correct 22 ms 24212 KB n=278
56 Correct 26 ms 24212 KB n=500
57 Correct 23 ms 24212 KB n=500
58 Correct 22 ms 24212 KB n=500
59 Correct 26 ms 24684 KB n=2000
60 Correct 28 ms 24812 KB n=2000
61 Correct 29 ms 24812 KB n=2000
62 Correct 28 ms 24812 KB n=2000
63 Correct 27 ms 24812 KB n=2000
64 Correct 26 ms 24812 KB n=2000
65 Correct 28 ms 24812 KB n=2000
66 Correct 27 ms 24812 KB n=2000
67 Correct 28 ms 24812 KB n=2000
68 Correct 34 ms 24812 KB n=2000
69 Correct 25 ms 24812 KB n=2000
70 Correct 25 ms 24812 KB n=2000
71 Correct 26 ms 24876 KB n=2000
72 Correct 25 ms 24876 KB n=2000
73 Correct 26 ms 24876 KB n=2000
74 Correct 27 ms 24876 KB n=1844
75 Correct 25 ms 24876 KB n=2000
76 Correct 29 ms 24876 KB n=2000
77 Correct 29 ms 24876 KB n=2000
78 Correct 27 ms 24876 KB n=2000
79 Correct 27 ms 24876 KB n=2000
80 Correct 27 ms 24876 KB n=2000
81 Correct 27 ms 24876 KB n=2000
82 Correct 27 ms 24876 KB n=2000
83 Correct 32 ms 24876 KB n=2000
84 Correct 27 ms 24876 KB n=2000
85 Correct 29 ms 24876 KB n=2000
86 Correct 28 ms 24876 KB n=2000
87 Correct 27 ms 24876 KB n=2000
88 Correct 27 ms 24876 KB n=2000
89 Correct 29 ms 24892 KB n=2000
90 Correct 28 ms 24892 KB n=2000
91 Correct 25 ms 24892 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB n=5
2 Correct 21 ms 23988 KB n=100
3 Correct 22 ms 24064 KB n=100
4 Correct 23 ms 24120 KB n=100
5 Correct 22 ms 24120 KB n=100
6 Correct 21 ms 24120 KB n=100
7 Correct 23 ms 24120 KB n=100
8 Correct 22 ms 24120 KB n=100
9 Correct 22 ms 24120 KB n=100
10 Correct 22 ms 24120 KB n=100
11 Correct 25 ms 24120 KB n=100
12 Correct 22 ms 24120 KB n=100
13 Correct 21 ms 24120 KB n=100
14 Correct 23 ms 24120 KB n=100
15 Correct 21 ms 24120 KB n=100
16 Correct 22 ms 24172 KB n=100
17 Correct 21 ms 24208 KB n=100
18 Correct 23 ms 24208 KB n=100
19 Correct 23 ms 24208 KB n=100
20 Correct 24 ms 24208 KB n=100
21 Correct 23 ms 24208 KB n=100
22 Correct 23 ms 24208 KB n=100
23 Correct 22 ms 24208 KB n=100
24 Correct 22 ms 24208 KB n=100
25 Correct 24 ms 24208 KB n=100
26 Correct 23 ms 24208 KB n=12
27 Correct 22 ms 24208 KB n=100
28 Correct 30 ms 24208 KB n=500
29 Correct 23 ms 24208 KB n=500
30 Correct 23 ms 24208 KB n=500
31 Correct 23 ms 24208 KB n=500
32 Correct 24 ms 24208 KB n=500
33 Correct 23 ms 24208 KB n=500
34 Correct 24 ms 24208 KB n=500
35 Correct 23 ms 24208 KB n=500
36 Correct 23 ms 24208 KB n=500
37 Correct 25 ms 24208 KB n=500
38 Correct 27 ms 24208 KB n=500
39 Correct 23 ms 24208 KB n=500
40 Correct 22 ms 24208 KB n=500
41 Correct 22 ms 24212 KB n=500
42 Correct 22 ms 24212 KB n=500
43 Correct 25 ms 24212 KB n=500
44 Correct 23 ms 24212 KB n=500
45 Correct 24 ms 24212 KB n=500
46 Correct 28 ms 24212 KB n=500
47 Correct 23 ms 24212 KB n=500
48 Correct 23 ms 24212 KB n=500
49 Correct 22 ms 24212 KB n=500
50 Correct 25 ms 24212 KB n=500
51 Correct 22 ms 24212 KB n=500
52 Correct 22 ms 24212 KB n=500
53 Correct 24 ms 24212 KB n=500
54 Correct 23 ms 24212 KB n=500
55 Correct 22 ms 24212 KB n=278
56 Correct 26 ms 24212 KB n=500
57 Correct 23 ms 24212 KB n=500
58 Correct 22 ms 24212 KB n=500
59 Correct 26 ms 24684 KB n=2000
60 Correct 28 ms 24812 KB n=2000
61 Correct 29 ms 24812 KB n=2000
62 Correct 28 ms 24812 KB n=2000
63 Correct 27 ms 24812 KB n=2000
64 Correct 26 ms 24812 KB n=2000
65 Correct 28 ms 24812 KB n=2000
66 Correct 27 ms 24812 KB n=2000
67 Correct 28 ms 24812 KB n=2000
68 Correct 34 ms 24812 KB n=2000
69 Correct 25 ms 24812 KB n=2000
70 Correct 25 ms 24812 KB n=2000
71 Correct 26 ms 24876 KB n=2000
72 Correct 25 ms 24876 KB n=2000
73 Correct 26 ms 24876 KB n=2000
74 Correct 27 ms 24876 KB n=1844
75 Correct 25 ms 24876 KB n=2000
76 Correct 29 ms 24876 KB n=2000
77 Correct 29 ms 24876 KB n=2000
78 Correct 27 ms 24876 KB n=2000
79 Correct 27 ms 24876 KB n=2000
80 Correct 27 ms 24876 KB n=2000
81 Correct 27 ms 24876 KB n=2000
82 Correct 27 ms 24876 KB n=2000
83 Correct 32 ms 24876 KB n=2000
84 Correct 27 ms 24876 KB n=2000
85 Correct 29 ms 24876 KB n=2000
86 Correct 28 ms 24876 KB n=2000
87 Correct 27 ms 24876 KB n=2000
88 Correct 27 ms 24876 KB n=2000
89 Correct 29 ms 24892 KB n=2000
90 Correct 28 ms 24892 KB n=2000
91 Correct 25 ms 24892 KB n=2000
92 Correct 1065 ms 85656 KB n=200000
93 Correct 1566 ms 89492 KB n=200000
94 Correct 1568 ms 92764 KB n=200000
95 Correct 1056 ms 92764 KB n=200000
96 Correct 1073 ms 92764 KB n=200000
97 Correct 1625 ms 92764 KB n=200000
98 Correct 1104 ms 92764 KB n=200000
99 Correct 1358 ms 92764 KB n=200000
100 Correct 1140 ms 92764 KB n=200000
101 Correct 1580 ms 94124 KB n=200000
102 Correct 658 ms 94124 KB n=200000
103 Correct 630 ms 94124 KB n=200000
104 Correct 651 ms 94124 KB n=200000
105 Correct 675 ms 94124 KB n=200000
106 Correct 737 ms 94124 KB n=200000
107 Correct 647 ms 94124 KB n=200000
108 Correct 1139 ms 94124 KB n=200000
109 Correct 1150 ms 94124 KB n=200000
110 Correct 1263 ms 94124 KB n=200000
111 Correct 1101 ms 94124 KB n=200000
112 Correct 1553 ms 94124 KB n=200000
113 Correct 1627 ms 94124 KB n=200000
114 Correct 1128 ms 94124 KB n=200000
115 Correct 1534 ms 94124 KB n=200000
116 Correct 1114 ms 94124 KB n=200000
117 Correct 1665 ms 101192 KB n=200000
118 Correct 1547 ms 102832 KB n=200000
119 Correct 1031 ms 107516 KB n=200000
120 Correct 1449 ms 122956 KB n=200000
121 Correct 1472 ms 130108 KB n=200000
122 Correct 1427 ms 137348 KB n=200000
123 Correct 642 ms 137348 KB n=200000
124 Correct 336 ms 137348 KB n=25264