Submission #608986

# Submission time Handle Problem Language Result Execution time Memory
608986 2022-07-27T11:37:11 Z tamthegod Birthday gift (IZhO18_treearray) C++14
56 / 100
1330 ms 207744 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 st[4 * 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);
    }
  //  cout << q;return;
    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';
                continue;
            }
            it = s[k].lower_bound(l);
            if(it != s[k].end() && *it < r)
            {
                cout << *it << " " << *it + 1 << '\n';
                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 65 ms 125516 KB n=5
2 Correct 59 ms 125524 KB n=100
3 Correct 62 ms 125572 KB n=100
4 Correct 62 ms 125608 KB n=100
5 Correct 64 ms 125576 KB n=100
6 Correct 59 ms 125604 KB n=100
7 Correct 68 ms 125492 KB n=100
8 Correct 64 ms 125556 KB n=100
9 Correct 68 ms 125508 KB n=100
10 Correct 67 ms 125612 KB n=100
11 Correct 61 ms 125564 KB n=100
12 Correct 63 ms 125608 KB n=100
13 Correct 59 ms 125596 KB n=100
14 Correct 59 ms 125596 KB n=100
15 Correct 62 ms 125604 KB n=100
16 Correct 92 ms 125516 KB n=100
17 Correct 65 ms 125596 KB n=100
18 Correct 61 ms 125536 KB n=100
19 Correct 60 ms 125560 KB n=100
20 Correct 72 ms 125576 KB n=100
21 Correct 65 ms 125592 KB n=100
22 Correct 66 ms 125696 KB n=100
23 Correct 71 ms 125560 KB n=100
24 Correct 68 ms 125584 KB n=100
25 Correct 65 ms 125516 KB n=100
26 Correct 56 ms 125548 KB n=12
27 Correct 61 ms 125604 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 65 ms 125516 KB n=5
2 Correct 59 ms 125524 KB n=100
3 Correct 62 ms 125572 KB n=100
4 Correct 62 ms 125608 KB n=100
5 Correct 64 ms 125576 KB n=100
6 Correct 59 ms 125604 KB n=100
7 Correct 68 ms 125492 KB n=100
8 Correct 64 ms 125556 KB n=100
9 Correct 68 ms 125508 KB n=100
10 Correct 67 ms 125612 KB n=100
11 Correct 61 ms 125564 KB n=100
12 Correct 63 ms 125608 KB n=100
13 Correct 59 ms 125596 KB n=100
14 Correct 59 ms 125596 KB n=100
15 Correct 62 ms 125604 KB n=100
16 Correct 92 ms 125516 KB n=100
17 Correct 65 ms 125596 KB n=100
18 Correct 61 ms 125536 KB n=100
19 Correct 60 ms 125560 KB n=100
20 Correct 72 ms 125576 KB n=100
21 Correct 65 ms 125592 KB n=100
22 Correct 66 ms 125696 KB n=100
23 Correct 71 ms 125560 KB n=100
24 Correct 68 ms 125584 KB n=100
25 Correct 65 ms 125516 KB n=100
26 Correct 56 ms 125548 KB n=12
27 Correct 61 ms 125604 KB n=100
28 Correct 57 ms 125672 KB n=500
29 Correct 68 ms 125768 KB n=500
30 Correct 57 ms 125756 KB n=500
31 Correct 58 ms 125724 KB n=500
32 Correct 64 ms 125692 KB n=500
33 Correct 67 ms 125724 KB n=500
34 Correct 108 ms 125644 KB n=500
35 Correct 73 ms 125720 KB n=500
36 Correct 74 ms 125728 KB n=500
37 Correct 74 ms 125644 KB n=500
38 Correct 93 ms 125744 KB n=500
39 Correct 81 ms 125704 KB n=500
40 Correct 76 ms 125744 KB n=500
41 Correct 77 ms 125772 KB n=500
42 Correct 72 ms 125740 KB n=500
43 Correct 75 ms 125664 KB n=500
44 Correct 56 ms 125688 KB n=500
45 Correct 60 ms 125692 KB n=500
46 Correct 56 ms 125772 KB n=500
47 Correct 61 ms 125664 KB n=500
48 Correct 57 ms 125748 KB n=500
49 Correct 56 ms 125712 KB n=500
50 Correct 72 ms 125704 KB n=500
51 Correct 63 ms 125640 KB n=500
52 Correct 61 ms 125656 KB n=500
53 Correct 56 ms 125692 KB n=500
54 Correct 62 ms 125768 KB n=500
55 Correct 60 ms 125656 KB n=278
56 Correct 63 ms 125788 KB n=500
57 Correct 56 ms 125736 KB n=500
58 Correct 62 ms 125656 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 65 ms 125516 KB n=5
2 Correct 59 ms 125524 KB n=100
3 Correct 62 ms 125572 KB n=100
4 Correct 62 ms 125608 KB n=100
5 Correct 64 ms 125576 KB n=100
6 Correct 59 ms 125604 KB n=100
7 Correct 68 ms 125492 KB n=100
8 Correct 64 ms 125556 KB n=100
9 Correct 68 ms 125508 KB n=100
10 Correct 67 ms 125612 KB n=100
11 Correct 61 ms 125564 KB n=100
12 Correct 63 ms 125608 KB n=100
13 Correct 59 ms 125596 KB n=100
14 Correct 59 ms 125596 KB n=100
15 Correct 62 ms 125604 KB n=100
16 Correct 92 ms 125516 KB n=100
17 Correct 65 ms 125596 KB n=100
18 Correct 61 ms 125536 KB n=100
19 Correct 60 ms 125560 KB n=100
20 Correct 72 ms 125576 KB n=100
21 Correct 65 ms 125592 KB n=100
22 Correct 66 ms 125696 KB n=100
23 Correct 71 ms 125560 KB n=100
24 Correct 68 ms 125584 KB n=100
25 Correct 65 ms 125516 KB n=100
26 Correct 56 ms 125548 KB n=12
27 Correct 61 ms 125604 KB n=100
28 Correct 57 ms 125672 KB n=500
29 Correct 68 ms 125768 KB n=500
30 Correct 57 ms 125756 KB n=500
31 Correct 58 ms 125724 KB n=500
32 Correct 64 ms 125692 KB n=500
33 Correct 67 ms 125724 KB n=500
34 Correct 108 ms 125644 KB n=500
35 Correct 73 ms 125720 KB n=500
36 Correct 74 ms 125728 KB n=500
37 Correct 74 ms 125644 KB n=500
38 Correct 93 ms 125744 KB n=500
39 Correct 81 ms 125704 KB n=500
40 Correct 76 ms 125744 KB n=500
41 Correct 77 ms 125772 KB n=500
42 Correct 72 ms 125740 KB n=500
43 Correct 75 ms 125664 KB n=500
44 Correct 56 ms 125688 KB n=500
45 Correct 60 ms 125692 KB n=500
46 Correct 56 ms 125772 KB n=500
47 Correct 61 ms 125664 KB n=500
48 Correct 57 ms 125748 KB n=500
49 Correct 56 ms 125712 KB n=500
50 Correct 72 ms 125704 KB n=500
51 Correct 63 ms 125640 KB n=500
52 Correct 61 ms 125656 KB n=500
53 Correct 56 ms 125692 KB n=500
54 Correct 62 ms 125768 KB n=500
55 Correct 60 ms 125656 KB n=278
56 Correct 63 ms 125788 KB n=500
57 Correct 56 ms 125736 KB n=500
58 Correct 62 ms 125656 KB n=500
59 Correct 75 ms 126224 KB n=2000
60 Correct 63 ms 126364 KB n=2000
61 Correct 98 ms 126268 KB n=2000
62 Correct 63 ms 126172 KB n=2000
63 Correct 57 ms 126164 KB n=2000
64 Correct 62 ms 126196 KB n=2000
65 Correct 80 ms 126180 KB n=2000
66 Correct 66 ms 126328 KB n=2000
67 Correct 59 ms 126156 KB n=2000
68 Correct 68 ms 126256 KB n=2000
69 Correct 62 ms 126272 KB n=2000
70 Correct 59 ms 126224 KB n=2000
71 Correct 78 ms 126236 KB n=2000
72 Correct 62 ms 126156 KB n=2000
73 Correct 59 ms 126248 KB n=2000
74 Correct 57 ms 126224 KB n=1844
75 Correct 60 ms 126264 KB n=2000
76 Correct 66 ms 126192 KB n=2000
77 Correct 66 ms 126180 KB n=2000
78 Correct 70 ms 126208 KB n=2000
79 Correct 58 ms 126140 KB n=2000
80 Correct 56 ms 126292 KB n=2000
81 Correct 60 ms 126280 KB n=2000
82 Correct 61 ms 126172 KB n=2000
83 Correct 67 ms 126332 KB n=2000
84 Correct 64 ms 126240 KB n=2000
85 Correct 81 ms 126236 KB n=2000
86 Correct 186 ms 126284 KB n=2000
87 Correct 63 ms 126216 KB n=2000
88 Correct 65 ms 126296 KB n=2000
89 Correct 71 ms 126436 KB n=2000
90 Correct 64 ms 126344 KB n=2000
91 Correct 63 ms 126152 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 65 ms 125516 KB n=5
2 Correct 59 ms 125524 KB n=100
3 Correct 62 ms 125572 KB n=100
4 Correct 62 ms 125608 KB n=100
5 Correct 64 ms 125576 KB n=100
6 Correct 59 ms 125604 KB n=100
7 Correct 68 ms 125492 KB n=100
8 Correct 64 ms 125556 KB n=100
9 Correct 68 ms 125508 KB n=100
10 Correct 67 ms 125612 KB n=100
11 Correct 61 ms 125564 KB n=100
12 Correct 63 ms 125608 KB n=100
13 Correct 59 ms 125596 KB n=100
14 Correct 59 ms 125596 KB n=100
15 Correct 62 ms 125604 KB n=100
16 Correct 92 ms 125516 KB n=100
17 Correct 65 ms 125596 KB n=100
18 Correct 61 ms 125536 KB n=100
19 Correct 60 ms 125560 KB n=100
20 Correct 72 ms 125576 KB n=100
21 Correct 65 ms 125592 KB n=100
22 Correct 66 ms 125696 KB n=100
23 Correct 71 ms 125560 KB n=100
24 Correct 68 ms 125584 KB n=100
25 Correct 65 ms 125516 KB n=100
26 Correct 56 ms 125548 KB n=12
27 Correct 61 ms 125604 KB n=100
28 Correct 57 ms 125672 KB n=500
29 Correct 68 ms 125768 KB n=500
30 Correct 57 ms 125756 KB n=500
31 Correct 58 ms 125724 KB n=500
32 Correct 64 ms 125692 KB n=500
33 Correct 67 ms 125724 KB n=500
34 Correct 108 ms 125644 KB n=500
35 Correct 73 ms 125720 KB n=500
36 Correct 74 ms 125728 KB n=500
37 Correct 74 ms 125644 KB n=500
38 Correct 93 ms 125744 KB n=500
39 Correct 81 ms 125704 KB n=500
40 Correct 76 ms 125744 KB n=500
41 Correct 77 ms 125772 KB n=500
42 Correct 72 ms 125740 KB n=500
43 Correct 75 ms 125664 KB n=500
44 Correct 56 ms 125688 KB n=500
45 Correct 60 ms 125692 KB n=500
46 Correct 56 ms 125772 KB n=500
47 Correct 61 ms 125664 KB n=500
48 Correct 57 ms 125748 KB n=500
49 Correct 56 ms 125712 KB n=500
50 Correct 72 ms 125704 KB n=500
51 Correct 63 ms 125640 KB n=500
52 Correct 61 ms 125656 KB n=500
53 Correct 56 ms 125692 KB n=500
54 Correct 62 ms 125768 KB n=500
55 Correct 60 ms 125656 KB n=278
56 Correct 63 ms 125788 KB n=500
57 Correct 56 ms 125736 KB n=500
58 Correct 62 ms 125656 KB n=500
59 Correct 75 ms 126224 KB n=2000
60 Correct 63 ms 126364 KB n=2000
61 Correct 98 ms 126268 KB n=2000
62 Correct 63 ms 126172 KB n=2000
63 Correct 57 ms 126164 KB n=2000
64 Correct 62 ms 126196 KB n=2000
65 Correct 80 ms 126180 KB n=2000
66 Correct 66 ms 126328 KB n=2000
67 Correct 59 ms 126156 KB n=2000
68 Correct 68 ms 126256 KB n=2000
69 Correct 62 ms 126272 KB n=2000
70 Correct 59 ms 126224 KB n=2000
71 Correct 78 ms 126236 KB n=2000
72 Correct 62 ms 126156 KB n=2000
73 Correct 59 ms 126248 KB n=2000
74 Correct 57 ms 126224 KB n=1844
75 Correct 60 ms 126264 KB n=2000
76 Correct 66 ms 126192 KB n=2000
77 Correct 66 ms 126180 KB n=2000
78 Correct 70 ms 126208 KB n=2000
79 Correct 58 ms 126140 KB n=2000
80 Correct 56 ms 126292 KB n=2000
81 Correct 60 ms 126280 KB n=2000
82 Correct 61 ms 126172 KB n=2000
83 Correct 67 ms 126332 KB n=2000
84 Correct 64 ms 126240 KB n=2000
85 Correct 81 ms 126236 KB n=2000
86 Correct 186 ms 126284 KB n=2000
87 Correct 63 ms 126216 KB n=2000
88 Correct 65 ms 126296 KB n=2000
89 Correct 71 ms 126436 KB n=2000
90 Correct 64 ms 126344 KB n=2000
91 Correct 63 ms 126152 KB n=2000
92 Correct 1072 ms 190280 KB n=200000
93 Correct 1260 ms 202380 KB n=200000
94 Correct 1150 ms 206376 KB n=200000
95 Correct 785 ms 195600 KB n=200000
96 Correct 776 ms 195748 KB n=200000
97 Correct 1246 ms 201340 KB n=200000
98 Correct 1130 ms 195692 KB n=200000
99 Correct 1053 ms 196172 KB n=200000
100 Correct 795 ms 195752 KB n=200000
101 Correct 1263 ms 207744 KB n=200000
102 Correct 516 ms 197256 KB n=200000
103 Correct 480 ms 197068 KB n=200000
104 Correct 529 ms 197048 KB n=200000
105 Correct 502 ms 197496 KB n=200000
106 Correct 508 ms 197464 KB n=200000
107 Correct 565 ms 197420 KB n=200000
108 Correct 1032 ms 196032 KB n=200000
109 Correct 950 ms 196032 KB n=200000
110 Correct 988 ms 196008 KB n=200000
111 Correct 953 ms 195168 KB n=200000
112 Correct 1191 ms 206968 KB n=200000
113 Correct 1330 ms 201256 KB n=200000
114 Correct 760 ms 195276 KB n=200000
115 Correct 1217 ms 198456 KB n=200000
116 Correct 713 ms 195904 KB n=200000
117 Correct 1069 ms 207192 KB n=200000
118 Correct 1208 ms 199720 KB n=200000
119 Correct 753 ms 195860 KB n=200000
120 Correct 1051 ms 206772 KB n=200000
121 Correct 1059 ms 206708 KB n=200000
122 Correct 1024 ms 206976 KB n=200000
123 Correct 515 ms 197324 KB n=200000
124 Incorrect 259 ms 143504 KB Wrong range.
125 Halted 0 ms 0 KB -