Submission #609017

# Submission time Handle Problem Language Result Execution time Memory
609017 2022-07-27T11:47:59 Z tamthegod Birthday gift (IZhO18_treearray) C++14
100 / 100
1362 ms 200108 KB
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, m, q;
vector<int> adj[maxN];
int f[maxN][21];
int lg[maxN];
int depth[maxN];
int a[maxN];
set<int> s[maxN], s1[maxN];
void Log()
{
    for(int i=2; i<maxN; i++) lg[i] = lg[i / 2] + 1;
}
void predfs(int u, int par)
{
    for(int v : adj[u])
    {
        if(v == par) continue;
        f[v][0] = u;
        depth[v] = depth[u] + 1;
        for(int i=1; i<=lg[n]; i++)
            f[v][i] = f[f[v][i - 1]][i - 1];
        predfs(v, u);
    }
}
int LCA(int u, int v)
{
    if(depth[u] < depth[v]) swap(u, v);
    int k = depth[u] - depth[v];
    for(int i=lg[n]; i>=0; i--)
    {
        if(k & (1 << i))
        {
            u = f[u][i];
            k -= (1 << i);
        }
    }
    if(u == v) return u;
    for(int i=lg[n]; i>=0; i--)
    {
        if(f[u][i] != f[v][i])
        {
            u = f[u][i];
            v = f[v][i];
        }
    }
    return f[u][0];
}
void ReadInput()
{
    cin >> n >> m >> q;
    for(int i=1; i<n; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for(int i=1; i<=m; i++) cin >> a[i];
}
void Solve()
{
    predfs(1, 0);
    for(int i=1; i<=m; i++)
    {
       // cout << LCA(a[i], a[i + 1]) << " ";
        if(i < m) s[LCA(a[i], a[i + 1])].insert(i);
        s1[a[i]].insert(i);
    }
    while(q--)
    {
        int type;
        cin >> type;
        if(type == 1)
        {
            int l, r;
            cin >> l >> r;
            s1[a[l]].erase(l);
            s1[r].insert(l);
            if(l < m)
            {
                s[LCA(a[l], a[l + 1])].erase(l);
                s[LCA(r, a[l + 1])].insert(l);
            }
            if(l > 1)
            {
                s[LCA(a[l - 1], a[l])].erase(l - 1);
                s[LCA(a[l - 1], r)].insert(l - 1);
            }
            a[l] = r;
        }
        else
        {
            int l, r, k;
            cin >> l >> r >> k;
            auto it = s[k].lower_bound(l);
            if(it != s[k].end() && *it < r)
            {
                cout << *it << " " << *it + 1 << '\n';
                assert(*it >= l && *it + 1 <= r);
                continue;
            }
            it = s1[k].lower_bound(l);
            if(it != s1[k].end() && *it <= r)
            {
                cout << *it << " " << *it << '\n';
                assert(*it >= l && *it <= r);
                continue;
            }
            cout << -1 << " " << -1 << '\n';
        }
    }
}
int32_t main()
{
  //  freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    Log();
    ReadInput();
    Solve();
}
# Verdict Execution time Memory Grader output
1 Correct 55 ms 125516 KB n=5
2 Correct 55 ms 125492 KB n=100
3 Correct 61 ms 125596 KB n=100
4 Correct 53 ms 125588 KB n=100
5 Correct 60 ms 125528 KB n=100
6 Correct 65 ms 125724 KB n=100
7 Correct 66 ms 125500 KB n=100
8 Correct 57 ms 125564 KB n=100
9 Correct 54 ms 125504 KB n=100
10 Correct 55 ms 125484 KB n=100
11 Correct 54 ms 125508 KB n=100
12 Correct 59 ms 125592 KB n=100
13 Correct 59 ms 125580 KB n=100
14 Correct 56 ms 125536 KB n=100
15 Correct 56 ms 125644 KB n=100
16 Correct 55 ms 125552 KB n=100
17 Correct 55 ms 125540 KB n=100
18 Correct 62 ms 125516 KB n=100
19 Correct 63 ms 125508 KB n=100
20 Correct 55 ms 125540 KB n=100
21 Correct 56 ms 125560 KB n=100
22 Correct 55 ms 125544 KB n=100
23 Correct 59 ms 125600 KB n=100
24 Correct 63 ms 125600 KB n=100
25 Correct 56 ms 125480 KB n=100
26 Correct 57 ms 125488 KB n=12
27 Correct 57 ms 125596 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 55 ms 125516 KB n=5
2 Correct 55 ms 125492 KB n=100
3 Correct 61 ms 125596 KB n=100
4 Correct 53 ms 125588 KB n=100
5 Correct 60 ms 125528 KB n=100
6 Correct 65 ms 125724 KB n=100
7 Correct 66 ms 125500 KB n=100
8 Correct 57 ms 125564 KB n=100
9 Correct 54 ms 125504 KB n=100
10 Correct 55 ms 125484 KB n=100
11 Correct 54 ms 125508 KB n=100
12 Correct 59 ms 125592 KB n=100
13 Correct 59 ms 125580 KB n=100
14 Correct 56 ms 125536 KB n=100
15 Correct 56 ms 125644 KB n=100
16 Correct 55 ms 125552 KB n=100
17 Correct 55 ms 125540 KB n=100
18 Correct 62 ms 125516 KB n=100
19 Correct 63 ms 125508 KB n=100
20 Correct 55 ms 125540 KB n=100
21 Correct 56 ms 125560 KB n=100
22 Correct 55 ms 125544 KB n=100
23 Correct 59 ms 125600 KB n=100
24 Correct 63 ms 125600 KB n=100
25 Correct 56 ms 125480 KB n=100
26 Correct 57 ms 125488 KB n=12
27 Correct 57 ms 125596 KB n=100
28 Correct 62 ms 125668 KB n=500
29 Correct 59 ms 125752 KB n=500
30 Correct 57 ms 125632 KB n=500
31 Correct 56 ms 125696 KB n=500
32 Correct 55 ms 125676 KB n=500
33 Correct 56 ms 125648 KB n=500
34 Correct 57 ms 125644 KB n=500
35 Correct 57 ms 125756 KB n=500
36 Correct 56 ms 125676 KB n=500
37 Correct 57 ms 125772 KB n=500
38 Correct 56 ms 125652 KB n=500
39 Correct 61 ms 125688 KB n=500
40 Correct 55 ms 125732 KB n=500
41 Correct 59 ms 125708 KB n=500
42 Correct 65 ms 125708 KB n=500
43 Correct 59 ms 125668 KB n=500
44 Correct 56 ms 125656 KB n=500
45 Correct 56 ms 125676 KB n=500
46 Correct 54 ms 125752 KB n=500
47 Correct 68 ms 125644 KB n=500
48 Correct 57 ms 125656 KB n=500
49 Correct 59 ms 125736 KB n=500
50 Correct 56 ms 125728 KB n=500
51 Correct 56 ms 125616 KB n=500
52 Correct 56 ms 125724 KB n=500
53 Correct 54 ms 125684 KB n=500
54 Correct 57 ms 125640 KB n=500
55 Correct 58 ms 125644 KB n=278
56 Correct 59 ms 125664 KB n=500
57 Correct 56 ms 125712 KB n=500
58 Correct 57 ms 125636 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 55 ms 125516 KB n=5
2 Correct 55 ms 125492 KB n=100
3 Correct 61 ms 125596 KB n=100
4 Correct 53 ms 125588 KB n=100
5 Correct 60 ms 125528 KB n=100
6 Correct 65 ms 125724 KB n=100
7 Correct 66 ms 125500 KB n=100
8 Correct 57 ms 125564 KB n=100
9 Correct 54 ms 125504 KB n=100
10 Correct 55 ms 125484 KB n=100
11 Correct 54 ms 125508 KB n=100
12 Correct 59 ms 125592 KB n=100
13 Correct 59 ms 125580 KB n=100
14 Correct 56 ms 125536 KB n=100
15 Correct 56 ms 125644 KB n=100
16 Correct 55 ms 125552 KB n=100
17 Correct 55 ms 125540 KB n=100
18 Correct 62 ms 125516 KB n=100
19 Correct 63 ms 125508 KB n=100
20 Correct 55 ms 125540 KB n=100
21 Correct 56 ms 125560 KB n=100
22 Correct 55 ms 125544 KB n=100
23 Correct 59 ms 125600 KB n=100
24 Correct 63 ms 125600 KB n=100
25 Correct 56 ms 125480 KB n=100
26 Correct 57 ms 125488 KB n=12
27 Correct 57 ms 125596 KB n=100
28 Correct 62 ms 125668 KB n=500
29 Correct 59 ms 125752 KB n=500
30 Correct 57 ms 125632 KB n=500
31 Correct 56 ms 125696 KB n=500
32 Correct 55 ms 125676 KB n=500
33 Correct 56 ms 125648 KB n=500
34 Correct 57 ms 125644 KB n=500
35 Correct 57 ms 125756 KB n=500
36 Correct 56 ms 125676 KB n=500
37 Correct 57 ms 125772 KB n=500
38 Correct 56 ms 125652 KB n=500
39 Correct 61 ms 125688 KB n=500
40 Correct 55 ms 125732 KB n=500
41 Correct 59 ms 125708 KB n=500
42 Correct 65 ms 125708 KB n=500
43 Correct 59 ms 125668 KB n=500
44 Correct 56 ms 125656 KB n=500
45 Correct 56 ms 125676 KB n=500
46 Correct 54 ms 125752 KB n=500
47 Correct 68 ms 125644 KB n=500
48 Correct 57 ms 125656 KB n=500
49 Correct 59 ms 125736 KB n=500
50 Correct 56 ms 125728 KB n=500
51 Correct 56 ms 125616 KB n=500
52 Correct 56 ms 125724 KB n=500
53 Correct 54 ms 125684 KB n=500
54 Correct 57 ms 125640 KB n=500
55 Correct 58 ms 125644 KB n=278
56 Correct 59 ms 125664 KB n=500
57 Correct 56 ms 125712 KB n=500
58 Correct 57 ms 125636 KB n=500
59 Correct 57 ms 126160 KB n=2000
60 Correct 67 ms 126272 KB n=2000
61 Correct 58 ms 126264 KB n=2000
62 Correct 58 ms 126152 KB n=2000
63 Correct 61 ms 126156 KB n=2000
64 Correct 68 ms 126124 KB n=2000
65 Correct 70 ms 126156 KB n=2000
66 Correct 59 ms 126280 KB n=2000
67 Correct 58 ms 126096 KB n=2000
68 Correct 59 ms 126180 KB n=2000
69 Correct 63 ms 126252 KB n=2000
70 Correct 56 ms 126216 KB n=2000
71 Correct 58 ms 126188 KB n=2000
72 Correct 62 ms 126132 KB n=2000
73 Correct 61 ms 126156 KB n=2000
74 Correct 58 ms 126164 KB n=1844
75 Correct 61 ms 126092 KB n=2000
76 Correct 59 ms 126120 KB n=2000
77 Correct 72 ms 126096 KB n=2000
78 Correct 70 ms 126120 KB n=2000
79 Correct 58 ms 126156 KB n=2000
80 Correct 60 ms 126240 KB n=2000
81 Correct 59 ms 126244 KB n=2000
82 Correct 57 ms 126156 KB n=2000
83 Correct 62 ms 126284 KB n=2000
84 Correct 59 ms 126156 KB n=2000
85 Correct 59 ms 126232 KB n=2000
86 Correct 59 ms 126156 KB n=2000
87 Correct 59 ms 126132 KB n=2000
88 Correct 60 ms 126312 KB n=2000
89 Correct 62 ms 126196 KB n=2000
90 Correct 64 ms 126224 KB n=2000
91 Correct 61 ms 126140 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 55 ms 125516 KB n=5
2 Correct 55 ms 125492 KB n=100
3 Correct 61 ms 125596 KB n=100
4 Correct 53 ms 125588 KB n=100
5 Correct 60 ms 125528 KB n=100
6 Correct 65 ms 125724 KB n=100
7 Correct 66 ms 125500 KB n=100
8 Correct 57 ms 125564 KB n=100
9 Correct 54 ms 125504 KB n=100
10 Correct 55 ms 125484 KB n=100
11 Correct 54 ms 125508 KB n=100
12 Correct 59 ms 125592 KB n=100
13 Correct 59 ms 125580 KB n=100
14 Correct 56 ms 125536 KB n=100
15 Correct 56 ms 125644 KB n=100
16 Correct 55 ms 125552 KB n=100
17 Correct 55 ms 125540 KB n=100
18 Correct 62 ms 125516 KB n=100
19 Correct 63 ms 125508 KB n=100
20 Correct 55 ms 125540 KB n=100
21 Correct 56 ms 125560 KB n=100
22 Correct 55 ms 125544 KB n=100
23 Correct 59 ms 125600 KB n=100
24 Correct 63 ms 125600 KB n=100
25 Correct 56 ms 125480 KB n=100
26 Correct 57 ms 125488 KB n=12
27 Correct 57 ms 125596 KB n=100
28 Correct 62 ms 125668 KB n=500
29 Correct 59 ms 125752 KB n=500
30 Correct 57 ms 125632 KB n=500
31 Correct 56 ms 125696 KB n=500
32 Correct 55 ms 125676 KB n=500
33 Correct 56 ms 125648 KB n=500
34 Correct 57 ms 125644 KB n=500
35 Correct 57 ms 125756 KB n=500
36 Correct 56 ms 125676 KB n=500
37 Correct 57 ms 125772 KB n=500
38 Correct 56 ms 125652 KB n=500
39 Correct 61 ms 125688 KB n=500
40 Correct 55 ms 125732 KB n=500
41 Correct 59 ms 125708 KB n=500
42 Correct 65 ms 125708 KB n=500
43 Correct 59 ms 125668 KB n=500
44 Correct 56 ms 125656 KB n=500
45 Correct 56 ms 125676 KB n=500
46 Correct 54 ms 125752 KB n=500
47 Correct 68 ms 125644 KB n=500
48 Correct 57 ms 125656 KB n=500
49 Correct 59 ms 125736 KB n=500
50 Correct 56 ms 125728 KB n=500
51 Correct 56 ms 125616 KB n=500
52 Correct 56 ms 125724 KB n=500
53 Correct 54 ms 125684 KB n=500
54 Correct 57 ms 125640 KB n=500
55 Correct 58 ms 125644 KB n=278
56 Correct 59 ms 125664 KB n=500
57 Correct 56 ms 125712 KB n=500
58 Correct 57 ms 125636 KB n=500
59 Correct 57 ms 126160 KB n=2000
60 Correct 67 ms 126272 KB n=2000
61 Correct 58 ms 126264 KB n=2000
62 Correct 58 ms 126152 KB n=2000
63 Correct 61 ms 126156 KB n=2000
64 Correct 68 ms 126124 KB n=2000
65 Correct 70 ms 126156 KB n=2000
66 Correct 59 ms 126280 KB n=2000
67 Correct 58 ms 126096 KB n=2000
68 Correct 59 ms 126180 KB n=2000
69 Correct 63 ms 126252 KB n=2000
70 Correct 56 ms 126216 KB n=2000
71 Correct 58 ms 126188 KB n=2000
72 Correct 62 ms 126132 KB n=2000
73 Correct 61 ms 126156 KB n=2000
74 Correct 58 ms 126164 KB n=1844
75 Correct 61 ms 126092 KB n=2000
76 Correct 59 ms 126120 KB n=2000
77 Correct 72 ms 126096 KB n=2000
78 Correct 70 ms 126120 KB n=2000
79 Correct 58 ms 126156 KB n=2000
80 Correct 60 ms 126240 KB n=2000
81 Correct 59 ms 126244 KB n=2000
82 Correct 57 ms 126156 KB n=2000
83 Correct 62 ms 126284 KB n=2000
84 Correct 59 ms 126156 KB n=2000
85 Correct 59 ms 126232 KB n=2000
86 Correct 59 ms 126156 KB n=2000
87 Correct 59 ms 126132 KB n=2000
88 Correct 60 ms 126312 KB n=2000
89 Correct 62 ms 126196 KB n=2000
90 Correct 64 ms 126224 KB n=2000
91 Correct 61 ms 126140 KB n=2000
92 Correct 808 ms 189392 KB n=200000
93 Correct 1213 ms 194800 KB n=200000
94 Correct 1244 ms 198764 KB n=200000
95 Correct 958 ms 189216 KB n=200000
96 Correct 1006 ms 189180 KB n=200000
97 Correct 1362 ms 193536 KB n=200000
98 Correct 907 ms 189284 KB n=200000
99 Correct 1118 ms 188796 KB n=200000
100 Correct 833 ms 189320 KB n=200000
101 Correct 1070 ms 200080 KB n=200000
102 Correct 477 ms 190396 KB n=200000
103 Correct 473 ms 190576 KB n=200000
104 Correct 490 ms 190444 KB n=200000
105 Correct 485 ms 190316 KB n=200000
106 Correct 524 ms 190152 KB n=200000
107 Correct 487 ms 190152 KB n=200000
108 Correct 871 ms 189212 KB n=200000
109 Correct 1012 ms 189160 KB n=200000
110 Correct 927 ms 189216 KB n=200000
111 Correct 902 ms 189108 KB n=200000
112 Correct 1160 ms 199060 KB n=200000
113 Correct 1167 ms 193552 KB n=200000
114 Correct 935 ms 189224 KB n=200000
115 Correct 1305 ms 190680 KB n=200000
116 Correct 747 ms 189044 KB n=200000
117 Correct 1201 ms 199324 KB n=200000
118 Correct 1207 ms 191984 KB n=200000
119 Correct 767 ms 188924 KB n=200000
120 Correct 1178 ms 199856 KB n=200000
121 Correct 1020 ms 199828 KB n=200000
122 Correct 1008 ms 200108 KB n=200000
123 Correct 523 ms 189772 KB n=200000
124 Correct 277 ms 141496 KB n=25264