답안 #523415

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523415 2022-02-07T15:38:27 Z vonatlus Birthday gift (IZhO18_treearray) C++17
56 / 100
1331 ms 77232 KB
/// adil sultanov | vonat1us 

#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:36777216")

#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
#define all(z) (z).begin(), (z).end()
 
using namespace std;

using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7; 
const int INF = 1e9 + 1e2;
  
void fin() {
#ifdef AM
    freopen(".in", "r", stdin);
#endif        
}                   

const bool flag = 0;

const int N = 2e5+10;
const int K = 18;

set<int> s[N], one[N];

vector<int> adj[N];

int up[K][N], tin[N], tout[N], tmr;

void dfs(int x = 0, int p = 0) {
    up[0][x] = p;
    for (int i = 1; i < K; ++i) {
        up[i][x] = up[i-1][up[i-1][x]];
    }
    tin[x] = ++tmr;
    for (int to : adj[x]) {
        if (to != p) {
            dfs(to, x);
        }
    }
    tout[x] = tmr;
}

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;
    if (upper(b, a)) return b;
    for (int i = K-1; ~i; --i) {
        if (!upper(up[i][a], b)) {
            a = up[i][a];
        }
    }
    return up[0][a];
}

void ma1n() {
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    vector<int> a(m);
    for (int& x : a) cin >> x, x--;

    dfs();
    for (int i = 0; i < m; ++i) {
        one[a[i]].insert(i);
        if (i+1 < m) s[lca(a[i+1], a[i])].insert(i);
    }
    
    for (int i = 0; i < q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            int pos, v;
            cin >> pos >> v;
            pos--, v--;
            one[a[pos]].erase(pos);

            if (pos+1 < n) s[lca(a[pos], a[pos+1])].erase(pos);
            if (pos > 0) s[lca(a[pos], a[pos-1])].erase(pos-1);
            
            a[pos] = v;
            one[v].insert(pos);

            if (pos+1 < n) s[lca(v, a[pos+1])].insert(pos);
            if (pos > 0) s[lca(v, a[pos-1])].insert(pos-1);
        } else {
            int l, r, v;
            cin >> l >> r >> v;
            l--, r--, v--;
            auto it = one[v].lower_bound(l);
            if (it != one[v].end() && *it <= r) {
                cout << *it+1 << " " << *it+1 << "\n";
                continue;
            }      
            it = s[v].lower_bound(l);
            if (it != s[v].end() && *it < r) {
                cout << *it+1 << " " << *it+2 << "\n";
            } else {
                cout << "-1 -1\n";
            }
        }
    }
} 

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), fin();
    int ts = 1;
    if (flag) {
        cin >> ts;
    }
    while (ts--) {
        ma1n(); 
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23884 KB n=5
2 Correct 15 ms 23800 KB n=100
3 Correct 14 ms 23936 KB n=100
4 Correct 13 ms 23884 KB n=100
5 Correct 13 ms 23884 KB n=100
6 Correct 14 ms 23884 KB n=100
7 Correct 14 ms 23932 KB n=100
8 Correct 13 ms 23928 KB n=100
9 Correct 13 ms 23884 KB n=100
10 Correct 13 ms 23884 KB n=100
11 Correct 14 ms 23884 KB n=100
12 Correct 14 ms 23852 KB n=100
13 Correct 14 ms 23908 KB n=100
14 Correct 15 ms 23840 KB n=100
15 Correct 14 ms 23816 KB n=100
16 Correct 14 ms 23884 KB n=100
17 Correct 15 ms 24056 KB n=100
18 Correct 14 ms 23884 KB n=100
19 Correct 13 ms 23932 KB n=100
20 Correct 14 ms 23824 KB n=100
21 Correct 14 ms 23884 KB n=100
22 Correct 13 ms 23884 KB n=100
23 Correct 12 ms 23884 KB n=100
24 Correct 13 ms 23932 KB n=100
25 Correct 13 ms 23884 KB n=100
26 Correct 13 ms 23884 KB n=12
27 Correct 13 ms 23884 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23884 KB n=5
2 Correct 15 ms 23800 KB n=100
3 Correct 14 ms 23936 KB n=100
4 Correct 13 ms 23884 KB n=100
5 Correct 13 ms 23884 KB n=100
6 Correct 14 ms 23884 KB n=100
7 Correct 14 ms 23932 KB n=100
8 Correct 13 ms 23928 KB n=100
9 Correct 13 ms 23884 KB n=100
10 Correct 13 ms 23884 KB n=100
11 Correct 14 ms 23884 KB n=100
12 Correct 14 ms 23852 KB n=100
13 Correct 14 ms 23908 KB n=100
14 Correct 15 ms 23840 KB n=100
15 Correct 14 ms 23816 KB n=100
16 Correct 14 ms 23884 KB n=100
17 Correct 15 ms 24056 KB n=100
18 Correct 14 ms 23884 KB n=100
19 Correct 13 ms 23932 KB n=100
20 Correct 14 ms 23824 KB n=100
21 Correct 14 ms 23884 KB n=100
22 Correct 13 ms 23884 KB n=100
23 Correct 12 ms 23884 KB n=100
24 Correct 13 ms 23932 KB n=100
25 Correct 13 ms 23884 KB n=100
26 Correct 13 ms 23884 KB n=12
27 Correct 13 ms 23884 KB n=100
28 Correct 15 ms 24012 KB n=500
29 Correct 14 ms 23944 KB n=500
30 Correct 14 ms 24016 KB n=500
31 Correct 14 ms 24016 KB n=500
32 Correct 13 ms 23972 KB n=500
33 Correct 14 ms 24012 KB n=500
34 Correct 14 ms 23940 KB n=500
35 Correct 13 ms 24012 KB n=500
36 Correct 14 ms 24004 KB n=500
37 Correct 14 ms 24012 KB n=500
38 Correct 14 ms 24012 KB n=500
39 Correct 17 ms 24012 KB n=500
40 Correct 14 ms 24012 KB n=500
41 Correct 14 ms 24012 KB n=500
42 Correct 13 ms 24012 KB n=500
43 Correct 13 ms 23972 KB n=500
44 Correct 14 ms 23944 KB n=500
45 Correct 14 ms 23936 KB n=500
46 Correct 14 ms 23976 KB n=500
47 Correct 13 ms 24012 KB n=500
48 Correct 14 ms 24020 KB n=500
49 Correct 14 ms 24012 KB n=500
50 Correct 14 ms 23940 KB n=500
51 Correct 13 ms 24004 KB n=500
52 Correct 13 ms 23928 KB n=500
53 Correct 14 ms 24012 KB n=500
54 Correct 14 ms 24012 KB n=500
55 Correct 14 ms 23884 KB n=278
56 Correct 13 ms 24012 KB n=500
57 Correct 14 ms 24012 KB n=500
58 Correct 14 ms 24012 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23884 KB n=5
2 Correct 15 ms 23800 KB n=100
3 Correct 14 ms 23936 KB n=100
4 Correct 13 ms 23884 KB n=100
5 Correct 13 ms 23884 KB n=100
6 Correct 14 ms 23884 KB n=100
7 Correct 14 ms 23932 KB n=100
8 Correct 13 ms 23928 KB n=100
9 Correct 13 ms 23884 KB n=100
10 Correct 13 ms 23884 KB n=100
11 Correct 14 ms 23884 KB n=100
12 Correct 14 ms 23852 KB n=100
13 Correct 14 ms 23908 KB n=100
14 Correct 15 ms 23840 KB n=100
15 Correct 14 ms 23816 KB n=100
16 Correct 14 ms 23884 KB n=100
17 Correct 15 ms 24056 KB n=100
18 Correct 14 ms 23884 KB n=100
19 Correct 13 ms 23932 KB n=100
20 Correct 14 ms 23824 KB n=100
21 Correct 14 ms 23884 KB n=100
22 Correct 13 ms 23884 KB n=100
23 Correct 12 ms 23884 KB n=100
24 Correct 13 ms 23932 KB n=100
25 Correct 13 ms 23884 KB n=100
26 Correct 13 ms 23884 KB n=12
27 Correct 13 ms 23884 KB n=100
28 Correct 15 ms 24012 KB n=500
29 Correct 14 ms 23944 KB n=500
30 Correct 14 ms 24016 KB n=500
31 Correct 14 ms 24016 KB n=500
32 Correct 13 ms 23972 KB n=500
33 Correct 14 ms 24012 KB n=500
34 Correct 14 ms 23940 KB n=500
35 Correct 13 ms 24012 KB n=500
36 Correct 14 ms 24004 KB n=500
37 Correct 14 ms 24012 KB n=500
38 Correct 14 ms 24012 KB n=500
39 Correct 17 ms 24012 KB n=500
40 Correct 14 ms 24012 KB n=500
41 Correct 14 ms 24012 KB n=500
42 Correct 13 ms 24012 KB n=500
43 Correct 13 ms 23972 KB n=500
44 Correct 14 ms 23944 KB n=500
45 Correct 14 ms 23936 KB n=500
46 Correct 14 ms 23976 KB n=500
47 Correct 13 ms 24012 KB n=500
48 Correct 14 ms 24020 KB n=500
49 Correct 14 ms 24012 KB n=500
50 Correct 14 ms 23940 KB n=500
51 Correct 13 ms 24004 KB n=500
52 Correct 13 ms 23928 KB n=500
53 Correct 14 ms 24012 KB n=500
54 Correct 14 ms 24012 KB n=500
55 Correct 14 ms 23884 KB n=278
56 Correct 13 ms 24012 KB n=500
57 Correct 14 ms 24012 KB n=500
58 Correct 14 ms 24012 KB n=500
59 Correct 17 ms 24372 KB n=2000
60 Correct 16 ms 24456 KB n=2000
61 Correct 16 ms 24332 KB n=2000
62 Correct 18 ms 24332 KB n=2000
63 Correct 18 ms 24396 KB n=2000
64 Correct 17 ms 24328 KB n=2000
65 Correct 17 ms 24364 KB n=2000
66 Correct 16 ms 24332 KB n=2000
67 Correct 16 ms 24268 KB n=2000
68 Correct 17 ms 24424 KB n=2000
69 Correct 16 ms 24396 KB n=2000
70 Correct 16 ms 24356 KB n=2000
71 Correct 17 ms 24328 KB n=2000
72 Correct 15 ms 24328 KB n=2000
73 Correct 16 ms 24280 KB n=2000
74 Correct 20 ms 24232 KB n=1844
75 Correct 15 ms 24312 KB n=2000
76 Correct 17 ms 24328 KB n=2000
77 Correct 17 ms 24268 KB n=2000
78 Correct 17 ms 24328 KB n=2000
79 Correct 18 ms 24284 KB n=2000
80 Correct 16 ms 24396 KB n=2000
81 Correct 16 ms 24396 KB n=2000
82 Correct 20 ms 24444 KB n=2000
83 Correct 15 ms 24332 KB n=2000
84 Correct 16 ms 24324 KB n=2000
85 Correct 16 ms 24396 KB n=2000
86 Correct 17 ms 24332 KB n=2000
87 Correct 18 ms 24396 KB n=2000
88 Correct 15 ms 24388 KB n=2000
89 Correct 15 ms 24524 KB n=2000
90 Correct 16 ms 24368 KB n=2000
91 Correct 15 ms 24328 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23884 KB n=5
2 Correct 15 ms 23800 KB n=100
3 Correct 14 ms 23936 KB n=100
4 Correct 13 ms 23884 KB n=100
5 Correct 13 ms 23884 KB n=100
6 Correct 14 ms 23884 KB n=100
7 Correct 14 ms 23932 KB n=100
8 Correct 13 ms 23928 KB n=100
9 Correct 13 ms 23884 KB n=100
10 Correct 13 ms 23884 KB n=100
11 Correct 14 ms 23884 KB n=100
12 Correct 14 ms 23852 KB n=100
13 Correct 14 ms 23908 KB n=100
14 Correct 15 ms 23840 KB n=100
15 Correct 14 ms 23816 KB n=100
16 Correct 14 ms 23884 KB n=100
17 Correct 15 ms 24056 KB n=100
18 Correct 14 ms 23884 KB n=100
19 Correct 13 ms 23932 KB n=100
20 Correct 14 ms 23824 KB n=100
21 Correct 14 ms 23884 KB n=100
22 Correct 13 ms 23884 KB n=100
23 Correct 12 ms 23884 KB n=100
24 Correct 13 ms 23932 KB n=100
25 Correct 13 ms 23884 KB n=100
26 Correct 13 ms 23884 KB n=12
27 Correct 13 ms 23884 KB n=100
28 Correct 15 ms 24012 KB n=500
29 Correct 14 ms 23944 KB n=500
30 Correct 14 ms 24016 KB n=500
31 Correct 14 ms 24016 KB n=500
32 Correct 13 ms 23972 KB n=500
33 Correct 14 ms 24012 KB n=500
34 Correct 14 ms 23940 KB n=500
35 Correct 13 ms 24012 KB n=500
36 Correct 14 ms 24004 KB n=500
37 Correct 14 ms 24012 KB n=500
38 Correct 14 ms 24012 KB n=500
39 Correct 17 ms 24012 KB n=500
40 Correct 14 ms 24012 KB n=500
41 Correct 14 ms 24012 KB n=500
42 Correct 13 ms 24012 KB n=500
43 Correct 13 ms 23972 KB n=500
44 Correct 14 ms 23944 KB n=500
45 Correct 14 ms 23936 KB n=500
46 Correct 14 ms 23976 KB n=500
47 Correct 13 ms 24012 KB n=500
48 Correct 14 ms 24020 KB n=500
49 Correct 14 ms 24012 KB n=500
50 Correct 14 ms 23940 KB n=500
51 Correct 13 ms 24004 KB n=500
52 Correct 13 ms 23928 KB n=500
53 Correct 14 ms 24012 KB n=500
54 Correct 14 ms 24012 KB n=500
55 Correct 14 ms 23884 KB n=278
56 Correct 13 ms 24012 KB n=500
57 Correct 14 ms 24012 KB n=500
58 Correct 14 ms 24012 KB n=500
59 Correct 17 ms 24372 KB n=2000
60 Correct 16 ms 24456 KB n=2000
61 Correct 16 ms 24332 KB n=2000
62 Correct 18 ms 24332 KB n=2000
63 Correct 18 ms 24396 KB n=2000
64 Correct 17 ms 24328 KB n=2000
65 Correct 17 ms 24364 KB n=2000
66 Correct 16 ms 24332 KB n=2000
67 Correct 16 ms 24268 KB n=2000
68 Correct 17 ms 24424 KB n=2000
69 Correct 16 ms 24396 KB n=2000
70 Correct 16 ms 24356 KB n=2000
71 Correct 17 ms 24328 KB n=2000
72 Correct 15 ms 24328 KB n=2000
73 Correct 16 ms 24280 KB n=2000
74 Correct 20 ms 24232 KB n=1844
75 Correct 15 ms 24312 KB n=2000
76 Correct 17 ms 24328 KB n=2000
77 Correct 17 ms 24268 KB n=2000
78 Correct 17 ms 24328 KB n=2000
79 Correct 18 ms 24284 KB n=2000
80 Correct 16 ms 24396 KB n=2000
81 Correct 16 ms 24396 KB n=2000
82 Correct 20 ms 24444 KB n=2000
83 Correct 15 ms 24332 KB n=2000
84 Correct 16 ms 24324 KB n=2000
85 Correct 16 ms 24396 KB n=2000
86 Correct 17 ms 24332 KB n=2000
87 Correct 18 ms 24396 KB n=2000
88 Correct 15 ms 24388 KB n=2000
89 Correct 15 ms 24524 KB n=2000
90 Correct 16 ms 24368 KB n=2000
91 Correct 15 ms 24328 KB n=2000
92 Correct 1253 ms 68808 KB n=200000
93 Correct 939 ms 72684 KB n=200000
94 Correct 580 ms 75296 KB n=200000
95 Correct 1211 ms 67768 KB n=200000
96 Correct 1222 ms 67964 KB n=200000
97 Correct 1047 ms 71220 KB n=200000
98 Correct 1229 ms 67952 KB n=200000
99 Correct 1228 ms 67372 KB n=200000
100 Correct 1192 ms 67988 KB n=200000
101 Correct 466 ms 77068 KB n=200000
102 Correct 671 ms 68960 KB n=200000
103 Correct 607 ms 69332 KB n=200000
104 Correct 587 ms 69536 KB n=200000
105 Correct 581 ms 69384 KB n=200000
106 Correct 614 ms 69376 KB n=200000
107 Correct 608 ms 69380 KB n=200000
108 Correct 1201 ms 68264 KB n=200000
109 Correct 1158 ms 68296 KB n=200000
110 Correct 1170 ms 68392 KB n=200000
111 Correct 1050 ms 68588 KB n=200000
112 Correct 543 ms 76008 KB n=200000
113 Correct 1040 ms 71716 KB n=200000
114 Correct 1079 ms 68676 KB n=200000
115 Correct 1331 ms 69600 KB n=200000
116 Correct 1177 ms 68424 KB n=200000
117 Correct 490 ms 76400 KB n=200000
118 Correct 1188 ms 70312 KB n=200000
119 Correct 1210 ms 68476 KB n=200000
120 Correct 445 ms 76688 KB n=200000
121 Correct 415 ms 76720 KB n=200000
122 Correct 421 ms 77232 KB n=200000
123 Correct 675 ms 69048 KB n=200000
124 Incorrect 152 ms 38436 KB Wrong range.
125 Halted 0 ms 0 KB -