답안 #1114062

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114062 2024-11-18T07:20:05 Z vjudge1 Birthday gift (IZhO18_treearray) C++17
56 / 100
4000 ms 56772 KB
//Dost SEFEROĞLU
#include <bits/stdc++.h>
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<    
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e18;
const int N = 2e5+50,Q = 2e5+50;


vi edges[N];
int tin[N],tout[N];
int A[N],B[N];
int timer = 1;
int up[N][20];

void dfs(int node,int p) {
    tin[node] = timer++;
    up[node][0] = p;
    for (auto it : edges[node]) {
        if (it != p) dfs(it,node);
    }
    tout[node] = timer-1;
}

bool anc(int a,int b) {
    return tin[a] <= tin[b] && tout[a] >= tout[b];
}

int lca(int a,int b) {
    if (anc(a,b)) return a;
    if (anc(b,a)) return b;
    for (int i = 19;i>=0;i--) if (!anc(up[a][i],b)) a = up[a][i];
    return up[a][0];
}

void solve() { 
    int n,m,q;
    cin >> n >> m >> q;
    for (int i=1;i<=n-1;i++) {
        int a,b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    dfs(1,1);
    for (int i = 1;i<=m;i++) {
        cin >> B[i];
    }
    for (int i=1;i<20;i++) {
        for (int j = 1;j<=n;j++) up[j][i] = up[up[j][i-1]][i-1];
    }
    while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int p,v;
            cin >> p >> v;
            A[p] = tin[v], B[p] = v;
        }
        else {
            int l,r,v;
            cin >> l >> r >> v;
            int runner = 0;
            int start = 0;
            bool fl = 0;
            for (int j = l;j<=r;j++) {
                if (!anc(v,B[j])) {
                    runner = 0;
                    continue;
                }
                if (!runner) runner = B[j],start = j;
                else runner = lca(runner,B[j]);
                if (runner == v) {
                    cout << start << " " << j << '\n';
                    fl = 1;
                    break;
                }
            }
            if (fl) continue;
            cout << -1 << " " << -1 << '\n';   
        }
    }
}                    
                             
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11600 KB n=5
2 Correct 3 ms 11600 KB n=100
3 Correct 3 ms 11600 KB n=100
4 Correct 3 ms 11600 KB n=100
5 Correct 3 ms 11600 KB n=100
6 Correct 3 ms 11672 KB n=100
7 Correct 3 ms 11600 KB n=100
8 Correct 3 ms 11600 KB n=100
9 Correct 3 ms 11612 KB n=100
10 Correct 3 ms 11600 KB n=100
11 Correct 3 ms 11600 KB n=100
12 Correct 3 ms 11600 KB n=100
13 Correct 4 ms 11616 KB n=100
14 Correct 3 ms 11600 KB n=100
15 Correct 3 ms 11600 KB n=100
16 Correct 3 ms 11600 KB n=100
17 Correct 3 ms 11600 KB n=100
18 Correct 3 ms 11600 KB n=100
19 Correct 3 ms 11600 KB n=100
20 Correct 3 ms 11776 KB n=100
21 Correct 3 ms 11600 KB n=100
22 Correct 3 ms 11768 KB n=100
23 Correct 2 ms 11600 KB n=100
24 Correct 3 ms 11600 KB n=100
25 Correct 3 ms 11768 KB n=100
26 Correct 3 ms 11768 KB n=12
27 Correct 3 ms 11600 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11600 KB n=5
2 Correct 3 ms 11600 KB n=100
3 Correct 3 ms 11600 KB n=100
4 Correct 3 ms 11600 KB n=100
5 Correct 3 ms 11600 KB n=100
6 Correct 3 ms 11672 KB n=100
7 Correct 3 ms 11600 KB n=100
8 Correct 3 ms 11600 KB n=100
9 Correct 3 ms 11612 KB n=100
10 Correct 3 ms 11600 KB n=100
11 Correct 3 ms 11600 KB n=100
12 Correct 3 ms 11600 KB n=100
13 Correct 4 ms 11616 KB n=100
14 Correct 3 ms 11600 KB n=100
15 Correct 3 ms 11600 KB n=100
16 Correct 3 ms 11600 KB n=100
17 Correct 3 ms 11600 KB n=100
18 Correct 3 ms 11600 KB n=100
19 Correct 3 ms 11600 KB n=100
20 Correct 3 ms 11776 KB n=100
21 Correct 3 ms 11600 KB n=100
22 Correct 3 ms 11768 KB n=100
23 Correct 2 ms 11600 KB n=100
24 Correct 3 ms 11600 KB n=100
25 Correct 3 ms 11768 KB n=100
26 Correct 3 ms 11768 KB n=12
27 Correct 3 ms 11600 KB n=100
28 Correct 4 ms 11856 KB n=500
29 Correct 3 ms 11856 KB n=500
30 Correct 3 ms 11856 KB n=500
31 Correct 4 ms 11856 KB n=500
32 Correct 3 ms 11856 KB n=500
33 Correct 3 ms 11856 KB n=500
34 Correct 3 ms 11856 KB n=500
35 Correct 3 ms 11856 KB n=500
36 Correct 3 ms 11856 KB n=500
37 Correct 3 ms 11856 KB n=500
38 Correct 3 ms 11780 KB n=500
39 Correct 3 ms 11784 KB n=500
40 Correct 3 ms 11856 KB n=500
41 Correct 3 ms 11856 KB n=500
42 Correct 4 ms 11856 KB n=500
43 Correct 3 ms 11856 KB n=500
44 Correct 3 ms 11856 KB n=500
45 Correct 4 ms 12024 KB n=500
46 Correct 3 ms 11856 KB n=500
47 Correct 4 ms 11856 KB n=500
48 Correct 3 ms 11856 KB n=500
49 Correct 4 ms 11856 KB n=500
50 Correct 3 ms 11856 KB n=500
51 Correct 3 ms 11856 KB n=500
52 Correct 4 ms 11780 KB n=500
53 Correct 3 ms 11856 KB n=500
54 Correct 3 ms 11856 KB n=500
55 Correct 3 ms 11600 KB n=278
56 Correct 4 ms 11856 KB n=500
57 Correct 3 ms 11856 KB n=500
58 Correct 5 ms 11876 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11600 KB n=5
2 Correct 3 ms 11600 KB n=100
3 Correct 3 ms 11600 KB n=100
4 Correct 3 ms 11600 KB n=100
5 Correct 3 ms 11600 KB n=100
6 Correct 3 ms 11672 KB n=100
7 Correct 3 ms 11600 KB n=100
8 Correct 3 ms 11600 KB n=100
9 Correct 3 ms 11612 KB n=100
10 Correct 3 ms 11600 KB n=100
11 Correct 3 ms 11600 KB n=100
12 Correct 3 ms 11600 KB n=100
13 Correct 4 ms 11616 KB n=100
14 Correct 3 ms 11600 KB n=100
15 Correct 3 ms 11600 KB n=100
16 Correct 3 ms 11600 KB n=100
17 Correct 3 ms 11600 KB n=100
18 Correct 3 ms 11600 KB n=100
19 Correct 3 ms 11600 KB n=100
20 Correct 3 ms 11776 KB n=100
21 Correct 3 ms 11600 KB n=100
22 Correct 3 ms 11768 KB n=100
23 Correct 2 ms 11600 KB n=100
24 Correct 3 ms 11600 KB n=100
25 Correct 3 ms 11768 KB n=100
26 Correct 3 ms 11768 KB n=12
27 Correct 3 ms 11600 KB n=100
28 Correct 4 ms 11856 KB n=500
29 Correct 3 ms 11856 KB n=500
30 Correct 3 ms 11856 KB n=500
31 Correct 4 ms 11856 KB n=500
32 Correct 3 ms 11856 KB n=500
33 Correct 3 ms 11856 KB n=500
34 Correct 3 ms 11856 KB n=500
35 Correct 3 ms 11856 KB n=500
36 Correct 3 ms 11856 KB n=500
37 Correct 3 ms 11856 KB n=500
38 Correct 3 ms 11780 KB n=500
39 Correct 3 ms 11784 KB n=500
40 Correct 3 ms 11856 KB n=500
41 Correct 3 ms 11856 KB n=500
42 Correct 4 ms 11856 KB n=500
43 Correct 3 ms 11856 KB n=500
44 Correct 3 ms 11856 KB n=500
45 Correct 4 ms 12024 KB n=500
46 Correct 3 ms 11856 KB n=500
47 Correct 4 ms 11856 KB n=500
48 Correct 3 ms 11856 KB n=500
49 Correct 4 ms 11856 KB n=500
50 Correct 3 ms 11856 KB n=500
51 Correct 3 ms 11856 KB n=500
52 Correct 4 ms 11780 KB n=500
53 Correct 3 ms 11856 KB n=500
54 Correct 3 ms 11856 KB n=500
55 Correct 3 ms 11600 KB n=278
56 Correct 4 ms 11856 KB n=500
57 Correct 3 ms 11856 KB n=500
58 Correct 5 ms 11876 KB n=500
59 Correct 5 ms 14160 KB n=2000
60 Correct 6 ms 14160 KB n=2000
61 Correct 10 ms 14160 KB n=2000
62 Correct 9 ms 14160 KB n=2000
63 Correct 5 ms 14160 KB n=2000
64 Correct 8 ms 14160 KB n=2000
65 Correct 5 ms 13904 KB n=2000
66 Correct 8 ms 14160 KB n=2000
67 Correct 4 ms 14160 KB n=2000
68 Correct 12 ms 14160 KB n=2000
69 Correct 7 ms 14160 KB n=2000
70 Correct 7 ms 14160 KB n=2000
71 Correct 6 ms 14160 KB n=2000
72 Correct 5 ms 14160 KB n=2000
73 Correct 5 ms 14160 KB n=2000
74 Correct 5 ms 13904 KB n=1844
75 Correct 5 ms 14160 KB n=2000
76 Correct 11 ms 14320 KB n=2000
77 Correct 9 ms 13904 KB n=2000
78 Correct 15 ms 13920 KB n=2000
79 Correct 4 ms 13904 KB n=2000
80 Correct 8 ms 14160 KB n=2000
81 Correct 8 ms 14088 KB n=2000
82 Correct 5 ms 13904 KB n=2000
83 Correct 7 ms 14336 KB n=2000
84 Correct 6 ms 14160 KB n=2000
85 Correct 10 ms 14324 KB n=2000
86 Correct 7 ms 14160 KB n=2000
87 Correct 6 ms 13904 KB n=2000
88 Correct 10 ms 14160 KB n=2000
89 Correct 10 ms 14088 KB n=2000
90 Correct 8 ms 14160 KB n=2000
91 Correct 9 ms 14160 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11600 KB n=5
2 Correct 3 ms 11600 KB n=100
3 Correct 3 ms 11600 KB n=100
4 Correct 3 ms 11600 KB n=100
5 Correct 3 ms 11600 KB n=100
6 Correct 3 ms 11672 KB n=100
7 Correct 3 ms 11600 KB n=100
8 Correct 3 ms 11600 KB n=100
9 Correct 3 ms 11612 KB n=100
10 Correct 3 ms 11600 KB n=100
11 Correct 3 ms 11600 KB n=100
12 Correct 3 ms 11600 KB n=100
13 Correct 4 ms 11616 KB n=100
14 Correct 3 ms 11600 KB n=100
15 Correct 3 ms 11600 KB n=100
16 Correct 3 ms 11600 KB n=100
17 Correct 3 ms 11600 KB n=100
18 Correct 3 ms 11600 KB n=100
19 Correct 3 ms 11600 KB n=100
20 Correct 3 ms 11776 KB n=100
21 Correct 3 ms 11600 KB n=100
22 Correct 3 ms 11768 KB n=100
23 Correct 2 ms 11600 KB n=100
24 Correct 3 ms 11600 KB n=100
25 Correct 3 ms 11768 KB n=100
26 Correct 3 ms 11768 KB n=12
27 Correct 3 ms 11600 KB n=100
28 Correct 4 ms 11856 KB n=500
29 Correct 3 ms 11856 KB n=500
30 Correct 3 ms 11856 KB n=500
31 Correct 4 ms 11856 KB n=500
32 Correct 3 ms 11856 KB n=500
33 Correct 3 ms 11856 KB n=500
34 Correct 3 ms 11856 KB n=500
35 Correct 3 ms 11856 KB n=500
36 Correct 3 ms 11856 KB n=500
37 Correct 3 ms 11856 KB n=500
38 Correct 3 ms 11780 KB n=500
39 Correct 3 ms 11784 KB n=500
40 Correct 3 ms 11856 KB n=500
41 Correct 3 ms 11856 KB n=500
42 Correct 4 ms 11856 KB n=500
43 Correct 3 ms 11856 KB n=500
44 Correct 3 ms 11856 KB n=500
45 Correct 4 ms 12024 KB n=500
46 Correct 3 ms 11856 KB n=500
47 Correct 4 ms 11856 KB n=500
48 Correct 3 ms 11856 KB n=500
49 Correct 4 ms 11856 KB n=500
50 Correct 3 ms 11856 KB n=500
51 Correct 3 ms 11856 KB n=500
52 Correct 4 ms 11780 KB n=500
53 Correct 3 ms 11856 KB n=500
54 Correct 3 ms 11856 KB n=500
55 Correct 3 ms 11600 KB n=278
56 Correct 4 ms 11856 KB n=500
57 Correct 3 ms 11856 KB n=500
58 Correct 5 ms 11876 KB n=500
59 Correct 5 ms 14160 KB n=2000
60 Correct 6 ms 14160 KB n=2000
61 Correct 10 ms 14160 KB n=2000
62 Correct 9 ms 14160 KB n=2000
63 Correct 5 ms 14160 KB n=2000
64 Correct 8 ms 14160 KB n=2000
65 Correct 5 ms 13904 KB n=2000
66 Correct 8 ms 14160 KB n=2000
67 Correct 4 ms 14160 KB n=2000
68 Correct 12 ms 14160 KB n=2000
69 Correct 7 ms 14160 KB n=2000
70 Correct 7 ms 14160 KB n=2000
71 Correct 6 ms 14160 KB n=2000
72 Correct 5 ms 14160 KB n=2000
73 Correct 5 ms 14160 KB n=2000
74 Correct 5 ms 13904 KB n=1844
75 Correct 5 ms 14160 KB n=2000
76 Correct 11 ms 14320 KB n=2000
77 Correct 9 ms 13904 KB n=2000
78 Correct 15 ms 13920 KB n=2000
79 Correct 4 ms 13904 KB n=2000
80 Correct 8 ms 14160 KB n=2000
81 Correct 8 ms 14088 KB n=2000
82 Correct 5 ms 13904 KB n=2000
83 Correct 7 ms 14336 KB n=2000
84 Correct 6 ms 14160 KB n=2000
85 Correct 10 ms 14324 KB n=2000
86 Correct 7 ms 14160 KB n=2000
87 Correct 6 ms 13904 KB n=2000
88 Correct 10 ms 14160 KB n=2000
89 Correct 10 ms 14088 KB n=2000
90 Correct 8 ms 14160 KB n=2000
91 Correct 9 ms 14160 KB n=2000
92 Correct 192 ms 56772 KB n=200000
93 Execution timed out 4049 ms 56660 KB Time limit exceeded
94 Halted 0 ms 0 KB -