Submission #80582

# Submission time Handle Problem Language Result Execution time Memory
80582 2018-10-21T13:21:49 Z inom Birthday gift (IZhO18_treearray) C++14
56 / 100
4000 ms 53160 KB
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);

using namespace std;
  
const int N = 2 * 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int TN = 1;

int n, m, Q, l = 1;
vector<int> verr[N], up[N];
int tin[N], tout[N], timer, node[N];

void dfs(int x, int pr = 1) {
    tin[x] = ++timer;
    up[x][0] = pr;
    for (int i = 1; i <= l; i++) {
        up[x][i] = up[up[x][i - 1]][i - 1];
    }
    for (auto i: verr[x]) {
        if (i != pr) {
            dfs(i, x);
        }
    }
    tout[x] = ++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;
    }
    else 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;
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        verr[x].pb(y); verr[y].pb(x);
    }
    while ((1<<l) <= n) {
        l++;
    }
    for (int i = 1; i <= n; i++) {
        up[i].resize(l + 10);
    
    }
    dfs(1);
    for (int i = 1; i <= m; i++) {
        cin >> node[i];
    }
    while (Q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int pos, v;
            cin >> pos >> v;
            node[pos] = v;
        }
        else {
            int l, r, v;
            cin >> l >> r >> v;
            bool ok = false;
            for (int i = l; i <= r; i++) {
                if (node[i] == v) {
                    cout << i << " " << i << "\n"; ok = true; break;
                }
            }
            if (ok) {
                continue;
            }
            ok = false;
            for (int i = l; i < r; i++) {
                if (lca(node[i], node[i + 1]) == v) {
                    cout << i << " " << i + 1 << "\n"; ok = true; break;
                }
            }
            if (!ok) {
                cout << -1 << " " << -1 << "\n";
            }
        }
    }
    return;
}

signed main() {
    // ios_base::sync_with_stdio(0);
    // in; out; 
    // cin >> TN;
    while (TN--) solve();
    return 0;
 }
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB n=5
2 Correct 13 ms 9732 KB n=100
3 Correct 11 ms 9904 KB n=100
4 Correct 11 ms 9956 KB n=100
5 Correct 12 ms 9956 KB n=100
6 Correct 12 ms 9964 KB n=100
7 Correct 11 ms 10000 KB n=100
8 Correct 11 ms 10000 KB n=100
9 Correct 12 ms 10000 KB n=100
10 Correct 11 ms 10000 KB n=100
11 Correct 17 ms 10004 KB n=100
12 Correct 12 ms 10008 KB n=100
13 Correct 11 ms 10012 KB n=100
14 Correct 11 ms 10016 KB n=100
15 Correct 11 ms 10020 KB n=100
16 Correct 11 ms 10024 KB n=100
17 Correct 12 ms 10032 KB n=100
18 Correct 11 ms 10032 KB n=100
19 Correct 11 ms 10036 KB n=100
20 Correct 12 ms 10040 KB n=100
21 Correct 10 ms 10044 KB n=100
22 Correct 11 ms 10048 KB n=100
23 Correct 11 ms 10052 KB n=100
24 Correct 10 ms 10056 KB n=100
25 Correct 11 ms 10060 KB n=100
26 Correct 10 ms 10124 KB n=12
27 Correct 11 ms 10124 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB n=5
2 Correct 13 ms 9732 KB n=100
3 Correct 11 ms 9904 KB n=100
4 Correct 11 ms 9956 KB n=100
5 Correct 12 ms 9956 KB n=100
6 Correct 12 ms 9964 KB n=100
7 Correct 11 ms 10000 KB n=100
8 Correct 11 ms 10000 KB n=100
9 Correct 12 ms 10000 KB n=100
10 Correct 11 ms 10000 KB n=100
11 Correct 17 ms 10004 KB n=100
12 Correct 12 ms 10008 KB n=100
13 Correct 11 ms 10012 KB n=100
14 Correct 11 ms 10016 KB n=100
15 Correct 11 ms 10020 KB n=100
16 Correct 11 ms 10024 KB n=100
17 Correct 12 ms 10032 KB n=100
18 Correct 11 ms 10032 KB n=100
19 Correct 11 ms 10036 KB n=100
20 Correct 12 ms 10040 KB n=100
21 Correct 10 ms 10044 KB n=100
22 Correct 11 ms 10048 KB n=100
23 Correct 11 ms 10052 KB n=100
24 Correct 10 ms 10056 KB n=100
25 Correct 11 ms 10060 KB n=100
26 Correct 10 ms 10124 KB n=12
27 Correct 11 ms 10124 KB n=100
28 Correct 12 ms 10200 KB n=500
29 Correct 13 ms 10216 KB n=500
30 Correct 12 ms 10244 KB n=500
31 Correct 12 ms 10260 KB n=500
32 Correct 14 ms 10292 KB n=500
33 Correct 12 ms 10320 KB n=500
34 Correct 12 ms 10352 KB n=500
35 Correct 16 ms 10364 KB n=500
36 Correct 23 ms 10380 KB n=500
37 Correct 17 ms 10392 KB n=500
38 Correct 15 ms 10404 KB n=500
39 Correct 14 ms 10420 KB n=500
40 Correct 15 ms 10432 KB n=500
41 Correct 16 ms 10448 KB n=500
42 Correct 13 ms 10464 KB n=500
43 Correct 14 ms 10476 KB n=500
44 Correct 13 ms 10492 KB n=500
45 Correct 12 ms 10504 KB n=500
46 Correct 12 ms 10516 KB n=500
47 Correct 12 ms 10532 KB n=500
48 Correct 11 ms 10548 KB n=500
49 Correct 11 ms 10560 KB n=500
50 Correct 12 ms 10676 KB n=500
51 Correct 13 ms 10676 KB n=500
52 Correct 12 ms 10676 KB n=500
53 Correct 14 ms 10676 KB n=500
54 Correct 12 ms 10676 KB n=500
55 Correct 10 ms 10676 KB n=278
56 Correct 12 ms 10676 KB n=500
57 Correct 12 ms 10676 KB n=500
58 Correct 14 ms 10756 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB n=5
2 Correct 13 ms 9732 KB n=100
3 Correct 11 ms 9904 KB n=100
4 Correct 11 ms 9956 KB n=100
5 Correct 12 ms 9956 KB n=100
6 Correct 12 ms 9964 KB n=100
7 Correct 11 ms 10000 KB n=100
8 Correct 11 ms 10000 KB n=100
9 Correct 12 ms 10000 KB n=100
10 Correct 11 ms 10000 KB n=100
11 Correct 17 ms 10004 KB n=100
12 Correct 12 ms 10008 KB n=100
13 Correct 11 ms 10012 KB n=100
14 Correct 11 ms 10016 KB n=100
15 Correct 11 ms 10020 KB n=100
16 Correct 11 ms 10024 KB n=100
17 Correct 12 ms 10032 KB n=100
18 Correct 11 ms 10032 KB n=100
19 Correct 11 ms 10036 KB n=100
20 Correct 12 ms 10040 KB n=100
21 Correct 10 ms 10044 KB n=100
22 Correct 11 ms 10048 KB n=100
23 Correct 11 ms 10052 KB n=100
24 Correct 10 ms 10056 KB n=100
25 Correct 11 ms 10060 KB n=100
26 Correct 10 ms 10124 KB n=12
27 Correct 11 ms 10124 KB n=100
28 Correct 12 ms 10200 KB n=500
29 Correct 13 ms 10216 KB n=500
30 Correct 12 ms 10244 KB n=500
31 Correct 12 ms 10260 KB n=500
32 Correct 14 ms 10292 KB n=500
33 Correct 12 ms 10320 KB n=500
34 Correct 12 ms 10352 KB n=500
35 Correct 16 ms 10364 KB n=500
36 Correct 23 ms 10380 KB n=500
37 Correct 17 ms 10392 KB n=500
38 Correct 15 ms 10404 KB n=500
39 Correct 14 ms 10420 KB n=500
40 Correct 15 ms 10432 KB n=500
41 Correct 16 ms 10448 KB n=500
42 Correct 13 ms 10464 KB n=500
43 Correct 14 ms 10476 KB n=500
44 Correct 13 ms 10492 KB n=500
45 Correct 12 ms 10504 KB n=500
46 Correct 12 ms 10516 KB n=500
47 Correct 12 ms 10532 KB n=500
48 Correct 11 ms 10548 KB n=500
49 Correct 11 ms 10560 KB n=500
50 Correct 12 ms 10676 KB n=500
51 Correct 13 ms 10676 KB n=500
52 Correct 12 ms 10676 KB n=500
53 Correct 14 ms 10676 KB n=500
54 Correct 12 ms 10676 KB n=500
55 Correct 10 ms 10676 KB n=278
56 Correct 12 ms 10676 KB n=500
57 Correct 12 ms 10676 KB n=500
58 Correct 14 ms 10756 KB n=500
59 Correct 16 ms 10952 KB n=2000
60 Correct 17 ms 11060 KB n=2000
61 Correct 21 ms 11060 KB n=2000
62 Correct 21 ms 11116 KB n=2000
63 Correct 17 ms 11144 KB n=2000
64 Correct 23 ms 11184 KB n=2000
65 Correct 17 ms 11196 KB n=2000
66 Correct 18 ms 11332 KB n=2000
67 Correct 18 ms 11388 KB n=2000
68 Correct 22 ms 11440 KB n=2000
69 Correct 130 ms 11628 KB n=2000
70 Correct 127 ms 11628 KB n=2000
71 Correct 128 ms 11732 KB n=2000
72 Correct 80 ms 11732 KB n=2000
73 Correct 88 ms 11844 KB n=2000
74 Correct 21 ms 11844 KB n=1844
75 Correct 73 ms 11888 KB n=2000
76 Correct 71 ms 11888 KB n=2000
77 Correct 87 ms 12048 KB n=2000
78 Correct 87 ms 12048 KB n=2000
79 Correct 16 ms 12048 KB n=2000
80 Correct 20 ms 12072 KB n=2000
81 Correct 22 ms 12160 KB n=2000
82 Correct 15 ms 12184 KB n=2000
83 Correct 21 ms 12232 KB n=2000
84 Correct 34 ms 12292 KB n=2000
85 Correct 36 ms 12344 KB n=2000
86 Correct 39 ms 12400 KB n=2000
87 Correct 36 ms 12456 KB n=2000
88 Correct 31 ms 12508 KB n=2000
89 Correct 32 ms 12564 KB n=2000
90 Correct 24 ms 12624 KB n=2000
91 Correct 101 ms 12676 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9720 KB n=5
2 Correct 13 ms 9732 KB n=100
3 Correct 11 ms 9904 KB n=100
4 Correct 11 ms 9956 KB n=100
5 Correct 12 ms 9956 KB n=100
6 Correct 12 ms 9964 KB n=100
7 Correct 11 ms 10000 KB n=100
8 Correct 11 ms 10000 KB n=100
9 Correct 12 ms 10000 KB n=100
10 Correct 11 ms 10000 KB n=100
11 Correct 17 ms 10004 KB n=100
12 Correct 12 ms 10008 KB n=100
13 Correct 11 ms 10012 KB n=100
14 Correct 11 ms 10016 KB n=100
15 Correct 11 ms 10020 KB n=100
16 Correct 11 ms 10024 KB n=100
17 Correct 12 ms 10032 KB n=100
18 Correct 11 ms 10032 KB n=100
19 Correct 11 ms 10036 KB n=100
20 Correct 12 ms 10040 KB n=100
21 Correct 10 ms 10044 KB n=100
22 Correct 11 ms 10048 KB n=100
23 Correct 11 ms 10052 KB n=100
24 Correct 10 ms 10056 KB n=100
25 Correct 11 ms 10060 KB n=100
26 Correct 10 ms 10124 KB n=12
27 Correct 11 ms 10124 KB n=100
28 Correct 12 ms 10200 KB n=500
29 Correct 13 ms 10216 KB n=500
30 Correct 12 ms 10244 KB n=500
31 Correct 12 ms 10260 KB n=500
32 Correct 14 ms 10292 KB n=500
33 Correct 12 ms 10320 KB n=500
34 Correct 12 ms 10352 KB n=500
35 Correct 16 ms 10364 KB n=500
36 Correct 23 ms 10380 KB n=500
37 Correct 17 ms 10392 KB n=500
38 Correct 15 ms 10404 KB n=500
39 Correct 14 ms 10420 KB n=500
40 Correct 15 ms 10432 KB n=500
41 Correct 16 ms 10448 KB n=500
42 Correct 13 ms 10464 KB n=500
43 Correct 14 ms 10476 KB n=500
44 Correct 13 ms 10492 KB n=500
45 Correct 12 ms 10504 KB n=500
46 Correct 12 ms 10516 KB n=500
47 Correct 12 ms 10532 KB n=500
48 Correct 11 ms 10548 KB n=500
49 Correct 11 ms 10560 KB n=500
50 Correct 12 ms 10676 KB n=500
51 Correct 13 ms 10676 KB n=500
52 Correct 12 ms 10676 KB n=500
53 Correct 14 ms 10676 KB n=500
54 Correct 12 ms 10676 KB n=500
55 Correct 10 ms 10676 KB n=278
56 Correct 12 ms 10676 KB n=500
57 Correct 12 ms 10676 KB n=500
58 Correct 14 ms 10756 KB n=500
59 Correct 16 ms 10952 KB n=2000
60 Correct 17 ms 11060 KB n=2000
61 Correct 21 ms 11060 KB n=2000
62 Correct 21 ms 11116 KB n=2000
63 Correct 17 ms 11144 KB n=2000
64 Correct 23 ms 11184 KB n=2000
65 Correct 17 ms 11196 KB n=2000
66 Correct 18 ms 11332 KB n=2000
67 Correct 18 ms 11388 KB n=2000
68 Correct 22 ms 11440 KB n=2000
69 Correct 130 ms 11628 KB n=2000
70 Correct 127 ms 11628 KB n=2000
71 Correct 128 ms 11732 KB n=2000
72 Correct 80 ms 11732 KB n=2000
73 Correct 88 ms 11844 KB n=2000
74 Correct 21 ms 11844 KB n=1844
75 Correct 73 ms 11888 KB n=2000
76 Correct 71 ms 11888 KB n=2000
77 Correct 87 ms 12048 KB n=2000
78 Correct 87 ms 12048 KB n=2000
79 Correct 16 ms 12048 KB n=2000
80 Correct 20 ms 12072 KB n=2000
81 Correct 22 ms 12160 KB n=2000
82 Correct 15 ms 12184 KB n=2000
83 Correct 21 ms 12232 KB n=2000
84 Correct 34 ms 12292 KB n=2000
85 Correct 36 ms 12344 KB n=2000
86 Correct 39 ms 12400 KB n=2000
87 Correct 36 ms 12456 KB n=2000
88 Correct 31 ms 12508 KB n=2000
89 Correct 32 ms 12564 KB n=2000
90 Correct 24 ms 12624 KB n=2000
91 Correct 101 ms 12676 KB n=2000
92 Execution timed out 4094 ms 53160 KB Time limit exceeded
93 Halted 0 ms 0 KB -