답안 #890514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890514 2023-12-21T11:34:38 Z ttamx Birthday gift (IZhO18_treearray) C++14
100 / 100
851 ms 82572 KB
#include<bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using db = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<db>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<db,db>;
const int INF=0x3fffffff;
// const int MOD=1000000007;
const int MOD=998244353;
const ll LINF=0x1fffffffffffffff;
const db DINF=numeric_limits<db>::infinity();
const db EPS=1e-9;
const db PI=acos(db(-1));

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

int n,m,q;
int a[N];
vector<int> adj[N];
set<int> pos[N],pos2[N];
int lv[N],pa[N][K];

void dfs(int u,int p=0){
    lv[u]=lv[p]+1;
    pa[u][0]=p;
    for(int i=1;i<K;i++)pa[u][i]=pa[pa[u][i-1]][i-1];
    for(auto v:adj[u])if(v!=p)dfs(v,u);
}

int lca(int u,int v){
    if(lv[u]<lv[v])swap(u,v);
    for(int i=K-1;i>=0;i--)if(lv[pa[u][i]]>=lv[v])u=pa[u][i];
    if(u==v)return u;
    for(int i=K-1;i>=0;i--)if(pa[u][i]!=pa[v][i])u=pa[u][i],v=pa[v][i];
    return pa[u][0];
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> m >> q;
    for(int i=1;i<n;i++){
        int u,v;
        cin >> u >> v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }
    dfs(1);
    for(int i=1;i<=m;i++)cin >> a[i];
    for(int i=1;i<=m;i++)pos[a[i]].emplace(i);
    for(int i=2;i<=m;i++)pos2[lca(a[i],a[i-1])].emplace(i);
    while(q--){
        int t;
        cin >> t;
        if(t==1){
            int i,v;
            cin >> i >> v;
            pos[a[i]].erase(i);
            if(i>1)pos2[lca(a[i],a[i-1])].erase(i);
            if(i<m)pos2[lca(a[i],a[i+1])].erase(i+1);
            a[i]=v;
            pos[a[i]].emplace(i);
            if(i>1)pos2[lca(a[i],a[i-1])].emplace(i);
            if(i<m)pos2[lca(a[i],a[i+1])].emplace(i+1);
        }else{
            int l,r,v;
            cin >> l >> r >> v;
            auto it=pos[v].lower_bound(l);
            if(it!=pos[v].end()&&*it<=r){
                cout << *it << " " << *it << "\n";
                continue;
            }
            it=pos2[v].lower_bound(l+1);
            if(it!=pos2[v].end()&&*it<=r){
                cout << *it-1 << " " << *it << "\n";
                continue;
            }
            cout << "-1 -1\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 24156 KB n=5
2 Correct 6 ms 24156 KB n=100
3 Correct 5 ms 24152 KB n=100
4 Correct 5 ms 24156 KB n=100
5 Correct 5 ms 24156 KB n=100
6 Correct 5 ms 24156 KB n=100
7 Correct 5 ms 24276 KB n=100
8 Correct 5 ms 24156 KB n=100
9 Correct 6 ms 24152 KB n=100
10 Correct 5 ms 24156 KB n=100
11 Correct 5 ms 24156 KB n=100
12 Correct 5 ms 24152 KB n=100
13 Correct 6 ms 24156 KB n=100
14 Correct 5 ms 24244 KB n=100
15 Correct 5 ms 24156 KB n=100
16 Correct 6 ms 24152 KB n=100
17 Correct 5 ms 24156 KB n=100
18 Correct 7 ms 24152 KB n=100
19 Correct 6 ms 24156 KB n=100
20 Correct 5 ms 24156 KB n=100
21 Correct 5 ms 24156 KB n=100
22 Correct 5 ms 24152 KB n=100
23 Correct 5 ms 24156 KB n=100
24 Correct 5 ms 24156 KB n=100
25 Correct 5 ms 24276 KB n=100
26 Correct 6 ms 24152 KB n=12
27 Correct 5 ms 24156 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 24156 KB n=5
2 Correct 6 ms 24156 KB n=100
3 Correct 5 ms 24152 KB n=100
4 Correct 5 ms 24156 KB n=100
5 Correct 5 ms 24156 KB n=100
6 Correct 5 ms 24156 KB n=100
7 Correct 5 ms 24276 KB n=100
8 Correct 5 ms 24156 KB n=100
9 Correct 6 ms 24152 KB n=100
10 Correct 5 ms 24156 KB n=100
11 Correct 5 ms 24156 KB n=100
12 Correct 5 ms 24152 KB n=100
13 Correct 6 ms 24156 KB n=100
14 Correct 5 ms 24244 KB n=100
15 Correct 5 ms 24156 KB n=100
16 Correct 6 ms 24152 KB n=100
17 Correct 5 ms 24156 KB n=100
18 Correct 7 ms 24152 KB n=100
19 Correct 6 ms 24156 KB n=100
20 Correct 5 ms 24156 KB n=100
21 Correct 5 ms 24156 KB n=100
22 Correct 5 ms 24152 KB n=100
23 Correct 5 ms 24156 KB n=100
24 Correct 5 ms 24156 KB n=100
25 Correct 5 ms 24276 KB n=100
26 Correct 6 ms 24152 KB n=12
27 Correct 5 ms 24156 KB n=100
28 Correct 6 ms 24152 KB n=500
29 Correct 6 ms 24292 KB n=500
30 Correct 6 ms 24408 KB n=500
31 Correct 6 ms 24412 KB n=500
32 Correct 6 ms 24352 KB n=500
33 Correct 6 ms 24412 KB n=500
34 Correct 6 ms 24156 KB n=500
35 Correct 6 ms 24412 KB n=500
36 Correct 6 ms 24156 KB n=500
37 Correct 6 ms 24244 KB n=500
38 Correct 6 ms 24412 KB n=500
39 Correct 6 ms 24412 KB n=500
40 Correct 6 ms 24412 KB n=500
41 Correct 6 ms 24244 KB n=500
42 Correct 6 ms 24156 KB n=500
43 Correct 6 ms 24156 KB n=500
44 Correct 6 ms 24412 KB n=500
45 Correct 6 ms 24156 KB n=500
46 Correct 6 ms 24412 KB n=500
47 Correct 6 ms 24412 KB n=500
48 Correct 6 ms 24412 KB n=500
49 Correct 6 ms 24412 KB n=500
50 Correct 6 ms 24408 KB n=500
51 Correct 6 ms 24412 KB n=500
52 Correct 6 ms 24412 KB n=500
53 Correct 6 ms 24408 KB n=500
54 Correct 6 ms 24408 KB n=500
55 Correct 6 ms 24284 KB n=278
56 Correct 6 ms 24412 KB n=500
57 Correct 6 ms 24412 KB n=500
58 Correct 6 ms 24412 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 24156 KB n=5
2 Correct 6 ms 24156 KB n=100
3 Correct 5 ms 24152 KB n=100
4 Correct 5 ms 24156 KB n=100
5 Correct 5 ms 24156 KB n=100
6 Correct 5 ms 24156 KB n=100
7 Correct 5 ms 24276 KB n=100
8 Correct 5 ms 24156 KB n=100
9 Correct 6 ms 24152 KB n=100
10 Correct 5 ms 24156 KB n=100
11 Correct 5 ms 24156 KB n=100
12 Correct 5 ms 24152 KB n=100
13 Correct 6 ms 24156 KB n=100
14 Correct 5 ms 24244 KB n=100
15 Correct 5 ms 24156 KB n=100
16 Correct 6 ms 24152 KB n=100
17 Correct 5 ms 24156 KB n=100
18 Correct 7 ms 24152 KB n=100
19 Correct 6 ms 24156 KB n=100
20 Correct 5 ms 24156 KB n=100
21 Correct 5 ms 24156 KB n=100
22 Correct 5 ms 24152 KB n=100
23 Correct 5 ms 24156 KB n=100
24 Correct 5 ms 24156 KB n=100
25 Correct 5 ms 24276 KB n=100
26 Correct 6 ms 24152 KB n=12
27 Correct 5 ms 24156 KB n=100
28 Correct 6 ms 24152 KB n=500
29 Correct 6 ms 24292 KB n=500
30 Correct 6 ms 24408 KB n=500
31 Correct 6 ms 24412 KB n=500
32 Correct 6 ms 24352 KB n=500
33 Correct 6 ms 24412 KB n=500
34 Correct 6 ms 24156 KB n=500
35 Correct 6 ms 24412 KB n=500
36 Correct 6 ms 24156 KB n=500
37 Correct 6 ms 24244 KB n=500
38 Correct 6 ms 24412 KB n=500
39 Correct 6 ms 24412 KB n=500
40 Correct 6 ms 24412 KB n=500
41 Correct 6 ms 24244 KB n=500
42 Correct 6 ms 24156 KB n=500
43 Correct 6 ms 24156 KB n=500
44 Correct 6 ms 24412 KB n=500
45 Correct 6 ms 24156 KB n=500
46 Correct 6 ms 24412 KB n=500
47 Correct 6 ms 24412 KB n=500
48 Correct 6 ms 24412 KB n=500
49 Correct 6 ms 24412 KB n=500
50 Correct 6 ms 24408 KB n=500
51 Correct 6 ms 24412 KB n=500
52 Correct 6 ms 24412 KB n=500
53 Correct 6 ms 24408 KB n=500
54 Correct 6 ms 24408 KB n=500
55 Correct 6 ms 24284 KB n=278
56 Correct 6 ms 24412 KB n=500
57 Correct 6 ms 24412 KB n=500
58 Correct 6 ms 24412 KB n=500
59 Correct 8 ms 24668 KB n=2000
60 Correct 8 ms 24668 KB n=2000
61 Correct 8 ms 24740 KB n=2000
62 Correct 8 ms 24668 KB n=2000
63 Correct 8 ms 24664 KB n=2000
64 Correct 8 ms 24664 KB n=2000
65 Correct 8 ms 24668 KB n=2000
66 Correct 9 ms 24620 KB n=2000
67 Correct 9 ms 24668 KB n=2000
68 Correct 8 ms 24668 KB n=2000
69 Correct 7 ms 24668 KB n=2000
70 Correct 7 ms 24664 KB n=2000
71 Correct 7 ms 24668 KB n=2000
72 Correct 8 ms 24652 KB n=2000
73 Correct 7 ms 24668 KB n=2000
74 Correct 8 ms 24668 KB n=1844
75 Correct 7 ms 24668 KB n=2000
76 Correct 8 ms 24748 KB n=2000
77 Correct 9 ms 24668 KB n=2000
78 Correct 9 ms 24668 KB n=2000
79 Correct 8 ms 24668 KB n=2000
80 Correct 8 ms 24668 KB n=2000
81 Correct 8 ms 24920 KB n=2000
82 Correct 9 ms 24668 KB n=2000
83 Correct 8 ms 24668 KB n=2000
84 Correct 8 ms 24668 KB n=2000
85 Correct 8 ms 24548 KB n=2000
86 Correct 9 ms 24724 KB n=2000
87 Correct 8 ms 24664 KB n=2000
88 Correct 7 ms 24664 KB n=2000
89 Correct 8 ms 24668 KB n=2000
90 Correct 8 ms 24668 KB n=2000
91 Correct 7 ms 24764 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 24156 KB n=5
2 Correct 6 ms 24156 KB n=100
3 Correct 5 ms 24152 KB n=100
4 Correct 5 ms 24156 KB n=100
5 Correct 5 ms 24156 KB n=100
6 Correct 5 ms 24156 KB n=100
7 Correct 5 ms 24276 KB n=100
8 Correct 5 ms 24156 KB n=100
9 Correct 6 ms 24152 KB n=100
10 Correct 5 ms 24156 KB n=100
11 Correct 5 ms 24156 KB n=100
12 Correct 5 ms 24152 KB n=100
13 Correct 6 ms 24156 KB n=100
14 Correct 5 ms 24244 KB n=100
15 Correct 5 ms 24156 KB n=100
16 Correct 6 ms 24152 KB n=100
17 Correct 5 ms 24156 KB n=100
18 Correct 7 ms 24152 KB n=100
19 Correct 6 ms 24156 KB n=100
20 Correct 5 ms 24156 KB n=100
21 Correct 5 ms 24156 KB n=100
22 Correct 5 ms 24152 KB n=100
23 Correct 5 ms 24156 KB n=100
24 Correct 5 ms 24156 KB n=100
25 Correct 5 ms 24276 KB n=100
26 Correct 6 ms 24152 KB n=12
27 Correct 5 ms 24156 KB n=100
28 Correct 6 ms 24152 KB n=500
29 Correct 6 ms 24292 KB n=500
30 Correct 6 ms 24408 KB n=500
31 Correct 6 ms 24412 KB n=500
32 Correct 6 ms 24352 KB n=500
33 Correct 6 ms 24412 KB n=500
34 Correct 6 ms 24156 KB n=500
35 Correct 6 ms 24412 KB n=500
36 Correct 6 ms 24156 KB n=500
37 Correct 6 ms 24244 KB n=500
38 Correct 6 ms 24412 KB n=500
39 Correct 6 ms 24412 KB n=500
40 Correct 6 ms 24412 KB n=500
41 Correct 6 ms 24244 KB n=500
42 Correct 6 ms 24156 KB n=500
43 Correct 6 ms 24156 KB n=500
44 Correct 6 ms 24412 KB n=500
45 Correct 6 ms 24156 KB n=500
46 Correct 6 ms 24412 KB n=500
47 Correct 6 ms 24412 KB n=500
48 Correct 6 ms 24412 KB n=500
49 Correct 6 ms 24412 KB n=500
50 Correct 6 ms 24408 KB n=500
51 Correct 6 ms 24412 KB n=500
52 Correct 6 ms 24412 KB n=500
53 Correct 6 ms 24408 KB n=500
54 Correct 6 ms 24408 KB n=500
55 Correct 6 ms 24284 KB n=278
56 Correct 6 ms 24412 KB n=500
57 Correct 6 ms 24412 KB n=500
58 Correct 6 ms 24412 KB n=500
59 Correct 8 ms 24668 KB n=2000
60 Correct 8 ms 24668 KB n=2000
61 Correct 8 ms 24740 KB n=2000
62 Correct 8 ms 24668 KB n=2000
63 Correct 8 ms 24664 KB n=2000
64 Correct 8 ms 24664 KB n=2000
65 Correct 8 ms 24668 KB n=2000
66 Correct 9 ms 24620 KB n=2000
67 Correct 9 ms 24668 KB n=2000
68 Correct 8 ms 24668 KB n=2000
69 Correct 7 ms 24668 KB n=2000
70 Correct 7 ms 24664 KB n=2000
71 Correct 7 ms 24668 KB n=2000
72 Correct 8 ms 24652 KB n=2000
73 Correct 7 ms 24668 KB n=2000
74 Correct 8 ms 24668 KB n=1844
75 Correct 7 ms 24668 KB n=2000
76 Correct 8 ms 24748 KB n=2000
77 Correct 9 ms 24668 KB n=2000
78 Correct 9 ms 24668 KB n=2000
79 Correct 8 ms 24668 KB n=2000
80 Correct 8 ms 24668 KB n=2000
81 Correct 8 ms 24920 KB n=2000
82 Correct 9 ms 24668 KB n=2000
83 Correct 8 ms 24668 KB n=2000
84 Correct 8 ms 24668 KB n=2000
85 Correct 8 ms 24548 KB n=2000
86 Correct 9 ms 24724 KB n=2000
87 Correct 8 ms 24664 KB n=2000
88 Correct 7 ms 24664 KB n=2000
89 Correct 8 ms 24668 KB n=2000
90 Correct 8 ms 24668 KB n=2000
91 Correct 7 ms 24764 KB n=2000
92 Correct 539 ms 73096 KB n=200000
93 Correct 737 ms 78024 KB n=200000
94 Correct 698 ms 81356 KB n=200000
95 Correct 544 ms 73068 KB n=200000
96 Correct 484 ms 72948 KB n=200000
97 Correct 846 ms 77136 KB n=200000
98 Correct 527 ms 72940 KB n=200000
99 Correct 643 ms 73092 KB n=200000
100 Correct 552 ms 72904 KB n=200000
101 Correct 788 ms 82572 KB n=200000
102 Correct 290 ms 74160 KB n=200000
103 Correct 276 ms 73948 KB n=200000
104 Correct 286 ms 73884 KB n=200000
105 Correct 306 ms 74460 KB n=200000
106 Correct 289 ms 74316 KB n=200000
107 Correct 301 ms 74324 KB n=200000
108 Correct 595 ms 73048 KB n=200000
109 Correct 607 ms 72948 KB n=200000
110 Correct 671 ms 73044 KB n=200000
111 Correct 590 ms 72348 KB n=200000
112 Correct 851 ms 81512 KB n=200000
113 Correct 838 ms 77140 KB n=200000
114 Correct 501 ms 72240 KB n=200000
115 Correct 773 ms 75044 KB n=200000
116 Correct 502 ms 73048 KB n=200000
117 Correct 690 ms 82156 KB n=200000
118 Correct 744 ms 75860 KB n=200000
119 Correct 475 ms 72900 KB n=200000
120 Correct 615 ms 81528 KB n=200000
121 Correct 618 ms 81488 KB n=200000
122 Correct 591 ms 81748 KB n=200000
123 Correct 297 ms 74324 KB n=200000
124 Correct 126 ms 39252 KB n=25264