답안 #1110966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110966 2024-11-11T06:58:51 Z KasymK Birthday gift (IZhO18_treearray) C++17
100 / 100
859 ms 88272 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 3e5+5;
const int LOG = 25;
vector<int> adj[N];
int v[N], A[N][LOG], d[N];

void dfs(int x, int pr = -1){
    A[x][0] = pr;
    for(int i = 1; i < LOG; ++i)
        A[x][i] = A[A[x][i-1]][i-1];
    tr(it, adj[x])
        if(*it!=pr){
            d[*it] = d[x]+1;
            dfs(*it, x);
        }
}

int al(int x, int k){
    if(d[x]<k)
        return -1;
    for(int i = LOG-1; i >= 0; --i)
        if(k>>i&1){
            if(A[x][i]==-1)
                return -1;
            x = A[x][i];
        }
    return x;
}

int lca(int a, int b){
    if(d[b]>d[a])
        swap(a, b);
    a = al(a, d[a]-d[b]);
    if(a==b)
        return a;
    for(int i = LOG-1; i >= 0; --i)
        if(A[a][i] != A[b][i])
            a = A[a][i], b = A[b][i];
    return A[a][0];
}

int main(){
    // freopen("file.txt", "r", stdin);
    int n, m, q;
    scanf("%d%d%d", &n, &m, &q);
    for(int i = 1; i < n; ++i){
        int a, b;
        scanf("%d%d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(1);
    for(int i = 1; i <= m; ++i){
        int x;
        scanf("%d", &x);
        v[i] = x;
        assert(x <= n);
    }
    vector<set<pii>> A(n+1);
    for(int i = 1; i <= m; ++i)
        A[v[i]].insert({i, i});
    for(int i = 1; i < m; ++i)
        A[lca(v[i], v[i+1])].insert({i, i+1});
    while(q--){
        int op;
        scanf("%d", &op);
        if(op==1){
            int k, u;
            scanf("%d%d", &k, &u);
            A[v[k]].erase({k, k});
            if(k>1)
                A[lca(v[k-1], v[k])].erase({k-1, k});
            if(k+1<=m)
                A[lca(v[k], v[k+1])].erase({k, k+1});
            v[k] = u;
            A[v[k]].insert({k, k});
            if(k>1)
                A[lca(v[k-1], v[k])].insert({k-1, k});
            if(k+1<=m)
                A[lca(v[k], v[k+1])].insert({k, k+1});
            continue;
        }
        int l, r, val;
        scanf("%d%d%d", &l, &r, &val);
        auto ii = A[val].lower_bound({l, l});
        if(ii==A[val].end() or ii->ss>r)
            printf("-1 -1\n");
        else
            printf("%d %d\n", ii->ff, ii->ss);
    }
    return 0;
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     scanf("%d%d%d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
treearray.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
treearray.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         scanf("%d", &op);
      |         ~~~~~^~~~~~~~~~~
treearray.cpp:82:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |             scanf("%d%d", &k, &u);
      |             ~~~~~^~~~~~~~~~~~~~~~
treearray.cpp:97:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         scanf("%d%d%d", &l, &r, &val);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12112 KB n=5
2 Correct 3 ms 12112 KB n=100
3 Correct 3 ms 12112 KB n=100
4 Correct 3 ms 12112 KB n=100
5 Correct 3 ms 12112 KB n=100
6 Correct 3 ms 12112 KB n=100
7 Correct 3 ms 12112 KB n=100
8 Correct 3 ms 12112 KB n=100
9 Correct 4 ms 12280 KB n=100
10 Correct 3 ms 12112 KB n=100
11 Correct 3 ms 12216 KB n=100
12 Correct 3 ms 12112 KB n=100
13 Correct 4 ms 12112 KB n=100
14 Correct 4 ms 12344 KB n=100
15 Correct 3 ms 12112 KB n=100
16 Correct 3 ms 12112 KB n=100
17 Correct 4 ms 12112 KB n=100
18 Correct 3 ms 12112 KB n=100
19 Correct 3 ms 12112 KB n=100
20 Correct 4 ms 12112 KB n=100
21 Correct 4 ms 12112 KB n=100
22 Correct 3 ms 12112 KB n=100
23 Correct 3 ms 12112 KB n=100
24 Correct 4 ms 12112 KB n=100
25 Correct 4 ms 12112 KB n=100
26 Correct 4 ms 12112 KB n=12
27 Correct 3 ms 12112 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12112 KB n=5
2 Correct 3 ms 12112 KB n=100
3 Correct 3 ms 12112 KB n=100
4 Correct 3 ms 12112 KB n=100
5 Correct 3 ms 12112 KB n=100
6 Correct 3 ms 12112 KB n=100
7 Correct 3 ms 12112 KB n=100
8 Correct 3 ms 12112 KB n=100
9 Correct 4 ms 12280 KB n=100
10 Correct 3 ms 12112 KB n=100
11 Correct 3 ms 12216 KB n=100
12 Correct 3 ms 12112 KB n=100
13 Correct 4 ms 12112 KB n=100
14 Correct 4 ms 12344 KB n=100
15 Correct 3 ms 12112 KB n=100
16 Correct 3 ms 12112 KB n=100
17 Correct 4 ms 12112 KB n=100
18 Correct 3 ms 12112 KB n=100
19 Correct 3 ms 12112 KB n=100
20 Correct 4 ms 12112 KB n=100
21 Correct 4 ms 12112 KB n=100
22 Correct 3 ms 12112 KB n=100
23 Correct 3 ms 12112 KB n=100
24 Correct 4 ms 12112 KB n=100
25 Correct 4 ms 12112 KB n=100
26 Correct 4 ms 12112 KB n=12
27 Correct 3 ms 12112 KB n=100
28 Correct 4 ms 12368 KB n=500
29 Correct 3 ms 12368 KB n=500
30 Correct 4 ms 12368 KB n=500
31 Correct 4 ms 12368 KB n=500
32 Correct 4 ms 12368 KB n=500
33 Correct 4 ms 12368 KB n=500
34 Correct 4 ms 12536 KB n=500
35 Correct 4 ms 12368 KB n=500
36 Correct 4 ms 12336 KB n=500
37 Correct 4 ms 12368 KB n=500
38 Correct 4 ms 12368 KB n=500
39 Correct 3 ms 12368 KB n=500
40 Correct 4 ms 12368 KB n=500
41 Correct 4 ms 12368 KB n=500
42 Correct 4 ms 12536 KB n=500
43 Correct 4 ms 12368 KB n=500
44 Correct 4 ms 12536 KB n=500
45 Correct 4 ms 12368 KB n=500
46 Correct 4 ms 12536 KB n=500
47 Correct 4 ms 12368 KB n=500
48 Correct 4 ms 12368 KB n=500
49 Correct 4 ms 12368 KB n=500
50 Correct 4 ms 12368 KB n=500
51 Correct 4 ms 12340 KB n=500
52 Correct 4 ms 12368 KB n=500
53 Correct 4 ms 12368 KB n=500
54 Correct 4 ms 12368 KB n=500
55 Correct 4 ms 12368 KB n=278
56 Correct 4 ms 12368 KB n=500
57 Correct 4 ms 12368 KB n=500
58 Correct 4 ms 12368 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12112 KB n=5
2 Correct 3 ms 12112 KB n=100
3 Correct 3 ms 12112 KB n=100
4 Correct 3 ms 12112 KB n=100
5 Correct 3 ms 12112 KB n=100
6 Correct 3 ms 12112 KB n=100
7 Correct 3 ms 12112 KB n=100
8 Correct 3 ms 12112 KB n=100
9 Correct 4 ms 12280 KB n=100
10 Correct 3 ms 12112 KB n=100
11 Correct 3 ms 12216 KB n=100
12 Correct 3 ms 12112 KB n=100
13 Correct 4 ms 12112 KB n=100
14 Correct 4 ms 12344 KB n=100
15 Correct 3 ms 12112 KB n=100
16 Correct 3 ms 12112 KB n=100
17 Correct 4 ms 12112 KB n=100
18 Correct 3 ms 12112 KB n=100
19 Correct 3 ms 12112 KB n=100
20 Correct 4 ms 12112 KB n=100
21 Correct 4 ms 12112 KB n=100
22 Correct 3 ms 12112 KB n=100
23 Correct 3 ms 12112 KB n=100
24 Correct 4 ms 12112 KB n=100
25 Correct 4 ms 12112 KB n=100
26 Correct 4 ms 12112 KB n=12
27 Correct 3 ms 12112 KB n=100
28 Correct 4 ms 12368 KB n=500
29 Correct 3 ms 12368 KB n=500
30 Correct 4 ms 12368 KB n=500
31 Correct 4 ms 12368 KB n=500
32 Correct 4 ms 12368 KB n=500
33 Correct 4 ms 12368 KB n=500
34 Correct 4 ms 12536 KB n=500
35 Correct 4 ms 12368 KB n=500
36 Correct 4 ms 12336 KB n=500
37 Correct 4 ms 12368 KB n=500
38 Correct 4 ms 12368 KB n=500
39 Correct 3 ms 12368 KB n=500
40 Correct 4 ms 12368 KB n=500
41 Correct 4 ms 12368 KB n=500
42 Correct 4 ms 12536 KB n=500
43 Correct 4 ms 12368 KB n=500
44 Correct 4 ms 12536 KB n=500
45 Correct 4 ms 12368 KB n=500
46 Correct 4 ms 12536 KB n=500
47 Correct 4 ms 12368 KB n=500
48 Correct 4 ms 12368 KB n=500
49 Correct 4 ms 12368 KB n=500
50 Correct 4 ms 12368 KB n=500
51 Correct 4 ms 12340 KB n=500
52 Correct 4 ms 12368 KB n=500
53 Correct 4 ms 12368 KB n=500
54 Correct 4 ms 12368 KB n=500
55 Correct 4 ms 12368 KB n=278
56 Correct 4 ms 12368 KB n=500
57 Correct 4 ms 12368 KB n=500
58 Correct 4 ms 12368 KB n=500
59 Correct 8 ms 12624 KB n=2000
60 Correct 6 ms 12624 KB n=2000
61 Correct 5 ms 12624 KB n=2000
62 Correct 6 ms 12624 KB n=2000
63 Correct 6 ms 12624 KB n=2000
64 Correct 6 ms 12800 KB n=2000
65 Correct 6 ms 12624 KB n=2000
66 Correct 6 ms 12624 KB n=2000
67 Correct 6 ms 12624 KB n=2000
68 Correct 7 ms 12624 KB n=2000
69 Correct 5 ms 12624 KB n=2000
70 Correct 5 ms 12624 KB n=2000
71 Correct 5 ms 12624 KB n=2000
72 Correct 4 ms 12660 KB n=2000
73 Correct 5 ms 12792 KB n=2000
74 Correct 5 ms 12800 KB n=1844
75 Correct 7 ms 12624 KB n=2000
76 Correct 6 ms 12624 KB n=2000
77 Correct 6 ms 12624 KB n=2000
78 Correct 6 ms 12624 KB n=2000
79 Correct 7 ms 12624 KB n=2000
80 Correct 7 ms 12624 KB n=2000
81 Correct 6 ms 12636 KB n=2000
82 Correct 6 ms 12624 KB n=2000
83 Correct 6 ms 12804 KB n=2000
84 Correct 5 ms 12624 KB n=2000
85 Correct 6 ms 12624 KB n=2000
86 Correct 6 ms 12624 KB n=2000
87 Correct 6 ms 12624 KB n=2000
88 Correct 6 ms 12624 KB n=2000
89 Correct 5 ms 12624 KB n=2000
90 Correct 6 ms 12624 KB n=2000
91 Correct 5 ms 12672 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12112 KB n=5
2 Correct 3 ms 12112 KB n=100
3 Correct 3 ms 12112 KB n=100
4 Correct 3 ms 12112 KB n=100
5 Correct 3 ms 12112 KB n=100
6 Correct 3 ms 12112 KB n=100
7 Correct 3 ms 12112 KB n=100
8 Correct 3 ms 12112 KB n=100
9 Correct 4 ms 12280 KB n=100
10 Correct 3 ms 12112 KB n=100
11 Correct 3 ms 12216 KB n=100
12 Correct 3 ms 12112 KB n=100
13 Correct 4 ms 12112 KB n=100
14 Correct 4 ms 12344 KB n=100
15 Correct 3 ms 12112 KB n=100
16 Correct 3 ms 12112 KB n=100
17 Correct 4 ms 12112 KB n=100
18 Correct 3 ms 12112 KB n=100
19 Correct 3 ms 12112 KB n=100
20 Correct 4 ms 12112 KB n=100
21 Correct 4 ms 12112 KB n=100
22 Correct 3 ms 12112 KB n=100
23 Correct 3 ms 12112 KB n=100
24 Correct 4 ms 12112 KB n=100
25 Correct 4 ms 12112 KB n=100
26 Correct 4 ms 12112 KB n=12
27 Correct 3 ms 12112 KB n=100
28 Correct 4 ms 12368 KB n=500
29 Correct 3 ms 12368 KB n=500
30 Correct 4 ms 12368 KB n=500
31 Correct 4 ms 12368 KB n=500
32 Correct 4 ms 12368 KB n=500
33 Correct 4 ms 12368 KB n=500
34 Correct 4 ms 12536 KB n=500
35 Correct 4 ms 12368 KB n=500
36 Correct 4 ms 12336 KB n=500
37 Correct 4 ms 12368 KB n=500
38 Correct 4 ms 12368 KB n=500
39 Correct 3 ms 12368 KB n=500
40 Correct 4 ms 12368 KB n=500
41 Correct 4 ms 12368 KB n=500
42 Correct 4 ms 12536 KB n=500
43 Correct 4 ms 12368 KB n=500
44 Correct 4 ms 12536 KB n=500
45 Correct 4 ms 12368 KB n=500
46 Correct 4 ms 12536 KB n=500
47 Correct 4 ms 12368 KB n=500
48 Correct 4 ms 12368 KB n=500
49 Correct 4 ms 12368 KB n=500
50 Correct 4 ms 12368 KB n=500
51 Correct 4 ms 12340 KB n=500
52 Correct 4 ms 12368 KB n=500
53 Correct 4 ms 12368 KB n=500
54 Correct 4 ms 12368 KB n=500
55 Correct 4 ms 12368 KB n=278
56 Correct 4 ms 12368 KB n=500
57 Correct 4 ms 12368 KB n=500
58 Correct 4 ms 12368 KB n=500
59 Correct 8 ms 12624 KB n=2000
60 Correct 6 ms 12624 KB n=2000
61 Correct 5 ms 12624 KB n=2000
62 Correct 6 ms 12624 KB n=2000
63 Correct 6 ms 12624 KB n=2000
64 Correct 6 ms 12800 KB n=2000
65 Correct 6 ms 12624 KB n=2000
66 Correct 6 ms 12624 KB n=2000
67 Correct 6 ms 12624 KB n=2000
68 Correct 7 ms 12624 KB n=2000
69 Correct 5 ms 12624 KB n=2000
70 Correct 5 ms 12624 KB n=2000
71 Correct 5 ms 12624 KB n=2000
72 Correct 4 ms 12660 KB n=2000
73 Correct 5 ms 12792 KB n=2000
74 Correct 5 ms 12800 KB n=1844
75 Correct 7 ms 12624 KB n=2000
76 Correct 6 ms 12624 KB n=2000
77 Correct 6 ms 12624 KB n=2000
78 Correct 6 ms 12624 KB n=2000
79 Correct 7 ms 12624 KB n=2000
80 Correct 7 ms 12624 KB n=2000
81 Correct 6 ms 12636 KB n=2000
82 Correct 6 ms 12624 KB n=2000
83 Correct 6 ms 12804 KB n=2000
84 Correct 5 ms 12624 KB n=2000
85 Correct 6 ms 12624 KB n=2000
86 Correct 6 ms 12624 KB n=2000
87 Correct 6 ms 12624 KB n=2000
88 Correct 6 ms 12624 KB n=2000
89 Correct 5 ms 12624 KB n=2000
90 Correct 6 ms 12624 KB n=2000
91 Correct 5 ms 12672 KB n=2000
92 Correct 510 ms 69960 KB n=200000
93 Correct 514 ms 76356 KB n=200000
94 Correct 557 ms 78920 KB n=200000
95 Correct 566 ms 69132 KB n=200000
96 Correct 595 ms 69396 KB n=200000
97 Correct 859 ms 81100 KB n=200000
98 Correct 624 ms 75688 KB n=200000
99 Correct 636 ms 75832 KB n=200000
100 Correct 530 ms 75716 KB n=200000
101 Correct 717 ms 88272 KB n=200000
102 Correct 277 ms 76872 KB n=200000
103 Correct 255 ms 76872 KB n=200000
104 Correct 286 ms 76792 KB n=200000
105 Correct 293 ms 77128 KB n=200000
106 Correct 314 ms 77376 KB n=200000
107 Correct 297 ms 77188 KB n=200000
108 Correct 559 ms 75848 KB n=200000
109 Correct 569 ms 75848 KB n=200000
110 Correct 582 ms 75848 KB n=200000
111 Correct 564 ms 75116 KB n=200000
112 Correct 741 ms 86940 KB n=200000
113 Correct 531 ms 80968 KB n=200000
114 Correct 428 ms 75196 KB n=200000
115 Correct 553 ms 78088 KB n=200000
116 Correct 433 ms 75760 KB n=200000
117 Correct 503 ms 87504 KB n=200000
118 Correct 545 ms 79588 KB n=200000
119 Correct 452 ms 75708 KB n=200000
120 Correct 521 ms 87368 KB n=200000
121 Correct 504 ms 87544 KB n=200000
122 Correct 519 ms 87676 KB n=200000
123 Correct 268 ms 77072 KB n=200000
124 Correct 120 ms 28232 KB n=25264