Submission #609010

# Submission time Handle Problem Language Result Execution time Memory
609010 2022-07-27T11:44:52 Z tamthegod Birthday gift (IZhO18_treearray) C++14
56 / 100
1364 ms 200112 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]) << " ";
        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 < n)
            {
                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 = s1[k].lower_bound(l);
            if(it != s1[k].end() && *it <= r)
            {
                cout << *it << " " << *it << '\n';
                assert(*it >= l && *it <= r);
                continue;
            }
            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;
            }
            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 56 ms 125552 KB n=5
2 Correct 56 ms 125596 KB n=100
3 Correct 57 ms 125620 KB n=100
4 Correct 56 ms 125556 KB n=100
5 Correct 54 ms 125600 KB n=100
6 Correct 58 ms 125556 KB n=100
7 Correct 54 ms 125588 KB n=100
8 Correct 55 ms 125604 KB n=100
9 Correct 56 ms 125480 KB n=100
10 Correct 56 ms 125564 KB n=100
11 Correct 59 ms 125584 KB n=100
12 Correct 56 ms 125576 KB n=100
13 Correct 61 ms 125592 KB n=100
14 Correct 64 ms 125588 KB n=100
15 Correct 55 ms 125600 KB n=100
16 Correct 55 ms 125484 KB n=100
17 Correct 56 ms 125568 KB n=100
18 Correct 55 ms 125596 KB n=100
19 Correct 56 ms 125556 KB n=100
20 Correct 66 ms 125516 KB n=100
21 Correct 63 ms 125604 KB n=100
22 Correct 57 ms 125732 KB n=100
23 Correct 55 ms 125516 KB n=100
24 Correct 56 ms 125512 KB n=100
25 Correct 55 ms 125584 KB n=100
26 Correct 56 ms 125644 KB n=12
27 Correct 58 ms 125492 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 56 ms 125552 KB n=5
2 Correct 56 ms 125596 KB n=100
3 Correct 57 ms 125620 KB n=100
4 Correct 56 ms 125556 KB n=100
5 Correct 54 ms 125600 KB n=100
6 Correct 58 ms 125556 KB n=100
7 Correct 54 ms 125588 KB n=100
8 Correct 55 ms 125604 KB n=100
9 Correct 56 ms 125480 KB n=100
10 Correct 56 ms 125564 KB n=100
11 Correct 59 ms 125584 KB n=100
12 Correct 56 ms 125576 KB n=100
13 Correct 61 ms 125592 KB n=100
14 Correct 64 ms 125588 KB n=100
15 Correct 55 ms 125600 KB n=100
16 Correct 55 ms 125484 KB n=100
17 Correct 56 ms 125568 KB n=100
18 Correct 55 ms 125596 KB n=100
19 Correct 56 ms 125556 KB n=100
20 Correct 66 ms 125516 KB n=100
21 Correct 63 ms 125604 KB n=100
22 Correct 57 ms 125732 KB n=100
23 Correct 55 ms 125516 KB n=100
24 Correct 56 ms 125512 KB n=100
25 Correct 55 ms 125584 KB n=100
26 Correct 56 ms 125644 KB n=12
27 Correct 58 ms 125492 KB n=100
28 Correct 58 ms 125640 KB n=500
29 Correct 58 ms 125740 KB n=500
30 Correct 55 ms 125668 KB n=500
31 Correct 58 ms 125640 KB n=500
32 Correct 59 ms 125708 KB n=500
33 Correct 57 ms 125708 KB n=500
34 Correct 57 ms 125620 KB n=500
35 Correct 59 ms 125644 KB n=500
36 Correct 56 ms 125724 KB n=500
37 Correct 57 ms 125608 KB n=500
38 Correct 56 ms 125644 KB n=500
39 Correct 58 ms 125660 KB n=500
40 Correct 60 ms 125724 KB n=500
41 Correct 59 ms 125712 KB n=500
42 Correct 59 ms 125672 KB n=500
43 Correct 59 ms 125608 KB n=500
44 Correct 56 ms 125648 KB n=500
45 Correct 57 ms 125728 KB n=500
46 Correct 57 ms 125716 KB n=500
47 Correct 57 ms 125644 KB n=500
48 Correct 56 ms 125728 KB n=500
49 Correct 59 ms 125748 KB n=500
50 Correct 56 ms 125612 KB n=500
51 Correct 56 ms 125720 KB n=500
52 Correct 58 ms 125644 KB n=500
53 Correct 61 ms 125636 KB n=500
54 Correct 57 ms 125692 KB n=500
55 Correct 57 ms 125592 KB n=278
56 Correct 55 ms 125640 KB n=500
57 Correct 56 ms 125700 KB n=500
58 Correct 56 ms 125704 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 56 ms 125552 KB n=5
2 Correct 56 ms 125596 KB n=100
3 Correct 57 ms 125620 KB n=100
4 Correct 56 ms 125556 KB n=100
5 Correct 54 ms 125600 KB n=100
6 Correct 58 ms 125556 KB n=100
7 Correct 54 ms 125588 KB n=100
8 Correct 55 ms 125604 KB n=100
9 Correct 56 ms 125480 KB n=100
10 Correct 56 ms 125564 KB n=100
11 Correct 59 ms 125584 KB n=100
12 Correct 56 ms 125576 KB n=100
13 Correct 61 ms 125592 KB n=100
14 Correct 64 ms 125588 KB n=100
15 Correct 55 ms 125600 KB n=100
16 Correct 55 ms 125484 KB n=100
17 Correct 56 ms 125568 KB n=100
18 Correct 55 ms 125596 KB n=100
19 Correct 56 ms 125556 KB n=100
20 Correct 66 ms 125516 KB n=100
21 Correct 63 ms 125604 KB n=100
22 Correct 57 ms 125732 KB n=100
23 Correct 55 ms 125516 KB n=100
24 Correct 56 ms 125512 KB n=100
25 Correct 55 ms 125584 KB n=100
26 Correct 56 ms 125644 KB n=12
27 Correct 58 ms 125492 KB n=100
28 Correct 58 ms 125640 KB n=500
29 Correct 58 ms 125740 KB n=500
30 Correct 55 ms 125668 KB n=500
31 Correct 58 ms 125640 KB n=500
32 Correct 59 ms 125708 KB n=500
33 Correct 57 ms 125708 KB n=500
34 Correct 57 ms 125620 KB n=500
35 Correct 59 ms 125644 KB n=500
36 Correct 56 ms 125724 KB n=500
37 Correct 57 ms 125608 KB n=500
38 Correct 56 ms 125644 KB n=500
39 Correct 58 ms 125660 KB n=500
40 Correct 60 ms 125724 KB n=500
41 Correct 59 ms 125712 KB n=500
42 Correct 59 ms 125672 KB n=500
43 Correct 59 ms 125608 KB n=500
44 Correct 56 ms 125648 KB n=500
45 Correct 57 ms 125728 KB n=500
46 Correct 57 ms 125716 KB n=500
47 Correct 57 ms 125644 KB n=500
48 Correct 56 ms 125728 KB n=500
49 Correct 59 ms 125748 KB n=500
50 Correct 56 ms 125612 KB n=500
51 Correct 56 ms 125720 KB n=500
52 Correct 58 ms 125644 KB n=500
53 Correct 61 ms 125636 KB n=500
54 Correct 57 ms 125692 KB n=500
55 Correct 57 ms 125592 KB n=278
56 Correct 55 ms 125640 KB n=500
57 Correct 56 ms 125700 KB n=500
58 Correct 56 ms 125704 KB n=500
59 Correct 58 ms 126204 KB n=2000
60 Correct 61 ms 126204 KB n=2000
61 Correct 60 ms 126208 KB n=2000
62 Correct 61 ms 126228 KB n=2000
63 Correct 60 ms 126156 KB n=2000
64 Correct 59 ms 126156 KB n=2000
65 Correct 57 ms 126120 KB n=2000
66 Correct 58 ms 126208 KB n=2000
67 Correct 59 ms 126156 KB n=2000
68 Correct 62 ms 126296 KB n=2000
69 Correct 61 ms 126100 KB n=2000
70 Correct 59 ms 126284 KB n=2000
71 Correct 59 ms 126104 KB n=2000
72 Correct 58 ms 126128 KB n=2000
73 Correct 58 ms 126172 KB n=2000
74 Correct 58 ms 126092 KB n=1844
75 Correct 61 ms 126112 KB n=2000
76 Correct 58 ms 126136 KB n=2000
77 Correct 60 ms 126108 KB n=2000
78 Correct 62 ms 126212 KB n=2000
79 Correct 59 ms 126152 KB n=2000
80 Correct 61 ms 126188 KB n=2000
81 Correct 60 ms 126240 KB n=2000
82 Correct 61 ms 126096 KB n=2000
83 Correct 62 ms 126156 KB n=2000
84 Correct 60 ms 126144 KB n=2000
85 Correct 60 ms 126164 KB n=2000
86 Correct 62 ms 126224 KB n=2000
87 Correct 62 ms 126136 KB n=2000
88 Correct 62 ms 126240 KB n=2000
89 Correct 73 ms 126296 KB n=2000
90 Correct 59 ms 126256 KB n=2000
91 Correct 72 ms 126212 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 56 ms 125552 KB n=5
2 Correct 56 ms 125596 KB n=100
3 Correct 57 ms 125620 KB n=100
4 Correct 56 ms 125556 KB n=100
5 Correct 54 ms 125600 KB n=100
6 Correct 58 ms 125556 KB n=100
7 Correct 54 ms 125588 KB n=100
8 Correct 55 ms 125604 KB n=100
9 Correct 56 ms 125480 KB n=100
10 Correct 56 ms 125564 KB n=100
11 Correct 59 ms 125584 KB n=100
12 Correct 56 ms 125576 KB n=100
13 Correct 61 ms 125592 KB n=100
14 Correct 64 ms 125588 KB n=100
15 Correct 55 ms 125600 KB n=100
16 Correct 55 ms 125484 KB n=100
17 Correct 56 ms 125568 KB n=100
18 Correct 55 ms 125596 KB n=100
19 Correct 56 ms 125556 KB n=100
20 Correct 66 ms 125516 KB n=100
21 Correct 63 ms 125604 KB n=100
22 Correct 57 ms 125732 KB n=100
23 Correct 55 ms 125516 KB n=100
24 Correct 56 ms 125512 KB n=100
25 Correct 55 ms 125584 KB n=100
26 Correct 56 ms 125644 KB n=12
27 Correct 58 ms 125492 KB n=100
28 Correct 58 ms 125640 KB n=500
29 Correct 58 ms 125740 KB n=500
30 Correct 55 ms 125668 KB n=500
31 Correct 58 ms 125640 KB n=500
32 Correct 59 ms 125708 KB n=500
33 Correct 57 ms 125708 KB n=500
34 Correct 57 ms 125620 KB n=500
35 Correct 59 ms 125644 KB n=500
36 Correct 56 ms 125724 KB n=500
37 Correct 57 ms 125608 KB n=500
38 Correct 56 ms 125644 KB n=500
39 Correct 58 ms 125660 KB n=500
40 Correct 60 ms 125724 KB n=500
41 Correct 59 ms 125712 KB n=500
42 Correct 59 ms 125672 KB n=500
43 Correct 59 ms 125608 KB n=500
44 Correct 56 ms 125648 KB n=500
45 Correct 57 ms 125728 KB n=500
46 Correct 57 ms 125716 KB n=500
47 Correct 57 ms 125644 KB n=500
48 Correct 56 ms 125728 KB n=500
49 Correct 59 ms 125748 KB n=500
50 Correct 56 ms 125612 KB n=500
51 Correct 56 ms 125720 KB n=500
52 Correct 58 ms 125644 KB n=500
53 Correct 61 ms 125636 KB n=500
54 Correct 57 ms 125692 KB n=500
55 Correct 57 ms 125592 KB n=278
56 Correct 55 ms 125640 KB n=500
57 Correct 56 ms 125700 KB n=500
58 Correct 56 ms 125704 KB n=500
59 Correct 58 ms 126204 KB n=2000
60 Correct 61 ms 126204 KB n=2000
61 Correct 60 ms 126208 KB n=2000
62 Correct 61 ms 126228 KB n=2000
63 Correct 60 ms 126156 KB n=2000
64 Correct 59 ms 126156 KB n=2000
65 Correct 57 ms 126120 KB n=2000
66 Correct 58 ms 126208 KB n=2000
67 Correct 59 ms 126156 KB n=2000
68 Correct 62 ms 126296 KB n=2000
69 Correct 61 ms 126100 KB n=2000
70 Correct 59 ms 126284 KB n=2000
71 Correct 59 ms 126104 KB n=2000
72 Correct 58 ms 126128 KB n=2000
73 Correct 58 ms 126172 KB n=2000
74 Correct 58 ms 126092 KB n=1844
75 Correct 61 ms 126112 KB n=2000
76 Correct 58 ms 126136 KB n=2000
77 Correct 60 ms 126108 KB n=2000
78 Correct 62 ms 126212 KB n=2000
79 Correct 59 ms 126152 KB n=2000
80 Correct 61 ms 126188 KB n=2000
81 Correct 60 ms 126240 KB n=2000
82 Correct 61 ms 126096 KB n=2000
83 Correct 62 ms 126156 KB n=2000
84 Correct 60 ms 126144 KB n=2000
85 Correct 60 ms 126164 KB n=2000
86 Correct 62 ms 126224 KB n=2000
87 Correct 62 ms 126136 KB n=2000
88 Correct 62 ms 126240 KB n=2000
89 Correct 73 ms 126296 KB n=2000
90 Correct 59 ms 126256 KB n=2000
91 Correct 72 ms 126212 KB n=2000
92 Correct 797 ms 189444 KB n=200000
93 Correct 1174 ms 194632 KB n=200000
94 Correct 1083 ms 198760 KB n=200000
95 Correct 741 ms 189196 KB n=200000
96 Correct 784 ms 189320 KB n=200000
97 Correct 1364 ms 193548 KB n=200000
98 Correct 795 ms 189240 KB n=200000
99 Correct 1161 ms 188980 KB n=200000
100 Correct 771 ms 189392 KB n=200000
101 Correct 1107 ms 200040 KB n=200000
102 Correct 497 ms 190648 KB n=200000
103 Correct 488 ms 190604 KB n=200000
104 Correct 475 ms 190532 KB n=200000
105 Correct 510 ms 190212 KB n=200000
106 Correct 458 ms 190112 KB n=200000
107 Correct 471 ms 190188 KB n=200000
108 Correct 886 ms 189116 KB n=200000
109 Correct 951 ms 189300 KB n=200000
110 Correct 1050 ms 189136 KB n=200000
111 Correct 780 ms 189200 KB n=200000
112 Correct 1075 ms 199028 KB n=200000
113 Correct 1132 ms 193588 KB n=200000
114 Correct 768 ms 189188 KB n=200000
115 Correct 1207 ms 190872 KB n=200000
116 Correct 692 ms 188980 KB n=200000
117 Correct 1055 ms 199364 KB n=200000
118 Correct 1188 ms 192080 KB n=200000
119 Correct 732 ms 189000 KB n=200000
120 Correct 1016 ms 199748 KB n=200000
121 Correct 1129 ms 199748 KB n=200000
122 Correct 1016 ms 200112 KB n=200000
123 Correct 514 ms 189932 KB n=200000
124 Incorrect 252 ms 141680 KB Wrong range.
125 Halted 0 ms 0 KB -