답안 #899460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
899460 2024-01-06T08:47:11 Z otarius Birthday gift (IZhO18_treearray) C++17
100 / 100
731 ms 83224 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

void __print(int x) { cerr << x; }

void __print(long x) { cerr << x; }

void __print(long long x) { cerr << x; }

void __print(unsigned x) { cerr << x; }

void __print(unsigned long x) { cerr << x; }

void __print(unsigned long long x) { cerr << x; }

void __print(float x) { cerr << x; }

void __print(double x) { cerr << x; }

void __print(long double x) { cerr << x; }

void __print(char x) { cerr << '\'' << x << '\''; }

void __print(const char *x) { cerr << '\"' << x << '\"'; }

void __print(const string &x) { cerr << '\"' << x << '\"'; }

void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}

template<typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}

void _print() { cerr << "]\n"; }

template<typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long

// #define int long long
// #define int unsigned long long

const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;

vector<int> adj[200005];
set<int> pos[200005], lpos[200005];
int x, y, par[200005][18], in[200005], out[200005], tim;
void dfs(int v, int p) {
    in[v] = ++tim;
    par[v][0] = p;
    for (int i = 1; i < 18; i++)
        par[v][i] = par[par[v][i - 1]][i - 1];
    for (int u : adj[v]) if (u != p) dfs(u, v);
    out[v] = ++tim;
}
bool anc(int a, int b) {
    return (in[a] <= in[b] && out[a] >= out[b]);
}
int lca(int x, int y) {
    if (anc(x, y)) return x;
    if (anc(y, x)) return y;
    for (int i = 17; i >= 0; i--) {
        if (par[x][i] == 0) continue;
        if (!anc(par[x][i], y)) x = par[x][i];
    } return par[x][0];
}
void solve() {
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1; i < n; i++) {
        cin >> x >> y;
        adj[x].pb(y); adj[y].pb(x);
    } int arr[m + 1];
    for (int i = 1; i <= m; i++) {
        cin >> arr[i]; pos[arr[i]].insert(i);
    } dfs(1, 0);
    for (int i = 2; i <= m; i++)
        lpos[lca(arr[i], arr[i - 1])].insert(i);
    int tst, l, r, v;
    for (int i = 1; i <= q; i++) {
        cin >> tst;
        if (tst & 1) {
            cin >> l >> v;
            pos[arr[l]].erase(l);
            if (l > 1) lpos[lca(arr[l], arr[l - 1])].erase(l);
            if (l < m) lpos[lca(arr[l], arr[l + 1])].erase(l + 1);
            arr[l] = v;
            pos[arr[l]].insert(l);
            if (l > 1) lpos[lca(arr[l], arr[l - 1])].insert(l);
            if (l < m) lpos[lca(arr[l], arr[l + 1])].insert(l + 1);
        } else {
            cin >> l >> r >> v;
            auto it = pos[v].lower_bound(l);
            if (it != pos[v].end() && *it <= r) {
                cout << *it << ' ' << *it << '\n'; continue;
            } it = lpos[v].lower_bound(l + 1);
            if (it != lpos[v].end() && *it <= r) {
                cout << *it - 1 << ' ' << *it << '\n'; continue;
            } cout << "-1 -1\n";
        }
    }
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 26972 KB n=5
2 Correct 6 ms 26968 KB n=100
3 Correct 5 ms 26972 KB n=100
4 Correct 5 ms 26968 KB n=100
5 Correct 5 ms 26972 KB n=100
6 Correct 5 ms 26972 KB n=100
7 Correct 5 ms 26968 KB n=100
8 Correct 5 ms 26972 KB n=100
9 Correct 5 ms 26968 KB n=100
10 Correct 5 ms 26972 KB n=100
11 Correct 5 ms 26968 KB n=100
12 Correct 5 ms 26972 KB n=100
13 Correct 5 ms 26972 KB n=100
14 Correct 5 ms 26968 KB n=100
15 Correct 7 ms 27056 KB n=100
16 Correct 6 ms 26972 KB n=100
17 Correct 5 ms 27072 KB n=100
18 Correct 5 ms 26972 KB n=100
19 Correct 5 ms 26972 KB n=100
20 Correct 5 ms 27124 KB n=100
21 Correct 6 ms 26968 KB n=100
22 Correct 5 ms 27060 KB n=100
23 Correct 5 ms 26972 KB n=100
24 Correct 5 ms 26972 KB n=100
25 Correct 6 ms 26972 KB n=100
26 Correct 5 ms 26972 KB n=12
27 Correct 6 ms 26972 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 26972 KB n=5
2 Correct 6 ms 26968 KB n=100
3 Correct 5 ms 26972 KB n=100
4 Correct 5 ms 26968 KB n=100
5 Correct 5 ms 26972 KB n=100
6 Correct 5 ms 26972 KB n=100
7 Correct 5 ms 26968 KB n=100
8 Correct 5 ms 26972 KB n=100
9 Correct 5 ms 26968 KB n=100
10 Correct 5 ms 26972 KB n=100
11 Correct 5 ms 26968 KB n=100
12 Correct 5 ms 26972 KB n=100
13 Correct 5 ms 26972 KB n=100
14 Correct 5 ms 26968 KB n=100
15 Correct 7 ms 27056 KB n=100
16 Correct 6 ms 26972 KB n=100
17 Correct 5 ms 27072 KB n=100
18 Correct 5 ms 26972 KB n=100
19 Correct 5 ms 26972 KB n=100
20 Correct 5 ms 27124 KB n=100
21 Correct 6 ms 26968 KB n=100
22 Correct 5 ms 27060 KB n=100
23 Correct 5 ms 26972 KB n=100
24 Correct 5 ms 26972 KB n=100
25 Correct 6 ms 26972 KB n=100
26 Correct 5 ms 26972 KB n=12
27 Correct 6 ms 26972 KB n=100
28 Correct 7 ms 26968 KB n=500
29 Correct 6 ms 26972 KB n=500
30 Correct 6 ms 26972 KB n=500
31 Correct 6 ms 27224 KB n=500
32 Correct 6 ms 26968 KB n=500
33 Correct 6 ms 26972 KB n=500
34 Correct 6 ms 26972 KB n=500
35 Correct 6 ms 26972 KB n=500
36 Correct 7 ms 26968 KB n=500
37 Correct 7 ms 26968 KB n=500
38 Correct 6 ms 26972 KB n=500
39 Correct 6 ms 27076 KB n=500
40 Correct 6 ms 27080 KB n=500
41 Correct 6 ms 27224 KB n=500
42 Correct 6 ms 26972 KB n=500
43 Correct 6 ms 26972 KB n=500
44 Correct 6 ms 26972 KB n=500
45 Correct 5 ms 26972 KB n=500
46 Correct 5 ms 26968 KB n=500
47 Correct 5 ms 27192 KB n=500
48 Correct 6 ms 26972 KB n=500
49 Correct 5 ms 26972 KB n=500
50 Correct 6 ms 26972 KB n=500
51 Correct 7 ms 26972 KB n=500
52 Correct 6 ms 27224 KB n=500
53 Correct 6 ms 26972 KB n=500
54 Correct 7 ms 26972 KB n=500
55 Correct 5 ms 26972 KB n=278
56 Correct 6 ms 26972 KB n=500
57 Correct 6 ms 26972 KB n=500
58 Correct 7 ms 27484 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 26972 KB n=5
2 Correct 6 ms 26968 KB n=100
3 Correct 5 ms 26972 KB n=100
4 Correct 5 ms 26968 KB n=100
5 Correct 5 ms 26972 KB n=100
6 Correct 5 ms 26972 KB n=100
7 Correct 5 ms 26968 KB n=100
8 Correct 5 ms 26972 KB n=100
9 Correct 5 ms 26968 KB n=100
10 Correct 5 ms 26972 KB n=100
11 Correct 5 ms 26968 KB n=100
12 Correct 5 ms 26972 KB n=100
13 Correct 5 ms 26972 KB n=100
14 Correct 5 ms 26968 KB n=100
15 Correct 7 ms 27056 KB n=100
16 Correct 6 ms 26972 KB n=100
17 Correct 5 ms 27072 KB n=100
18 Correct 5 ms 26972 KB n=100
19 Correct 5 ms 26972 KB n=100
20 Correct 5 ms 27124 KB n=100
21 Correct 6 ms 26968 KB n=100
22 Correct 5 ms 27060 KB n=100
23 Correct 5 ms 26972 KB n=100
24 Correct 5 ms 26972 KB n=100
25 Correct 6 ms 26972 KB n=100
26 Correct 5 ms 26972 KB n=12
27 Correct 6 ms 26972 KB n=100
28 Correct 7 ms 26968 KB n=500
29 Correct 6 ms 26972 KB n=500
30 Correct 6 ms 26972 KB n=500
31 Correct 6 ms 27224 KB n=500
32 Correct 6 ms 26968 KB n=500
33 Correct 6 ms 26972 KB n=500
34 Correct 6 ms 26972 KB n=500
35 Correct 6 ms 26972 KB n=500
36 Correct 7 ms 26968 KB n=500
37 Correct 7 ms 26968 KB n=500
38 Correct 6 ms 26972 KB n=500
39 Correct 6 ms 27076 KB n=500
40 Correct 6 ms 27080 KB n=500
41 Correct 6 ms 27224 KB n=500
42 Correct 6 ms 26972 KB n=500
43 Correct 6 ms 26972 KB n=500
44 Correct 6 ms 26972 KB n=500
45 Correct 5 ms 26972 KB n=500
46 Correct 5 ms 26968 KB n=500
47 Correct 5 ms 27192 KB n=500
48 Correct 6 ms 26972 KB n=500
49 Correct 5 ms 26972 KB n=500
50 Correct 6 ms 26972 KB n=500
51 Correct 7 ms 26972 KB n=500
52 Correct 6 ms 27224 KB n=500
53 Correct 6 ms 26972 KB n=500
54 Correct 7 ms 26972 KB n=500
55 Correct 5 ms 26972 KB n=278
56 Correct 6 ms 26972 KB n=500
57 Correct 6 ms 26972 KB n=500
58 Correct 7 ms 27484 KB n=500
59 Correct 7 ms 27224 KB n=2000
60 Correct 7 ms 27224 KB n=2000
61 Correct 9 ms 27224 KB n=2000
62 Correct 9 ms 27228 KB n=2000
63 Correct 8 ms 27224 KB n=2000
64 Correct 7 ms 27228 KB n=2000
65 Correct 8 ms 27228 KB n=2000
66 Correct 7 ms 27480 KB n=2000
67 Correct 8 ms 27228 KB n=2000
68 Correct 7 ms 27228 KB n=2000
69 Correct 8 ms 27324 KB n=2000
70 Correct 7 ms 27228 KB n=2000
71 Correct 7 ms 27224 KB n=2000
72 Correct 7 ms 27228 KB n=2000
73 Correct 7 ms 27228 KB n=2000
74 Correct 7 ms 27228 KB n=1844
75 Correct 7 ms 27296 KB n=2000
76 Correct 7 ms 27228 KB n=2000
77 Correct 8 ms 27228 KB n=2000
78 Correct 7 ms 27228 KB n=2000
79 Correct 7 ms 27228 KB n=2000
80 Correct 7 ms 27228 KB n=2000
81 Correct 7 ms 27420 KB n=2000
82 Correct 9 ms 27224 KB n=2000
83 Correct 7 ms 27224 KB n=2000
84 Correct 7 ms 27228 KB n=2000
85 Correct 8 ms 27228 KB n=2000
86 Correct 7 ms 27228 KB n=2000
87 Correct 7 ms 27228 KB n=2000
88 Correct 7 ms 27484 KB n=2000
89 Correct 7 ms 27484 KB n=2000
90 Correct 7 ms 27228 KB n=2000
91 Correct 7 ms 27224 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 26972 KB n=5
2 Correct 6 ms 26968 KB n=100
3 Correct 5 ms 26972 KB n=100
4 Correct 5 ms 26968 KB n=100
5 Correct 5 ms 26972 KB n=100
6 Correct 5 ms 26972 KB n=100
7 Correct 5 ms 26968 KB n=100
8 Correct 5 ms 26972 KB n=100
9 Correct 5 ms 26968 KB n=100
10 Correct 5 ms 26972 KB n=100
11 Correct 5 ms 26968 KB n=100
12 Correct 5 ms 26972 KB n=100
13 Correct 5 ms 26972 KB n=100
14 Correct 5 ms 26968 KB n=100
15 Correct 7 ms 27056 KB n=100
16 Correct 6 ms 26972 KB n=100
17 Correct 5 ms 27072 KB n=100
18 Correct 5 ms 26972 KB n=100
19 Correct 5 ms 26972 KB n=100
20 Correct 5 ms 27124 KB n=100
21 Correct 6 ms 26968 KB n=100
22 Correct 5 ms 27060 KB n=100
23 Correct 5 ms 26972 KB n=100
24 Correct 5 ms 26972 KB n=100
25 Correct 6 ms 26972 KB n=100
26 Correct 5 ms 26972 KB n=12
27 Correct 6 ms 26972 KB n=100
28 Correct 7 ms 26968 KB n=500
29 Correct 6 ms 26972 KB n=500
30 Correct 6 ms 26972 KB n=500
31 Correct 6 ms 27224 KB n=500
32 Correct 6 ms 26968 KB n=500
33 Correct 6 ms 26972 KB n=500
34 Correct 6 ms 26972 KB n=500
35 Correct 6 ms 26972 KB n=500
36 Correct 7 ms 26968 KB n=500
37 Correct 7 ms 26968 KB n=500
38 Correct 6 ms 26972 KB n=500
39 Correct 6 ms 27076 KB n=500
40 Correct 6 ms 27080 KB n=500
41 Correct 6 ms 27224 KB n=500
42 Correct 6 ms 26972 KB n=500
43 Correct 6 ms 26972 KB n=500
44 Correct 6 ms 26972 KB n=500
45 Correct 5 ms 26972 KB n=500
46 Correct 5 ms 26968 KB n=500
47 Correct 5 ms 27192 KB n=500
48 Correct 6 ms 26972 KB n=500
49 Correct 5 ms 26972 KB n=500
50 Correct 6 ms 26972 KB n=500
51 Correct 7 ms 26972 KB n=500
52 Correct 6 ms 27224 KB n=500
53 Correct 6 ms 26972 KB n=500
54 Correct 7 ms 26972 KB n=500
55 Correct 5 ms 26972 KB n=278
56 Correct 6 ms 26972 KB n=500
57 Correct 6 ms 26972 KB n=500
58 Correct 7 ms 27484 KB n=500
59 Correct 7 ms 27224 KB n=2000
60 Correct 7 ms 27224 KB n=2000
61 Correct 9 ms 27224 KB n=2000
62 Correct 9 ms 27228 KB n=2000
63 Correct 8 ms 27224 KB n=2000
64 Correct 7 ms 27228 KB n=2000
65 Correct 8 ms 27228 KB n=2000
66 Correct 7 ms 27480 KB n=2000
67 Correct 8 ms 27228 KB n=2000
68 Correct 7 ms 27228 KB n=2000
69 Correct 8 ms 27324 KB n=2000
70 Correct 7 ms 27228 KB n=2000
71 Correct 7 ms 27224 KB n=2000
72 Correct 7 ms 27228 KB n=2000
73 Correct 7 ms 27228 KB n=2000
74 Correct 7 ms 27228 KB n=1844
75 Correct 7 ms 27296 KB n=2000
76 Correct 7 ms 27228 KB n=2000
77 Correct 8 ms 27228 KB n=2000
78 Correct 7 ms 27228 KB n=2000
79 Correct 7 ms 27228 KB n=2000
80 Correct 7 ms 27228 KB n=2000
81 Correct 7 ms 27420 KB n=2000
82 Correct 9 ms 27224 KB n=2000
83 Correct 7 ms 27224 KB n=2000
84 Correct 7 ms 27228 KB n=2000
85 Correct 8 ms 27228 KB n=2000
86 Correct 7 ms 27228 KB n=2000
87 Correct 7 ms 27228 KB n=2000
88 Correct 7 ms 27484 KB n=2000
89 Correct 7 ms 27484 KB n=2000
90 Correct 7 ms 27228 KB n=2000
91 Correct 7 ms 27224 KB n=2000
92 Correct 486 ms 70144 KB n=200000
93 Correct 571 ms 78676 KB n=200000
94 Correct 416 ms 81900 KB n=200000
95 Correct 438 ms 73684 KB n=200000
96 Correct 477 ms 73672 KB n=200000
97 Correct 573 ms 77720 KB n=200000
98 Correct 453 ms 73664 KB n=200000
99 Correct 548 ms 73908 KB n=200000
100 Correct 422 ms 73776 KB n=200000
101 Correct 412 ms 83224 KB n=200000
102 Correct 249 ms 74836 KB n=200000
103 Correct 303 ms 74836 KB n=200000
104 Correct 285 ms 74704 KB n=200000
105 Correct 300 ms 75236 KB n=200000
106 Correct 267 ms 75388 KB n=200000
107 Correct 319 ms 75336 KB n=200000
108 Correct 506 ms 73556 KB n=200000
109 Correct 512 ms 73688 KB n=200000
110 Correct 535 ms 73756 KB n=200000
111 Correct 414 ms 73028 KB n=200000
112 Correct 399 ms 82224 KB n=200000
113 Correct 611 ms 77888 KB n=200000
114 Correct 463 ms 73240 KB n=200000
115 Correct 731 ms 75716 KB n=200000
116 Correct 476 ms 74024 KB n=200000
117 Correct 374 ms 82908 KB n=200000
118 Correct 655 ms 76652 KB n=200000
119 Correct 426 ms 73924 KB n=200000
120 Correct 402 ms 82260 KB n=200000
121 Correct 373 ms 82340 KB n=200000
122 Correct 341 ms 82580 KB n=200000
123 Correct 291 ms 74880 KB n=200000
124 Correct 87 ms 42068 KB n=25264