Submission #544654

# Submission time Handle Problem Language Result Execution time Memory
544654 2022-04-02T14:14:45 Z pokmui9909 None (KOI16_tree) C++17
100 / 100
212 ms 25548 KB
#include <bits/stdc++.h>
using namespace std;
 
int N, Q;
int cnt = 0;
vector<int> T[200005];
int in[200005];
int out[200005];
int seg[800005];
 
void update(int node, int s, int e, int l, int r, int v)
{
    if(l <= s && e <= r) {seg[node] = max(seg[node], v); return;}
    else if(s > r || e < l) return;
    update(node * 2, s, (s + e) / 2, l, r, v);
    update(node * 2 + 1, (s + e) / 2 + 1, e, l, r, v);
}
 
int query(int node, int s, int e, int k)
{
    if(s == e) return seg[node];
    int m = (s + e) / 2;
    if(k <= m) return max(seg[node], query(node * 2, s, m, k));
    else return max(seg[node], query(node * 2 + 1, m + 1, e, k));
}
 
void dfs(int n)
{
    in[n] = ++cnt;
    for(auto i : T[n]) dfs(i);
    out[n] = cnt;
}
 
int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
 
    cin >> N >> Q;
    for(int i = 2; i <= N; i++)
    {
        int u; cin >> u;
        T[u].push_back(i);
    }
    dfs(1);
    while(Q--)
    {
        int x, y, op; cin >> x >> y >> op;
        if(op == 0) cout << (query(1, 1, N, in[x]) == query(1, 1, N, in[y]) ? "YES" : "NO") << '\n';
        else
        {
            if(query(1, 1, N, in[x]) == query(1, 1, N, in[y])) cout << "YES\n";
            else{cout << "NO\n"; swap(x, y);}
            update(1, 1, N, in[x], out[x], in[x]);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5040 KB Output is correct
2 Correct 3 ms 5032 KB Output is correct
3 Correct 4 ms 5052 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5044 KB Output is correct
10 Correct 4 ms 5040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5040 KB Output is correct
2 Correct 3 ms 5032 KB Output is correct
3 Correct 4 ms 5052 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5044 KB Output is correct
10 Correct 4 ms 5040 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 4 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5040 KB Output is correct
2 Correct 3 ms 5032 KB Output is correct
3 Correct 4 ms 5052 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5044 KB Output is correct
10 Correct 4 ms 5040 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 4 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5040 KB Output is correct
22 Correct 96 ms 7928 KB Output is correct
23 Correct 96 ms 7908 KB Output is correct
24 Correct 98 ms 7916 KB Output is correct
25 Correct 97 ms 7828 KB Output is correct
26 Correct 100 ms 7824 KB Output is correct
27 Correct 98 ms 8012 KB Output is correct
28 Correct 95 ms 7960 KB Output is correct
29 Correct 94 ms 7980 KB Output is correct
30 Correct 86 ms 8104 KB Output is correct
31 Correct 91 ms 8060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5040 KB Output is correct
2 Correct 3 ms 5032 KB Output is correct
3 Correct 4 ms 5052 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5044 KB Output is correct
10 Correct 4 ms 5040 KB Output is correct
11 Correct 206 ms 24964 KB Output is correct
12 Correct 212 ms 24888 KB Output is correct
13 Correct 194 ms 24864 KB Output is correct
14 Correct 197 ms 25012 KB Output is correct
15 Correct 194 ms 24884 KB Output is correct
16 Correct 198 ms 25016 KB Output is correct
17 Correct 185 ms 25412 KB Output is correct
18 Correct 193 ms 25304 KB Output is correct
19 Correct 182 ms 25548 KB Output is correct
20 Correct 178 ms 25392 KB Output is correct
21 Correct 190 ms 24976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5040 KB Output is correct
2 Correct 3 ms 5032 KB Output is correct
3 Correct 4 ms 5052 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 4 ms 5076 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 4 ms 5076 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5044 KB Output is correct
10 Correct 4 ms 5040 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 3 ms 5076 KB Output is correct
13 Correct 4 ms 5076 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 4 ms 5076 KB Output is correct
16 Correct 3 ms 5076 KB Output is correct
17 Correct 3 ms 5076 KB Output is correct
18 Correct 4 ms 5076 KB Output is correct
19 Correct 4 ms 5076 KB Output is correct
20 Correct 3 ms 5076 KB Output is correct
21 Correct 3 ms 5040 KB Output is correct
22 Correct 96 ms 7928 KB Output is correct
23 Correct 96 ms 7908 KB Output is correct
24 Correct 98 ms 7916 KB Output is correct
25 Correct 97 ms 7828 KB Output is correct
26 Correct 100 ms 7824 KB Output is correct
27 Correct 98 ms 8012 KB Output is correct
28 Correct 95 ms 7960 KB Output is correct
29 Correct 94 ms 7980 KB Output is correct
30 Correct 86 ms 8104 KB Output is correct
31 Correct 91 ms 8060 KB Output is correct
32 Correct 206 ms 24964 KB Output is correct
33 Correct 212 ms 24888 KB Output is correct
34 Correct 194 ms 24864 KB Output is correct
35 Correct 197 ms 25012 KB Output is correct
36 Correct 194 ms 24884 KB Output is correct
37 Correct 198 ms 25016 KB Output is correct
38 Correct 185 ms 25412 KB Output is correct
39 Correct 193 ms 25304 KB Output is correct
40 Correct 182 ms 25548 KB Output is correct
41 Correct 178 ms 25392 KB Output is correct
42 Correct 190 ms 24976 KB Output is correct
43 Correct 172 ms 14844 KB Output is correct
44 Correct 159 ms 14872 KB Output is correct
45 Correct 166 ms 14928 KB Output is correct
46 Correct 170 ms 14996 KB Output is correct
47 Correct 159 ms 14856 KB Output is correct
48 Correct 133 ms 12280 KB Output is correct
49 Correct 129 ms 12856 KB Output is correct
50 Correct 127 ms 12672 KB Output is correct
51 Correct 190 ms 21056 KB Output is correct