답안 #579996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
579996 2022-06-20T12:42:13 Z loggerr Birthday gift (IZhO18_treearray) C++17
100 / 100
1169 ms 85596 KB
#include "bits/stdc++.h"

using namespace std;
using ll = int;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpl = vector<pll>;
using ld = long double;
using str = string;
using big_int = __int128_t;

const ld eps = 1e-7;
const ld PI = acos(-1);

#define all(c) (c).begin(), (c).end()
#define rall(c) ((c).rbegin()), ((c).rend())
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define fast ios_base::sync_with_stdio(0); cin.tie(0)
#define forn(i, n) for (ll i = 0; i < n; ++i)
#define sz(a) (ll)a.size()
#define endl '\n'
#define u_map unordered_map
#define mset multiset
//#define x first
//#define y second

#ifdef ONLINE_JUDGE
#define debug(x);
#else
#define debug(x) cerr << #x << ": " << x << endl;
#endif

str IO[2] = {"NO\n", "YES\n"};
str io[2] = {"no\n", "yes\n"};
str Io[2] = {"No\n", "Yes\n"};
//
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnd(1232423);

template<class T> bool inmin(T& x_, T y_) {return y_ < x_ ? (x_ = y_, true) : false;}
template<class T> bool inmax(T& x_, T y_) {return y_ > x_ ? (x_ = y_, true) : false;}

//const ll Mod = 1e9 + 7;
const ll Mod = 998244353;
//const ll Mod = 1e9 + 9;
//const ll Mod = 1234567891;
//const ll INF = 1e18;

template<class T> void add(T& x_, T y_) { x_ = (x_ + y_) % Mod; };
template<class T> void sub(T& x_, T y_) { x_ = (x_ + Mod - y_) % Mod; };
template<class T> void mul(T& x_, T y_) { x_ = (x_ * y_) % Mod; };

const ll Maxn = 2e5 + 10;
const ll Lg = 22;

vll gr[Maxn];
ll up[Lg][Maxn];
ll d[Maxn];

void dfs(ll v, ll p) {
    up[0][v] = p;
    d[v] = d[p] + 1;
    for (ll adj : gr[v]) {
        if (adj == p) continue;
        dfs(adj, v);
    }
}

ll la(ll v, ll k) {
    forn (i, Lg) {
        if (k & (1 << i))
            v = up[i][v];
    }
    return v;
}

ll lca(ll u, ll v) {
    if (d[u] < d[v]) swap(u, v);
    u = la(u, d[u] - d[v]);
    if (u == v)
        return u;
    for (ll i = Lg - 1; i >= 0; --i) {
        if (up[i][u] == up[i][v]) continue;
        u = up[i][u], v = up[i][v];
    }
    return up[0][u];
}

set<ll> dcV[Maxn], dcL[Maxn];

inline void solve() {
    ll n, m, q;
    cin >> n >> m >> q;
    forn (i, n - 1) {
        ll u, v;
        cin >> u >> v;
        --u, --v;
        gr[u].pb(v), gr[v].pb(u);
    }
    dfs(0, 0);
    for (ll i = 1; i < Lg; ++i) {
        forn (v, Maxn) {
            up[i][v] = up[i - 1][up[i - 1][v]];
        }
    }
    vll que(m);
    forn (i, m) {
        cin >> que[i];
        --que[i];
        dcV[que[i]].insert(i);
        if (i) {
            dcL[lca(que[i - 1], que[i])].insert(i - 1);
        }
    }
    while (q--) {
        ll tp;
        cin >> tp;
        if (tp == 1) {
            ll pos, v;
            cin >> pos >> v;
            --pos, --v;
            dcV[que[pos]].erase(pos);
            if (pos) dcL[lca(que[pos], que[pos - 1])].erase(pos - 1);
            if (pos < m - 1) dcL[lca(que[pos], que[pos + 1])].erase(pos);
            que[pos] = v;
            dcV[que[pos]].insert(pos);
            if (pos) dcL[lca(que[pos], que[pos - 1])].insert(pos - 1);
            if (pos < m - 1) dcL[lca(que[pos], que[pos + 1])].insert(pos);
            continue;
        }
        ll l, r, v;
        cin >> l >> r >> v;
        --l, --r, --v;
        auto id = dcV[v].lower_bound(l);
        if (id != dcV[v].end() && *id <= r) {
            cout << *id + 1 << ' ' << *id + 1 << endl;
            continue;
        }
        --r;
        id = dcL[v].lower_bound(l);
        if (id != dcL[v].end() && *id <= r) {
            cout << *id + 1 << ' ' << *id + 2 << endl;
            continue;
        }
        cout << -1 << ' ' << -1 << endl;
    }
    return;
}

int main() {
    fast;
    //cout << fixed << satprecision(10);
    ll test;
    test = 1;
    //cin >> test;
    for (ll id = 0; id < test; ++id) solve();
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 40148 KB n=5
2 Correct 26 ms 40228 KB n=100
3 Correct 21 ms 40244 KB n=100
4 Correct 20 ms 40276 KB n=100
5 Correct 22 ms 40252 KB n=100
6 Correct 21 ms 40212 KB n=100
7 Correct 21 ms 40276 KB n=100
8 Correct 21 ms 40224 KB n=100
9 Correct 21 ms 40276 KB n=100
10 Correct 28 ms 40140 KB n=100
11 Correct 23 ms 40196 KB n=100
12 Correct 22 ms 40232 KB n=100
13 Correct 21 ms 40240 KB n=100
14 Correct 22 ms 40276 KB n=100
15 Correct 22 ms 40276 KB n=100
16 Correct 20 ms 40148 KB n=100
17 Correct 22 ms 40252 KB n=100
18 Correct 21 ms 40148 KB n=100
19 Correct 26 ms 40272 KB n=100
20 Correct 23 ms 40208 KB n=100
21 Correct 22 ms 40276 KB n=100
22 Correct 21 ms 40276 KB n=100
23 Correct 22 ms 40212 KB n=100
24 Correct 22 ms 40172 KB n=100
25 Correct 21 ms 40148 KB n=100
26 Correct 22 ms 40204 KB n=12
27 Correct 23 ms 40260 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 40148 KB n=5
2 Correct 26 ms 40228 KB n=100
3 Correct 21 ms 40244 KB n=100
4 Correct 20 ms 40276 KB n=100
5 Correct 22 ms 40252 KB n=100
6 Correct 21 ms 40212 KB n=100
7 Correct 21 ms 40276 KB n=100
8 Correct 21 ms 40224 KB n=100
9 Correct 21 ms 40276 KB n=100
10 Correct 28 ms 40140 KB n=100
11 Correct 23 ms 40196 KB n=100
12 Correct 22 ms 40232 KB n=100
13 Correct 21 ms 40240 KB n=100
14 Correct 22 ms 40276 KB n=100
15 Correct 22 ms 40276 KB n=100
16 Correct 20 ms 40148 KB n=100
17 Correct 22 ms 40252 KB n=100
18 Correct 21 ms 40148 KB n=100
19 Correct 26 ms 40272 KB n=100
20 Correct 23 ms 40208 KB n=100
21 Correct 22 ms 40276 KB n=100
22 Correct 21 ms 40276 KB n=100
23 Correct 22 ms 40212 KB n=100
24 Correct 22 ms 40172 KB n=100
25 Correct 21 ms 40148 KB n=100
26 Correct 22 ms 40204 KB n=12
27 Correct 23 ms 40260 KB n=100
28 Correct 22 ms 40272 KB n=500
29 Correct 24 ms 40276 KB n=500
30 Correct 27 ms 40276 KB n=500
31 Correct 22 ms 40216 KB n=500
32 Correct 23 ms 40272 KB n=500
33 Correct 25 ms 40276 KB n=500
34 Correct 22 ms 40276 KB n=500
35 Correct 22 ms 40312 KB n=500
36 Correct 25 ms 40312 KB n=500
37 Correct 23 ms 40276 KB n=500
38 Correct 24 ms 40224 KB n=500
39 Correct 23 ms 40216 KB n=500
40 Correct 23 ms 40208 KB n=500
41 Correct 23 ms 40268 KB n=500
42 Correct 21 ms 40276 KB n=500
43 Correct 25 ms 40284 KB n=500
44 Correct 22 ms 40312 KB n=500
45 Correct 23 ms 40268 KB n=500
46 Correct 26 ms 40240 KB n=500
47 Correct 27 ms 40280 KB n=500
48 Correct 22 ms 40248 KB n=500
49 Correct 22 ms 40276 KB n=500
50 Correct 22 ms 40276 KB n=500
51 Correct 27 ms 40264 KB n=500
52 Correct 22 ms 40276 KB n=500
53 Correct 29 ms 40280 KB n=500
54 Correct 28 ms 40292 KB n=500
55 Correct 26 ms 40216 KB n=278
56 Correct 24 ms 40260 KB n=500
57 Correct 23 ms 40252 KB n=500
58 Correct 22 ms 40260 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 40148 KB n=5
2 Correct 26 ms 40228 KB n=100
3 Correct 21 ms 40244 KB n=100
4 Correct 20 ms 40276 KB n=100
5 Correct 22 ms 40252 KB n=100
6 Correct 21 ms 40212 KB n=100
7 Correct 21 ms 40276 KB n=100
8 Correct 21 ms 40224 KB n=100
9 Correct 21 ms 40276 KB n=100
10 Correct 28 ms 40140 KB n=100
11 Correct 23 ms 40196 KB n=100
12 Correct 22 ms 40232 KB n=100
13 Correct 21 ms 40240 KB n=100
14 Correct 22 ms 40276 KB n=100
15 Correct 22 ms 40276 KB n=100
16 Correct 20 ms 40148 KB n=100
17 Correct 22 ms 40252 KB n=100
18 Correct 21 ms 40148 KB n=100
19 Correct 26 ms 40272 KB n=100
20 Correct 23 ms 40208 KB n=100
21 Correct 22 ms 40276 KB n=100
22 Correct 21 ms 40276 KB n=100
23 Correct 22 ms 40212 KB n=100
24 Correct 22 ms 40172 KB n=100
25 Correct 21 ms 40148 KB n=100
26 Correct 22 ms 40204 KB n=12
27 Correct 23 ms 40260 KB n=100
28 Correct 22 ms 40272 KB n=500
29 Correct 24 ms 40276 KB n=500
30 Correct 27 ms 40276 KB n=500
31 Correct 22 ms 40216 KB n=500
32 Correct 23 ms 40272 KB n=500
33 Correct 25 ms 40276 KB n=500
34 Correct 22 ms 40276 KB n=500
35 Correct 22 ms 40312 KB n=500
36 Correct 25 ms 40312 KB n=500
37 Correct 23 ms 40276 KB n=500
38 Correct 24 ms 40224 KB n=500
39 Correct 23 ms 40216 KB n=500
40 Correct 23 ms 40208 KB n=500
41 Correct 23 ms 40268 KB n=500
42 Correct 21 ms 40276 KB n=500
43 Correct 25 ms 40284 KB n=500
44 Correct 22 ms 40312 KB n=500
45 Correct 23 ms 40268 KB n=500
46 Correct 26 ms 40240 KB n=500
47 Correct 27 ms 40280 KB n=500
48 Correct 22 ms 40248 KB n=500
49 Correct 22 ms 40276 KB n=500
50 Correct 22 ms 40276 KB n=500
51 Correct 27 ms 40264 KB n=500
52 Correct 22 ms 40276 KB n=500
53 Correct 29 ms 40280 KB n=500
54 Correct 28 ms 40292 KB n=500
55 Correct 26 ms 40216 KB n=278
56 Correct 24 ms 40260 KB n=500
57 Correct 23 ms 40252 KB n=500
58 Correct 22 ms 40260 KB n=500
59 Correct 24 ms 40464 KB n=2000
60 Correct 26 ms 40532 KB n=2000
61 Correct 26 ms 40520 KB n=2000
62 Correct 31 ms 40476 KB n=2000
63 Correct 26 ms 40560 KB n=2000
64 Correct 26 ms 40576 KB n=2000
65 Correct 24 ms 40532 KB n=2000
66 Correct 25 ms 40532 KB n=2000
67 Correct 24 ms 40476 KB n=2000
68 Correct 24 ms 40520 KB n=2000
69 Correct 24 ms 40548 KB n=2000
70 Correct 25 ms 40532 KB n=2000
71 Correct 26 ms 40452 KB n=2000
72 Correct 30 ms 40504 KB n=2000
73 Correct 23 ms 40544 KB n=2000
74 Correct 26 ms 40452 KB n=1844
75 Correct 25 ms 40456 KB n=2000
76 Correct 25 ms 40460 KB n=2000
77 Correct 33 ms 40536 KB n=2000
78 Correct 27 ms 40432 KB n=2000
79 Correct 24 ms 40504 KB n=2000
80 Correct 24 ms 40536 KB n=2000
81 Correct 27 ms 40536 KB n=2000
82 Correct 24 ms 40532 KB n=2000
83 Correct 24 ms 40532 KB n=2000
84 Correct 25 ms 40496 KB n=2000
85 Correct 27 ms 40516 KB n=2000
86 Correct 32 ms 40512 KB n=2000
87 Correct 24 ms 40532 KB n=2000
88 Correct 24 ms 40576 KB n=2000
89 Correct 24 ms 40532 KB n=2000
90 Correct 27 ms 40632 KB n=2000
91 Correct 26 ms 40532 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 40148 KB n=5
2 Correct 26 ms 40228 KB n=100
3 Correct 21 ms 40244 KB n=100
4 Correct 20 ms 40276 KB n=100
5 Correct 22 ms 40252 KB n=100
6 Correct 21 ms 40212 KB n=100
7 Correct 21 ms 40276 KB n=100
8 Correct 21 ms 40224 KB n=100
9 Correct 21 ms 40276 KB n=100
10 Correct 28 ms 40140 KB n=100
11 Correct 23 ms 40196 KB n=100
12 Correct 22 ms 40232 KB n=100
13 Correct 21 ms 40240 KB n=100
14 Correct 22 ms 40276 KB n=100
15 Correct 22 ms 40276 KB n=100
16 Correct 20 ms 40148 KB n=100
17 Correct 22 ms 40252 KB n=100
18 Correct 21 ms 40148 KB n=100
19 Correct 26 ms 40272 KB n=100
20 Correct 23 ms 40208 KB n=100
21 Correct 22 ms 40276 KB n=100
22 Correct 21 ms 40276 KB n=100
23 Correct 22 ms 40212 KB n=100
24 Correct 22 ms 40172 KB n=100
25 Correct 21 ms 40148 KB n=100
26 Correct 22 ms 40204 KB n=12
27 Correct 23 ms 40260 KB n=100
28 Correct 22 ms 40272 KB n=500
29 Correct 24 ms 40276 KB n=500
30 Correct 27 ms 40276 KB n=500
31 Correct 22 ms 40216 KB n=500
32 Correct 23 ms 40272 KB n=500
33 Correct 25 ms 40276 KB n=500
34 Correct 22 ms 40276 KB n=500
35 Correct 22 ms 40312 KB n=500
36 Correct 25 ms 40312 KB n=500
37 Correct 23 ms 40276 KB n=500
38 Correct 24 ms 40224 KB n=500
39 Correct 23 ms 40216 KB n=500
40 Correct 23 ms 40208 KB n=500
41 Correct 23 ms 40268 KB n=500
42 Correct 21 ms 40276 KB n=500
43 Correct 25 ms 40284 KB n=500
44 Correct 22 ms 40312 KB n=500
45 Correct 23 ms 40268 KB n=500
46 Correct 26 ms 40240 KB n=500
47 Correct 27 ms 40280 KB n=500
48 Correct 22 ms 40248 KB n=500
49 Correct 22 ms 40276 KB n=500
50 Correct 22 ms 40276 KB n=500
51 Correct 27 ms 40264 KB n=500
52 Correct 22 ms 40276 KB n=500
53 Correct 29 ms 40280 KB n=500
54 Correct 28 ms 40292 KB n=500
55 Correct 26 ms 40216 KB n=278
56 Correct 24 ms 40260 KB n=500
57 Correct 23 ms 40252 KB n=500
58 Correct 22 ms 40260 KB n=500
59 Correct 24 ms 40464 KB n=2000
60 Correct 26 ms 40532 KB n=2000
61 Correct 26 ms 40520 KB n=2000
62 Correct 31 ms 40476 KB n=2000
63 Correct 26 ms 40560 KB n=2000
64 Correct 26 ms 40576 KB n=2000
65 Correct 24 ms 40532 KB n=2000
66 Correct 25 ms 40532 KB n=2000
67 Correct 24 ms 40476 KB n=2000
68 Correct 24 ms 40520 KB n=2000
69 Correct 24 ms 40548 KB n=2000
70 Correct 25 ms 40532 KB n=2000
71 Correct 26 ms 40452 KB n=2000
72 Correct 30 ms 40504 KB n=2000
73 Correct 23 ms 40544 KB n=2000
74 Correct 26 ms 40452 KB n=1844
75 Correct 25 ms 40456 KB n=2000
76 Correct 25 ms 40460 KB n=2000
77 Correct 33 ms 40536 KB n=2000
78 Correct 27 ms 40432 KB n=2000
79 Correct 24 ms 40504 KB n=2000
80 Correct 24 ms 40536 KB n=2000
81 Correct 27 ms 40536 KB n=2000
82 Correct 24 ms 40532 KB n=2000
83 Correct 24 ms 40532 KB n=2000
84 Correct 25 ms 40496 KB n=2000
85 Correct 27 ms 40516 KB n=2000
86 Correct 32 ms 40512 KB n=2000
87 Correct 24 ms 40532 KB n=2000
88 Correct 24 ms 40576 KB n=2000
89 Correct 24 ms 40532 KB n=2000
90 Correct 27 ms 40632 KB n=2000
91 Correct 26 ms 40532 KB n=2000
92 Correct 833 ms 69728 KB n=200000
93 Correct 1030 ms 80956 KB n=200000
94 Correct 926 ms 84428 KB n=200000
95 Correct 820 ms 75800 KB n=200000
96 Correct 784 ms 75900 KB n=200000
97 Correct 1047 ms 80124 KB n=200000
98 Correct 748 ms 76080 KB n=200000
99 Correct 1016 ms 76252 KB n=200000
100 Correct 805 ms 76140 KB n=200000
101 Correct 900 ms 85596 KB n=200000
102 Correct 449 ms 77232 KB n=200000
103 Correct 435 ms 77096 KB n=200000
104 Correct 426 ms 77108 KB n=200000
105 Correct 439 ms 77520 KB n=200000
106 Correct 476 ms 77488 KB n=200000
107 Correct 501 ms 77524 KB n=200000
108 Correct 953 ms 76108 KB n=200000
109 Correct 1010 ms 76076 KB n=200000
110 Correct 921 ms 76068 KB n=200000
111 Correct 759 ms 75456 KB n=200000
112 Correct 937 ms 84612 KB n=200000
113 Correct 998 ms 80096 KB n=200000
114 Correct 851 ms 75436 KB n=200000
115 Correct 1169 ms 77996 KB n=200000
116 Correct 741 ms 76056 KB n=200000
117 Correct 951 ms 84912 KB n=200000
118 Correct 1081 ms 78880 KB n=200000
119 Correct 763 ms 76088 KB n=200000
120 Correct 970 ms 84676 KB n=200000
121 Correct 937 ms 84780 KB n=200000
122 Correct 972 ms 84820 KB n=200000
123 Correct 477 ms 77364 KB n=200000
124 Correct 222 ms 53256 KB n=25264