답안 #42777

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42777 2018-03-04T03:12:31 Z nickyrio Birthday gift (IZhO18_treearray) C++14
56 / 100
4000 ms 167272 KB
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i<= b; ++i)
#define FORD(i, a, b) for (int i = a; i>=b; --i)
#define REP(i, a) for (int i = 0; i<a; ++i)
#define DEBUG(x) { cerr << #x << " = " << x << endl; }
#define Arr(A, l, r) { cerr << #A  << " = "; FOR(_, l, r) cerr << A[_] << ' '; cerr << endl; }
#define N 1001000
#define pp pair<int, int>
#define next __next
#define prev __prev
#define __builtin_popcount __builtin_popcountll
#define bit(S, i) (((S) >> i) & 1)
#define IO ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
using namespace std;

int n, m, q, a[N], h[N];
int LCA[N][20], LOG;
vector<int> e[N];
set<int> One[N], Two[N];

void dfs(int u, int p) {
    for (int v : e[u]) if (v != p) {
        h[v] = h[u] + 1;
        LCA[v][0] = u;
        FOR(j, 1, LOG) LCA[v][j] = LCA[LCA[v][j - 1]][j - 1];
        dfs(v, u);
    }
}

int lca(int u, int v) {
    if (h[u] < h[v]) swap(u, v);
    int delta = h[u] - h[v];
    FORD(i, LOG, 0) if (bit(delta, i)) u = LCA[u][i];
    if (u == v) return u;
    FORD(i, LOG, 0) if (LCA[u][i] != LCA[v][i]) {
        u = LCA[u][i]; v = LCA[v][i];
    }
    return LCA[u][0];
}
int main() {
    #ifdef NERO
    freopen("test.inp","r",stdin);
    freopen("test.out","w",stdout);
    #endif //NERO
    IO;
    cin >> n >> m >> q;
    LOG = log2(n);
    FOR(i, 2, n) {
        int u, v;
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(1, -1);
    FOR(i, 1, m) {
        cin >> a[i];
        One[a[i]].insert(i);
        if (i != 1) {
            Two[lca(a[i], a[i - 1])].insert(i);
        }
    }
    while (q--) {
        int type, v, l, r;
        cin >> type;
        if (type == 1) {
            cin >> l >> v;
            One[a[l]].erase(l);
            if (l > 1) Two[lca(a[l - 1], a[l])].erase(l);
            if (l < m) Two[lca(a[l], a[l + 1])].erase(l + 1);
            a[l] = v;
            One[a[l]].insert(l);
            if (l > 1) Two[lca(a[l], a[l - 1])].insert(l);
            if (l < m) Two[lca(a[l], a[l + 1])].insert(l + 1);
        }
        else {
            cin >> l >> r >> v;
          	if (!One[v].empty() && *One[v].begin() <= r && *One[v].rbegin() >= l) {
                auto InOne = *lower_bound(One[v].begin(), One[v].end(), l);
            	if (InOne <= r) {
                    cout << InOne << ' ' << InOne << '\n';
                    continue;
                }
            }
            if (!Two[v].empty() && *Two[v].begin() <= r && *Two[v].rbegin() > l) {
            	auto InTwo = *lower_bound(Two[v].begin(), Two[v].end(), l + 1);
                if (InTwo <= r) {
                    cout << InTwo - 1 << ' ' << InTwo << '\n';
                    continue;
                }
            }
            cout << "-1 -1\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 117880 KB n=5
2 Correct 94 ms 117984 KB n=100
3 Correct 96 ms 118176 KB n=100
4 Correct 102 ms 118176 KB n=100
5 Correct 99 ms 118176 KB n=100
6 Correct 98 ms 118176 KB n=100
7 Correct 96 ms 118176 KB n=100
8 Correct 96 ms 118176 KB n=100
9 Correct 95 ms 118176 KB n=100
10 Correct 93 ms 118216 KB n=100
11 Correct 93 ms 118216 KB n=100
12 Correct 100 ms 118216 KB n=100
13 Correct 94 ms 118216 KB n=100
14 Correct 94 ms 118276 KB n=100
15 Correct 98 ms 118276 KB n=100
16 Correct 99 ms 118276 KB n=100
17 Correct 94 ms 118276 KB n=100
18 Correct 95 ms 118276 KB n=100
19 Correct 93 ms 118276 KB n=100
20 Correct 94 ms 118380 KB n=100
21 Correct 95 ms 118380 KB n=100
22 Correct 113 ms 118380 KB n=100
23 Correct 95 ms 118380 KB n=100
24 Correct 94 ms 118380 KB n=100
25 Correct 93 ms 118380 KB n=100
26 Correct 96 ms 118380 KB n=12
27 Correct 93 ms 118380 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 117880 KB n=5
2 Correct 94 ms 117984 KB n=100
3 Correct 96 ms 118176 KB n=100
4 Correct 102 ms 118176 KB n=100
5 Correct 99 ms 118176 KB n=100
6 Correct 98 ms 118176 KB n=100
7 Correct 96 ms 118176 KB n=100
8 Correct 96 ms 118176 KB n=100
9 Correct 95 ms 118176 KB n=100
10 Correct 93 ms 118216 KB n=100
11 Correct 93 ms 118216 KB n=100
12 Correct 100 ms 118216 KB n=100
13 Correct 94 ms 118216 KB n=100
14 Correct 94 ms 118276 KB n=100
15 Correct 98 ms 118276 KB n=100
16 Correct 99 ms 118276 KB n=100
17 Correct 94 ms 118276 KB n=100
18 Correct 95 ms 118276 KB n=100
19 Correct 93 ms 118276 KB n=100
20 Correct 94 ms 118380 KB n=100
21 Correct 95 ms 118380 KB n=100
22 Correct 113 ms 118380 KB n=100
23 Correct 95 ms 118380 KB n=100
24 Correct 94 ms 118380 KB n=100
25 Correct 93 ms 118380 KB n=100
26 Correct 96 ms 118380 KB n=12
27 Correct 93 ms 118380 KB n=100
28 Correct 96 ms 118408 KB n=500
29 Correct 95 ms 118424 KB n=500
30 Correct 95 ms 118488 KB n=500
31 Correct 94 ms 118488 KB n=500
32 Correct 98 ms 118488 KB n=500
33 Correct 95 ms 118488 KB n=500
34 Correct 95 ms 118488 KB n=500
35 Correct 96 ms 118560 KB n=500
36 Correct 93 ms 118576 KB n=500
37 Correct 94 ms 118576 KB n=500
38 Correct 101 ms 118576 KB n=500
39 Correct 93 ms 118648 KB n=500
40 Correct 93 ms 118648 KB n=500
41 Correct 94 ms 118648 KB n=500
42 Correct 95 ms 118648 KB n=500
43 Correct 96 ms 118648 KB n=500
44 Correct 94 ms 118648 KB n=500
45 Correct 96 ms 118696 KB n=500
46 Correct 93 ms 118696 KB n=500
47 Correct 97 ms 118696 KB n=500
48 Correct 93 ms 118696 KB n=500
49 Correct 92 ms 118752 KB n=500
50 Correct 94 ms 118752 KB n=500
51 Correct 93 ms 118780 KB n=500
52 Correct 94 ms 118780 KB n=500
53 Correct 96 ms 118816 KB n=500
54 Correct 97 ms 118816 KB n=500
55 Correct 93 ms 118840 KB n=278
56 Correct 95 ms 118848 KB n=500
57 Correct 94 ms 118848 KB n=500
58 Correct 94 ms 118848 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 117880 KB n=5
2 Correct 94 ms 117984 KB n=100
3 Correct 96 ms 118176 KB n=100
4 Correct 102 ms 118176 KB n=100
5 Correct 99 ms 118176 KB n=100
6 Correct 98 ms 118176 KB n=100
7 Correct 96 ms 118176 KB n=100
8 Correct 96 ms 118176 KB n=100
9 Correct 95 ms 118176 KB n=100
10 Correct 93 ms 118216 KB n=100
11 Correct 93 ms 118216 KB n=100
12 Correct 100 ms 118216 KB n=100
13 Correct 94 ms 118216 KB n=100
14 Correct 94 ms 118276 KB n=100
15 Correct 98 ms 118276 KB n=100
16 Correct 99 ms 118276 KB n=100
17 Correct 94 ms 118276 KB n=100
18 Correct 95 ms 118276 KB n=100
19 Correct 93 ms 118276 KB n=100
20 Correct 94 ms 118380 KB n=100
21 Correct 95 ms 118380 KB n=100
22 Correct 113 ms 118380 KB n=100
23 Correct 95 ms 118380 KB n=100
24 Correct 94 ms 118380 KB n=100
25 Correct 93 ms 118380 KB n=100
26 Correct 96 ms 118380 KB n=12
27 Correct 93 ms 118380 KB n=100
28 Correct 96 ms 118408 KB n=500
29 Correct 95 ms 118424 KB n=500
30 Correct 95 ms 118488 KB n=500
31 Correct 94 ms 118488 KB n=500
32 Correct 98 ms 118488 KB n=500
33 Correct 95 ms 118488 KB n=500
34 Correct 95 ms 118488 KB n=500
35 Correct 96 ms 118560 KB n=500
36 Correct 93 ms 118576 KB n=500
37 Correct 94 ms 118576 KB n=500
38 Correct 101 ms 118576 KB n=500
39 Correct 93 ms 118648 KB n=500
40 Correct 93 ms 118648 KB n=500
41 Correct 94 ms 118648 KB n=500
42 Correct 95 ms 118648 KB n=500
43 Correct 96 ms 118648 KB n=500
44 Correct 94 ms 118648 KB n=500
45 Correct 96 ms 118696 KB n=500
46 Correct 93 ms 118696 KB n=500
47 Correct 97 ms 118696 KB n=500
48 Correct 93 ms 118696 KB n=500
49 Correct 92 ms 118752 KB n=500
50 Correct 94 ms 118752 KB n=500
51 Correct 93 ms 118780 KB n=500
52 Correct 94 ms 118780 KB n=500
53 Correct 96 ms 118816 KB n=500
54 Correct 97 ms 118816 KB n=500
55 Correct 93 ms 118840 KB n=278
56 Correct 95 ms 118848 KB n=500
57 Correct 94 ms 118848 KB n=500
58 Correct 94 ms 118848 KB n=500
59 Correct 121 ms 119292 KB n=2000
60 Correct 100 ms 119324 KB n=2000
61 Correct 99 ms 119408 KB n=2000
62 Correct 105 ms 119408 KB n=2000
63 Correct 131 ms 119408 KB n=2000
64 Correct 105 ms 119536 KB n=2000
65 Correct 135 ms 119552 KB n=2000
66 Correct 103 ms 119692 KB n=2000
67 Correct 112 ms 119692 KB n=2000
68 Correct 99 ms 119700 KB n=2000
69 Correct 97 ms 119888 KB n=2000
70 Correct 98 ms 119924 KB n=2000
71 Correct 98 ms 119988 KB n=2000
72 Correct 104 ms 119988 KB n=2000
73 Correct 98 ms 119988 KB n=2000
74 Correct 118 ms 120104 KB n=1844
75 Correct 98 ms 120104 KB n=2000
76 Correct 100 ms 120124 KB n=2000
77 Correct 100 ms 120176 KB n=2000
78 Correct 97 ms 120176 KB n=2000
79 Correct 110 ms 120328 KB n=2000
80 Correct 97 ms 120516 KB n=2000
81 Correct 96 ms 120592 KB n=2000
82 Correct 111 ms 120592 KB n=2000
83 Correct 97 ms 120592 KB n=2000
84 Correct 98 ms 120660 KB n=2000
85 Correct 98 ms 120724 KB n=2000
86 Correct 98 ms 120724 KB n=2000
87 Correct 99 ms 120724 KB n=2000
88 Correct 96 ms 120780 KB n=2000
89 Correct 107 ms 121060 KB n=2000
90 Correct 97 ms 121060 KB n=2000
91 Correct 95 ms 121060 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 117880 KB n=5
2 Correct 94 ms 117984 KB n=100
3 Correct 96 ms 118176 KB n=100
4 Correct 102 ms 118176 KB n=100
5 Correct 99 ms 118176 KB n=100
6 Correct 98 ms 118176 KB n=100
7 Correct 96 ms 118176 KB n=100
8 Correct 96 ms 118176 KB n=100
9 Correct 95 ms 118176 KB n=100
10 Correct 93 ms 118216 KB n=100
11 Correct 93 ms 118216 KB n=100
12 Correct 100 ms 118216 KB n=100
13 Correct 94 ms 118216 KB n=100
14 Correct 94 ms 118276 KB n=100
15 Correct 98 ms 118276 KB n=100
16 Correct 99 ms 118276 KB n=100
17 Correct 94 ms 118276 KB n=100
18 Correct 95 ms 118276 KB n=100
19 Correct 93 ms 118276 KB n=100
20 Correct 94 ms 118380 KB n=100
21 Correct 95 ms 118380 KB n=100
22 Correct 113 ms 118380 KB n=100
23 Correct 95 ms 118380 KB n=100
24 Correct 94 ms 118380 KB n=100
25 Correct 93 ms 118380 KB n=100
26 Correct 96 ms 118380 KB n=12
27 Correct 93 ms 118380 KB n=100
28 Correct 96 ms 118408 KB n=500
29 Correct 95 ms 118424 KB n=500
30 Correct 95 ms 118488 KB n=500
31 Correct 94 ms 118488 KB n=500
32 Correct 98 ms 118488 KB n=500
33 Correct 95 ms 118488 KB n=500
34 Correct 95 ms 118488 KB n=500
35 Correct 96 ms 118560 KB n=500
36 Correct 93 ms 118576 KB n=500
37 Correct 94 ms 118576 KB n=500
38 Correct 101 ms 118576 KB n=500
39 Correct 93 ms 118648 KB n=500
40 Correct 93 ms 118648 KB n=500
41 Correct 94 ms 118648 KB n=500
42 Correct 95 ms 118648 KB n=500
43 Correct 96 ms 118648 KB n=500
44 Correct 94 ms 118648 KB n=500
45 Correct 96 ms 118696 KB n=500
46 Correct 93 ms 118696 KB n=500
47 Correct 97 ms 118696 KB n=500
48 Correct 93 ms 118696 KB n=500
49 Correct 92 ms 118752 KB n=500
50 Correct 94 ms 118752 KB n=500
51 Correct 93 ms 118780 KB n=500
52 Correct 94 ms 118780 KB n=500
53 Correct 96 ms 118816 KB n=500
54 Correct 97 ms 118816 KB n=500
55 Correct 93 ms 118840 KB n=278
56 Correct 95 ms 118848 KB n=500
57 Correct 94 ms 118848 KB n=500
58 Correct 94 ms 118848 KB n=500
59 Correct 121 ms 119292 KB n=2000
60 Correct 100 ms 119324 KB n=2000
61 Correct 99 ms 119408 KB n=2000
62 Correct 105 ms 119408 KB n=2000
63 Correct 131 ms 119408 KB n=2000
64 Correct 105 ms 119536 KB n=2000
65 Correct 135 ms 119552 KB n=2000
66 Correct 103 ms 119692 KB n=2000
67 Correct 112 ms 119692 KB n=2000
68 Correct 99 ms 119700 KB n=2000
69 Correct 97 ms 119888 KB n=2000
70 Correct 98 ms 119924 KB n=2000
71 Correct 98 ms 119988 KB n=2000
72 Correct 104 ms 119988 KB n=2000
73 Correct 98 ms 119988 KB n=2000
74 Correct 118 ms 120104 KB n=1844
75 Correct 98 ms 120104 KB n=2000
76 Correct 100 ms 120124 KB n=2000
77 Correct 100 ms 120176 KB n=2000
78 Correct 97 ms 120176 KB n=2000
79 Correct 110 ms 120328 KB n=2000
80 Correct 97 ms 120516 KB n=2000
81 Correct 96 ms 120592 KB n=2000
82 Correct 111 ms 120592 KB n=2000
83 Correct 97 ms 120592 KB n=2000
84 Correct 98 ms 120660 KB n=2000
85 Correct 98 ms 120724 KB n=2000
86 Correct 98 ms 120724 KB n=2000
87 Correct 99 ms 120724 KB n=2000
88 Correct 96 ms 120780 KB n=2000
89 Correct 107 ms 121060 KB n=2000
90 Correct 97 ms 121060 KB n=2000
91 Correct 95 ms 121060 KB n=2000
92 Execution timed out 4094 ms 167272 KB Time limit exceeded
93 Halted 0 ms 0 KB -