Submission #41615

# Submission time Handle Problem Language Result Execution time Memory
41615 2018-02-20T02:28:18 Z cheater2k Birthday gift (IZhO18_treearray) C++14
56 / 100
1698 ms 73244 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 200005;

int n, m, q;
int a[N];
vector<int> G[N];
int dep[N], par[N][17];
set<int> v1[N], v2[N];

void dfs(int u) {
    for (int v : G[u]) if (v != par[u][0]) {
        par[v][0] = u;
        dep[v] = dep[u] + 1;
        dfs(v);
    }
}

int lca(int u, int v) {
    if (dep[u] < dep[v]) swap(u, v);
    for (int i = 16; i >= 0; --i) if (dep[par[u][i]] >= dep[v]) u = par[u][i];
    for (int i = 16; i >= 0; --i) if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
    return u == v ? u : par[u][0];
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m >> q;
    for (int i = 1; i < n; ++i) {
        int u, v; cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    par[1][0] = 1;
    dfs(1);
    for (int j = 1; j <= 16; ++j) {
        for (int i = 1; i <= n; ++i) par[i][j] = par[par[i][j - 1]][j - 1];
    }
    for (int i = 1; i <= m; ++i) {
        cin >> a[i];
        v1[a[i]].insert(i);
    }
    for (int i = 1; i < m; ++i) {
        v2[lca(a[i], a[i + 1])].insert(i);
    }

    while(q--) {
        int type; cin >> type;
        if (type == 1) {
            int pos, u; cin >> pos >> u;

            v1[a[pos]].erase(pos);
            if (pos > 1) v2[lca(a[pos], a[pos - 1])].erase(pos - 1);
            if (pos < m) v2[lca(a[pos], a[pos + 1])].erase(pos);

            a[pos] = u;

            v1[a[pos]].insert(pos);
            if (pos > 1) v2[lca(a[pos], a[pos - 1])].insert(pos - 1);
            if (pos < m) v2[lca(a[pos], a[pos + 1])].insert(pos);
        } else {
            int l, r, u; cin >> l >> r >> u;
            set<int>::iterator it1 = v1[u].lower_bound(l);
            set<int>::iterator it2 = v2[u].lower_bound(l);

            int x = -1, y = -1;
            if (it1 != v1[u].end() && (*it1) <= r) x = (*it1), y = (*it1);
            if (it2 != v2[u].end() && (*it2) < r) x = (*it2), y = (*it2) + 1;

            printf("%d %d\n", x, y);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23800 KB n=5
2 Correct 19 ms 23904 KB n=100
3 Correct 20 ms 23908 KB n=100
4 Correct 21 ms 24048 KB n=100
5 Correct 20 ms 24048 KB n=100
6 Correct 19 ms 24048 KB n=100
7 Correct 19 ms 24048 KB n=100
8 Correct 20 ms 24048 KB n=100
9 Correct 20 ms 24048 KB n=100
10 Correct 20 ms 24048 KB n=100
11 Correct 20 ms 24084 KB n=100
12 Correct 20 ms 24120 KB n=100
13 Correct 20 ms 24120 KB n=100
14 Correct 22 ms 24120 KB n=100
15 Correct 20 ms 24120 KB n=100
16 Correct 20 ms 24120 KB n=100
17 Correct 20 ms 24120 KB n=100
18 Correct 21 ms 24120 KB n=100
19 Correct 20 ms 24120 KB n=100
20 Correct 20 ms 24120 KB n=100
21 Correct 21 ms 24120 KB n=100
22 Correct 20 ms 24120 KB n=100
23 Correct 20 ms 24120 KB n=100
24 Correct 20 ms 24132 KB n=100
25 Correct 20 ms 24156 KB n=100
26 Correct 23 ms 24156 KB n=12
27 Correct 20 ms 24156 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23800 KB n=5
2 Correct 19 ms 23904 KB n=100
3 Correct 20 ms 23908 KB n=100
4 Correct 21 ms 24048 KB n=100
5 Correct 20 ms 24048 KB n=100
6 Correct 19 ms 24048 KB n=100
7 Correct 19 ms 24048 KB n=100
8 Correct 20 ms 24048 KB n=100
9 Correct 20 ms 24048 KB n=100
10 Correct 20 ms 24048 KB n=100
11 Correct 20 ms 24084 KB n=100
12 Correct 20 ms 24120 KB n=100
13 Correct 20 ms 24120 KB n=100
14 Correct 22 ms 24120 KB n=100
15 Correct 20 ms 24120 KB n=100
16 Correct 20 ms 24120 KB n=100
17 Correct 20 ms 24120 KB n=100
18 Correct 21 ms 24120 KB n=100
19 Correct 20 ms 24120 KB n=100
20 Correct 20 ms 24120 KB n=100
21 Correct 21 ms 24120 KB n=100
22 Correct 20 ms 24120 KB n=100
23 Correct 20 ms 24120 KB n=100
24 Correct 20 ms 24132 KB n=100
25 Correct 20 ms 24156 KB n=100
26 Correct 23 ms 24156 KB n=12
27 Correct 20 ms 24156 KB n=100
28 Correct 21 ms 24156 KB n=500
29 Correct 21 ms 24160 KB n=500
30 Correct 20 ms 24160 KB n=500
31 Correct 20 ms 24160 KB n=500
32 Correct 21 ms 24160 KB n=500
33 Correct 20 ms 24160 KB n=500
34 Correct 20 ms 24160 KB n=500
35 Correct 21 ms 24160 KB n=500
36 Correct 24 ms 24160 KB n=500
37 Correct 24 ms 24160 KB n=500
38 Correct 23 ms 24160 KB n=500
39 Correct 23 ms 24160 KB n=500
40 Correct 21 ms 24284 KB n=500
41 Correct 21 ms 24284 KB n=500
42 Correct 21 ms 24284 KB n=500
43 Correct 21 ms 24284 KB n=500
44 Correct 21 ms 24284 KB n=500
45 Correct 21 ms 24284 KB n=500
46 Correct 23 ms 24284 KB n=500
47 Correct 21 ms 24284 KB n=500
48 Correct 21 ms 24284 KB n=500
49 Correct 21 ms 24284 KB n=500
50 Correct 23 ms 24284 KB n=500
51 Correct 20 ms 24284 KB n=500
52 Correct 21 ms 24284 KB n=500
53 Correct 20 ms 24284 KB n=500
54 Correct 20 ms 24284 KB n=500
55 Correct 21 ms 24284 KB n=278
56 Correct 20 ms 24284 KB n=500
57 Correct 22 ms 24284 KB n=500
58 Correct 22 ms 24284 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23800 KB n=5
2 Correct 19 ms 23904 KB n=100
3 Correct 20 ms 23908 KB n=100
4 Correct 21 ms 24048 KB n=100
5 Correct 20 ms 24048 KB n=100
6 Correct 19 ms 24048 KB n=100
7 Correct 19 ms 24048 KB n=100
8 Correct 20 ms 24048 KB n=100
9 Correct 20 ms 24048 KB n=100
10 Correct 20 ms 24048 KB n=100
11 Correct 20 ms 24084 KB n=100
12 Correct 20 ms 24120 KB n=100
13 Correct 20 ms 24120 KB n=100
14 Correct 22 ms 24120 KB n=100
15 Correct 20 ms 24120 KB n=100
16 Correct 20 ms 24120 KB n=100
17 Correct 20 ms 24120 KB n=100
18 Correct 21 ms 24120 KB n=100
19 Correct 20 ms 24120 KB n=100
20 Correct 20 ms 24120 KB n=100
21 Correct 21 ms 24120 KB n=100
22 Correct 20 ms 24120 KB n=100
23 Correct 20 ms 24120 KB n=100
24 Correct 20 ms 24132 KB n=100
25 Correct 20 ms 24156 KB n=100
26 Correct 23 ms 24156 KB n=12
27 Correct 20 ms 24156 KB n=100
28 Correct 21 ms 24156 KB n=500
29 Correct 21 ms 24160 KB n=500
30 Correct 20 ms 24160 KB n=500
31 Correct 20 ms 24160 KB n=500
32 Correct 21 ms 24160 KB n=500
33 Correct 20 ms 24160 KB n=500
34 Correct 20 ms 24160 KB n=500
35 Correct 21 ms 24160 KB n=500
36 Correct 24 ms 24160 KB n=500
37 Correct 24 ms 24160 KB n=500
38 Correct 23 ms 24160 KB n=500
39 Correct 23 ms 24160 KB n=500
40 Correct 21 ms 24284 KB n=500
41 Correct 21 ms 24284 KB n=500
42 Correct 21 ms 24284 KB n=500
43 Correct 21 ms 24284 KB n=500
44 Correct 21 ms 24284 KB n=500
45 Correct 21 ms 24284 KB n=500
46 Correct 23 ms 24284 KB n=500
47 Correct 21 ms 24284 KB n=500
48 Correct 21 ms 24284 KB n=500
49 Correct 21 ms 24284 KB n=500
50 Correct 23 ms 24284 KB n=500
51 Correct 20 ms 24284 KB n=500
52 Correct 21 ms 24284 KB n=500
53 Correct 20 ms 24284 KB n=500
54 Correct 20 ms 24284 KB n=500
55 Correct 21 ms 24284 KB n=278
56 Correct 20 ms 24284 KB n=500
57 Correct 22 ms 24284 KB n=500
58 Correct 22 ms 24284 KB n=500
59 Correct 24 ms 24412 KB n=2000
60 Correct 24 ms 24540 KB n=2000
61 Correct 25 ms 24556 KB n=2000
62 Correct 30 ms 24572 KB n=2000
63 Correct 32 ms 24572 KB n=2000
64 Correct 31 ms 24576 KB n=2000
65 Correct 25 ms 24576 KB n=2000
66 Correct 25 ms 24576 KB n=2000
67 Correct 25 ms 24576 KB n=2000
68 Correct 24 ms 24588 KB n=2000
69 Correct 23 ms 24588 KB n=2000
70 Correct 23 ms 24588 KB n=2000
71 Correct 22 ms 24588 KB n=2000
72 Correct 23 ms 24588 KB n=2000
73 Correct 23 ms 24588 KB n=2000
74 Correct 24 ms 24588 KB n=1844
75 Correct 27 ms 24588 KB n=2000
76 Correct 29 ms 24588 KB n=2000
77 Correct 26 ms 24588 KB n=2000
78 Correct 28 ms 24588 KB n=2000
79 Correct 27 ms 24588 KB n=2000
80 Correct 24 ms 24604 KB n=2000
81 Correct 25 ms 24604 KB n=2000
82 Correct 24 ms 24604 KB n=2000
83 Correct 24 ms 24604 KB n=2000
84 Correct 28 ms 24604 KB n=2000
85 Correct 25 ms 24604 KB n=2000
86 Correct 26 ms 24604 KB n=2000
87 Correct 29 ms 24604 KB n=2000
88 Correct 29 ms 24604 KB n=2000
89 Correct 24 ms 24604 KB n=2000
90 Correct 26 ms 24608 KB n=2000
91 Correct 24 ms 24608 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23800 KB n=5
2 Correct 19 ms 23904 KB n=100
3 Correct 20 ms 23908 KB n=100
4 Correct 21 ms 24048 KB n=100
5 Correct 20 ms 24048 KB n=100
6 Correct 19 ms 24048 KB n=100
7 Correct 19 ms 24048 KB n=100
8 Correct 20 ms 24048 KB n=100
9 Correct 20 ms 24048 KB n=100
10 Correct 20 ms 24048 KB n=100
11 Correct 20 ms 24084 KB n=100
12 Correct 20 ms 24120 KB n=100
13 Correct 20 ms 24120 KB n=100
14 Correct 22 ms 24120 KB n=100
15 Correct 20 ms 24120 KB n=100
16 Correct 20 ms 24120 KB n=100
17 Correct 20 ms 24120 KB n=100
18 Correct 21 ms 24120 KB n=100
19 Correct 20 ms 24120 KB n=100
20 Correct 20 ms 24120 KB n=100
21 Correct 21 ms 24120 KB n=100
22 Correct 20 ms 24120 KB n=100
23 Correct 20 ms 24120 KB n=100
24 Correct 20 ms 24132 KB n=100
25 Correct 20 ms 24156 KB n=100
26 Correct 23 ms 24156 KB n=12
27 Correct 20 ms 24156 KB n=100
28 Correct 21 ms 24156 KB n=500
29 Correct 21 ms 24160 KB n=500
30 Correct 20 ms 24160 KB n=500
31 Correct 20 ms 24160 KB n=500
32 Correct 21 ms 24160 KB n=500
33 Correct 20 ms 24160 KB n=500
34 Correct 20 ms 24160 KB n=500
35 Correct 21 ms 24160 KB n=500
36 Correct 24 ms 24160 KB n=500
37 Correct 24 ms 24160 KB n=500
38 Correct 23 ms 24160 KB n=500
39 Correct 23 ms 24160 KB n=500
40 Correct 21 ms 24284 KB n=500
41 Correct 21 ms 24284 KB n=500
42 Correct 21 ms 24284 KB n=500
43 Correct 21 ms 24284 KB n=500
44 Correct 21 ms 24284 KB n=500
45 Correct 21 ms 24284 KB n=500
46 Correct 23 ms 24284 KB n=500
47 Correct 21 ms 24284 KB n=500
48 Correct 21 ms 24284 KB n=500
49 Correct 21 ms 24284 KB n=500
50 Correct 23 ms 24284 KB n=500
51 Correct 20 ms 24284 KB n=500
52 Correct 21 ms 24284 KB n=500
53 Correct 20 ms 24284 KB n=500
54 Correct 20 ms 24284 KB n=500
55 Correct 21 ms 24284 KB n=278
56 Correct 20 ms 24284 KB n=500
57 Correct 22 ms 24284 KB n=500
58 Correct 22 ms 24284 KB n=500
59 Correct 24 ms 24412 KB n=2000
60 Correct 24 ms 24540 KB n=2000
61 Correct 25 ms 24556 KB n=2000
62 Correct 30 ms 24572 KB n=2000
63 Correct 32 ms 24572 KB n=2000
64 Correct 31 ms 24576 KB n=2000
65 Correct 25 ms 24576 KB n=2000
66 Correct 25 ms 24576 KB n=2000
67 Correct 25 ms 24576 KB n=2000
68 Correct 24 ms 24588 KB n=2000
69 Correct 23 ms 24588 KB n=2000
70 Correct 23 ms 24588 KB n=2000
71 Correct 22 ms 24588 KB n=2000
72 Correct 23 ms 24588 KB n=2000
73 Correct 23 ms 24588 KB n=2000
74 Correct 24 ms 24588 KB n=1844
75 Correct 27 ms 24588 KB n=2000
76 Correct 29 ms 24588 KB n=2000
77 Correct 26 ms 24588 KB n=2000
78 Correct 28 ms 24588 KB n=2000
79 Correct 27 ms 24588 KB n=2000
80 Correct 24 ms 24604 KB n=2000
81 Correct 25 ms 24604 KB n=2000
82 Correct 24 ms 24604 KB n=2000
83 Correct 24 ms 24604 KB n=2000
84 Correct 28 ms 24604 KB n=2000
85 Correct 25 ms 24604 KB n=2000
86 Correct 26 ms 24604 KB n=2000
87 Correct 29 ms 24604 KB n=2000
88 Correct 29 ms 24604 KB n=2000
89 Correct 24 ms 24604 KB n=2000
90 Correct 26 ms 24608 KB n=2000
91 Correct 24 ms 24608 KB n=2000
92 Correct 1087 ms 65996 KB n=200000
93 Correct 1650 ms 69856 KB n=200000
94 Incorrect 1698 ms 73244 KB Wrong range.
95 Halted 0 ms 0 KB -