답안 #1098613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098613 2024-10-09T16:09:54 Z flyingkite Birthday gift (IZhO18_treearray) C++17
100 / 100
1301 ms 104456 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second  
#define all(x) (x).begin(), (x).end()
 
const ll N = 2e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 350;
ll n,m,q;
vector<ll>adj[N];
ll up[N][20], d[N], a[N];
set<ll>s[N], g[N];
void dfs(ll u, ll par){
    for(auto v : adj[u]){
        if(v == par) continue;
        up[v][0] = u;
        for(int i = 1; i <= 19;i++) up[v][i] = up[up[v][i-1]][i-1];
        d[v] = d[u] + 1;
        dfs(v, u);
    }
}
ll lca(ll u, ll v){
    if(d[u] != d[v]){
        if(d[u] < d[v]) swap(u, v);
        ll k = d[u] - d[v];
        for(int i = 19; i >= 0;i--) if(k & (1 << i)) u = up[u][i];
    }
    if(u == v) return u;
    for(int i = 19; i >= 0;i--) if(up[u][i] != up[v][i]) u = up[u][i], v = up[v][i];
    return up[u][0];
}
void to_thic_cau(){
    cin >> n >> m >> q;
    for(int i = 1; i <= n - 1;i++){
        ll u,v; cin >> u >> v;
        adj[u].pb(v); adj[v].pb(u);
    }
    dfs(1, 0);
    for(int i = 1; i <= m;i++){
        cin >> a[i];
        s[a[i]].insert(i);
        if(i >= 2) g[lca(a[i], a[i-1])].insert(i);
    }
    while(q--){
        ll t; cin >> t;
        if(t == 1){
            ll pos, v; cin >> pos >> v;
            s[a[pos]].erase(pos);
            if(pos > 1) g[lca(a[pos], a[pos-1])].erase(pos);
            if(pos < m) g[lca(a[pos], a[pos+1])].erase(pos + 1);
            a[pos] = v;
            s[a[pos]].insert(pos);
            if(pos > 1) g[lca(a[pos], a[pos-1])].insert(pos);
            if(pos < m) g[lca(a[pos], a[pos+1])].insert(pos + 1);
        }
        else{
            ll l,r,v; cin >> l >> r >> v;
            auto it = s[v].lower_bound(l);
            if(it != s[v].end() && *it <= r){
                cout << (*it) << ' ' << (*it) << '\n';
                continue;
            }
            it = g[v].upper_bound(l);
            if(it != g[v].end() && *it <= r){
                cout << (*it) - 1 << ' ' << (*it) << '\n';
                continue;
            }
            cout << -1 << ' ' << -1 << '\n';
        }
    }
}
 
signed main()   
{  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll tc = 1;
    //cin >> tc;
    while(tc--) to_thic_cau();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB n=5
2 Correct 11 ms 23896 KB n=100
3 Correct 11 ms 23900 KB n=100
4 Correct 11 ms 23900 KB n=100
5 Correct 10 ms 23900 KB n=100
6 Correct 11 ms 23900 KB n=100
7 Correct 11 ms 23896 KB n=100
8 Correct 11 ms 23900 KB n=100
9 Correct 11 ms 23896 KB n=100
10 Correct 11 ms 23896 KB n=100
11 Correct 11 ms 23900 KB n=100
12 Correct 11 ms 23892 KB n=100
13 Correct 11 ms 23896 KB n=100
14 Correct 12 ms 23900 KB n=100
15 Correct 11 ms 23900 KB n=100
16 Correct 12 ms 23896 KB n=100
17 Correct 12 ms 24004 KB n=100
18 Correct 11 ms 23900 KB n=100
19 Correct 11 ms 23900 KB n=100
20 Correct 14 ms 23896 KB n=100
21 Correct 9 ms 23896 KB n=100
22 Correct 9 ms 23896 KB n=100
23 Correct 9 ms 23900 KB n=100
24 Correct 13 ms 23964 KB n=100
25 Correct 12 ms 23896 KB n=100
26 Correct 11 ms 23900 KB n=12
27 Correct 10 ms 23900 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB n=5
2 Correct 11 ms 23896 KB n=100
3 Correct 11 ms 23900 KB n=100
4 Correct 11 ms 23900 KB n=100
5 Correct 10 ms 23900 KB n=100
6 Correct 11 ms 23900 KB n=100
7 Correct 11 ms 23896 KB n=100
8 Correct 11 ms 23900 KB n=100
9 Correct 11 ms 23896 KB n=100
10 Correct 11 ms 23896 KB n=100
11 Correct 11 ms 23900 KB n=100
12 Correct 11 ms 23892 KB n=100
13 Correct 11 ms 23896 KB n=100
14 Correct 12 ms 23900 KB n=100
15 Correct 11 ms 23900 KB n=100
16 Correct 12 ms 23896 KB n=100
17 Correct 12 ms 24004 KB n=100
18 Correct 11 ms 23900 KB n=100
19 Correct 11 ms 23900 KB n=100
20 Correct 14 ms 23896 KB n=100
21 Correct 9 ms 23896 KB n=100
22 Correct 9 ms 23896 KB n=100
23 Correct 9 ms 23900 KB n=100
24 Correct 13 ms 23964 KB n=100
25 Correct 12 ms 23896 KB n=100
26 Correct 11 ms 23900 KB n=12
27 Correct 10 ms 23900 KB n=100
28 Correct 12 ms 23900 KB n=500
29 Correct 13 ms 24116 KB n=500
30 Correct 11 ms 24152 KB n=500
31 Correct 10 ms 24156 KB n=500
32 Correct 11 ms 23900 KB n=500
33 Correct 10 ms 24156 KB n=500
34 Correct 10 ms 24016 KB n=500
35 Correct 10 ms 24156 KB n=500
36 Correct 10 ms 23976 KB n=500
37 Correct 10 ms 24156 KB n=500
38 Correct 11 ms 23900 KB n=500
39 Correct 10 ms 23972 KB n=500
40 Correct 10 ms 23896 KB n=500
41 Correct 13 ms 24156 KB n=500
42 Correct 10 ms 23900 KB n=500
43 Correct 10 ms 24144 KB n=500
44 Correct 10 ms 23900 KB n=500
45 Correct 11 ms 24128 KB n=500
46 Correct 12 ms 24152 KB n=500
47 Correct 10 ms 24156 KB n=500
48 Correct 10 ms 23900 KB n=500
49 Correct 10 ms 24156 KB n=500
50 Correct 10 ms 23900 KB n=500
51 Correct 12 ms 24152 KB n=500
52 Correct 10 ms 23960 KB n=500
53 Correct 10 ms 24156 KB n=500
54 Correct 10 ms 24156 KB n=500
55 Correct 10 ms 24092 KB n=278
56 Correct 10 ms 24152 KB n=500
57 Correct 10 ms 24156 KB n=500
58 Correct 10 ms 23900 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB n=5
2 Correct 11 ms 23896 KB n=100
3 Correct 11 ms 23900 KB n=100
4 Correct 11 ms 23900 KB n=100
5 Correct 10 ms 23900 KB n=100
6 Correct 11 ms 23900 KB n=100
7 Correct 11 ms 23896 KB n=100
8 Correct 11 ms 23900 KB n=100
9 Correct 11 ms 23896 KB n=100
10 Correct 11 ms 23896 KB n=100
11 Correct 11 ms 23900 KB n=100
12 Correct 11 ms 23892 KB n=100
13 Correct 11 ms 23896 KB n=100
14 Correct 12 ms 23900 KB n=100
15 Correct 11 ms 23900 KB n=100
16 Correct 12 ms 23896 KB n=100
17 Correct 12 ms 24004 KB n=100
18 Correct 11 ms 23900 KB n=100
19 Correct 11 ms 23900 KB n=100
20 Correct 14 ms 23896 KB n=100
21 Correct 9 ms 23896 KB n=100
22 Correct 9 ms 23896 KB n=100
23 Correct 9 ms 23900 KB n=100
24 Correct 13 ms 23964 KB n=100
25 Correct 12 ms 23896 KB n=100
26 Correct 11 ms 23900 KB n=12
27 Correct 10 ms 23900 KB n=100
28 Correct 12 ms 23900 KB n=500
29 Correct 13 ms 24116 KB n=500
30 Correct 11 ms 24152 KB n=500
31 Correct 10 ms 24156 KB n=500
32 Correct 11 ms 23900 KB n=500
33 Correct 10 ms 24156 KB n=500
34 Correct 10 ms 24016 KB n=500
35 Correct 10 ms 24156 KB n=500
36 Correct 10 ms 23976 KB n=500
37 Correct 10 ms 24156 KB n=500
38 Correct 11 ms 23900 KB n=500
39 Correct 10 ms 23972 KB n=500
40 Correct 10 ms 23896 KB n=500
41 Correct 13 ms 24156 KB n=500
42 Correct 10 ms 23900 KB n=500
43 Correct 10 ms 24144 KB n=500
44 Correct 10 ms 23900 KB n=500
45 Correct 11 ms 24128 KB n=500
46 Correct 12 ms 24152 KB n=500
47 Correct 10 ms 24156 KB n=500
48 Correct 10 ms 23900 KB n=500
49 Correct 10 ms 24156 KB n=500
50 Correct 10 ms 23900 KB n=500
51 Correct 12 ms 24152 KB n=500
52 Correct 10 ms 23960 KB n=500
53 Correct 10 ms 24156 KB n=500
54 Correct 10 ms 24156 KB n=500
55 Correct 10 ms 24092 KB n=278
56 Correct 10 ms 24152 KB n=500
57 Correct 10 ms 24156 KB n=500
58 Correct 10 ms 23900 KB n=500
59 Correct 16 ms 24408 KB n=2000
60 Correct 13 ms 24668 KB n=2000
61 Correct 13 ms 24668 KB n=2000
62 Correct 13 ms 24664 KB n=2000
63 Correct 12 ms 24408 KB n=2000
64 Correct 12 ms 24600 KB n=2000
65 Correct 12 ms 24412 KB n=2000
66 Correct 12 ms 24668 KB n=2000
67 Correct 12 ms 24408 KB n=2000
68 Correct 11 ms 24664 KB n=2000
69 Correct 11 ms 24412 KB n=2000
70 Correct 11 ms 24408 KB n=2000
71 Correct 10 ms 24412 KB n=2000
72 Correct 11 ms 24412 KB n=2000
73 Correct 13 ms 24664 KB n=2000
74 Correct 15 ms 24412 KB n=1844
75 Correct 15 ms 24600 KB n=2000
76 Correct 16 ms 24592 KB n=2000
77 Correct 13 ms 24648 KB n=2000
78 Correct 14 ms 24488 KB n=2000
79 Correct 14 ms 24412 KB n=2000
80 Correct 12 ms 24668 KB n=2000
81 Correct 12 ms 24492 KB n=2000
82 Correct 13 ms 24412 KB n=2000
83 Correct 17 ms 24708 KB n=2000
84 Correct 14 ms 24656 KB n=2000
85 Correct 15 ms 24660 KB n=2000
86 Correct 17 ms 24668 KB n=2000
87 Correct 17 ms 24412 KB n=2000
88 Correct 16 ms 24636 KB n=2000
89 Correct 14 ms 24668 KB n=2000
90 Correct 14 ms 24664 KB n=2000
91 Correct 14 ms 24664 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23900 KB n=5
2 Correct 11 ms 23896 KB n=100
3 Correct 11 ms 23900 KB n=100
4 Correct 11 ms 23900 KB n=100
5 Correct 10 ms 23900 KB n=100
6 Correct 11 ms 23900 KB n=100
7 Correct 11 ms 23896 KB n=100
8 Correct 11 ms 23900 KB n=100
9 Correct 11 ms 23896 KB n=100
10 Correct 11 ms 23896 KB n=100
11 Correct 11 ms 23900 KB n=100
12 Correct 11 ms 23892 KB n=100
13 Correct 11 ms 23896 KB n=100
14 Correct 12 ms 23900 KB n=100
15 Correct 11 ms 23900 KB n=100
16 Correct 12 ms 23896 KB n=100
17 Correct 12 ms 24004 KB n=100
18 Correct 11 ms 23900 KB n=100
19 Correct 11 ms 23900 KB n=100
20 Correct 14 ms 23896 KB n=100
21 Correct 9 ms 23896 KB n=100
22 Correct 9 ms 23896 KB n=100
23 Correct 9 ms 23900 KB n=100
24 Correct 13 ms 23964 KB n=100
25 Correct 12 ms 23896 KB n=100
26 Correct 11 ms 23900 KB n=12
27 Correct 10 ms 23900 KB n=100
28 Correct 12 ms 23900 KB n=500
29 Correct 13 ms 24116 KB n=500
30 Correct 11 ms 24152 KB n=500
31 Correct 10 ms 24156 KB n=500
32 Correct 11 ms 23900 KB n=500
33 Correct 10 ms 24156 KB n=500
34 Correct 10 ms 24016 KB n=500
35 Correct 10 ms 24156 KB n=500
36 Correct 10 ms 23976 KB n=500
37 Correct 10 ms 24156 KB n=500
38 Correct 11 ms 23900 KB n=500
39 Correct 10 ms 23972 KB n=500
40 Correct 10 ms 23896 KB n=500
41 Correct 13 ms 24156 KB n=500
42 Correct 10 ms 23900 KB n=500
43 Correct 10 ms 24144 KB n=500
44 Correct 10 ms 23900 KB n=500
45 Correct 11 ms 24128 KB n=500
46 Correct 12 ms 24152 KB n=500
47 Correct 10 ms 24156 KB n=500
48 Correct 10 ms 23900 KB n=500
49 Correct 10 ms 24156 KB n=500
50 Correct 10 ms 23900 KB n=500
51 Correct 12 ms 24152 KB n=500
52 Correct 10 ms 23960 KB n=500
53 Correct 10 ms 24156 KB n=500
54 Correct 10 ms 24156 KB n=500
55 Correct 10 ms 24092 KB n=278
56 Correct 10 ms 24152 KB n=500
57 Correct 10 ms 24156 KB n=500
58 Correct 10 ms 23900 KB n=500
59 Correct 16 ms 24408 KB n=2000
60 Correct 13 ms 24668 KB n=2000
61 Correct 13 ms 24668 KB n=2000
62 Correct 13 ms 24664 KB n=2000
63 Correct 12 ms 24408 KB n=2000
64 Correct 12 ms 24600 KB n=2000
65 Correct 12 ms 24412 KB n=2000
66 Correct 12 ms 24668 KB n=2000
67 Correct 12 ms 24408 KB n=2000
68 Correct 11 ms 24664 KB n=2000
69 Correct 11 ms 24412 KB n=2000
70 Correct 11 ms 24408 KB n=2000
71 Correct 10 ms 24412 KB n=2000
72 Correct 11 ms 24412 KB n=2000
73 Correct 13 ms 24664 KB n=2000
74 Correct 15 ms 24412 KB n=1844
75 Correct 15 ms 24600 KB n=2000
76 Correct 16 ms 24592 KB n=2000
77 Correct 13 ms 24648 KB n=2000
78 Correct 14 ms 24488 KB n=2000
79 Correct 14 ms 24412 KB n=2000
80 Correct 12 ms 24668 KB n=2000
81 Correct 12 ms 24492 KB n=2000
82 Correct 13 ms 24412 KB n=2000
83 Correct 17 ms 24708 KB n=2000
84 Correct 14 ms 24656 KB n=2000
85 Correct 15 ms 24660 KB n=2000
86 Correct 17 ms 24668 KB n=2000
87 Correct 17 ms 24412 KB n=2000
88 Correct 16 ms 24636 KB n=2000
89 Correct 14 ms 24668 KB n=2000
90 Correct 14 ms 24664 KB n=2000
91 Correct 14 ms 24664 KB n=2000
92 Correct 574 ms 92560 KB n=200000
93 Correct 994 ms 99024 KB n=200000
94 Correct 1004 ms 103140 KB n=200000
95 Correct 513 ms 92352 KB n=200000
96 Correct 443 ms 92356 KB n=200000
97 Correct 685 ms 97924 KB n=200000
98 Correct 464 ms 92300 KB n=200000
99 Correct 732 ms 92756 KB n=200000
100 Correct 508 ms 92408 KB n=200000
101 Correct 768 ms 104456 KB n=200000
102 Correct 301 ms 93776 KB n=200000
103 Correct 301 ms 93944 KB n=200000
104 Correct 344 ms 93784 KB n=200000
105 Correct 353 ms 94100 KB n=200000
106 Correct 372 ms 94240 KB n=200000
107 Correct 336 ms 94140 KB n=200000
108 Correct 661 ms 92832 KB n=200000
109 Correct 666 ms 92756 KB n=200000
110 Correct 655 ms 92752 KB n=200000
111 Correct 482 ms 91768 KB n=200000
112 Correct 993 ms 103588 KB n=200000
113 Correct 1191 ms 97876 KB n=200000
114 Correct 662 ms 92016 KB n=200000
115 Correct 1301 ms 95272 KB n=200000
116 Correct 595 ms 92536 KB n=200000
117 Correct 981 ms 103708 KB n=200000
118 Correct 1081 ms 96592 KB n=200000
119 Correct 526 ms 92660 KB n=200000
120 Correct 962 ms 103500 KB n=200000
121 Correct 986 ms 103504 KB n=200000
122 Correct 1093 ms 103740 KB n=200000
123 Correct 457 ms 93980 KB n=200000
124 Correct 196 ms 41652 KB n=25264