Submission #412090

# Submission time Handle Problem Language Result Execution time Memory
412090 2021-05-26T13:48:30 Z arayi Birthday gift (IZhO18_treearray) C++17
100 / 100
1177 ms 181776 KB
//Arayi
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#include <chrono>
#include <random>
#include <complex>

#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int>
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;

lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x, ld y1, ld x2, ld y2)
{
    return sqrt((x - x2) * (x - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
    return (a * (a + 1LL)) / 2;
}
mt19937 rnd(363542);
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 0, -1, 0, 1, -1, -1, 1, 1, 0 };
int dy[] = { -1, 0, 1, 0, -1, 1, -1, 1, 0 };


const int N = 1e6 + 30;
lli mod = 1e17;
const ld pi = acos(-1);
const int T = 550;

lli bp(lli a, lli b = mod - 2LL)
{
    lli ret = 1;
    while (b)
    {
        if (b & 1) ret *= a, ret %= mod;
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return ret;
}
ostream& operator<<(ostream& c, pir a)
{
    c << a.fr << " " << a.sc;
    return c;
}
template<class T>
void maxi(T& a, T b)
{
    a = max(a, b);
}
template <class T>
void mini(T& a, T b)
{
    a = min(a, b);
}

int n, m, q;
int xr[N], pr[N][20];
vii g[N];
int a[N], b[N];
set<int> fp[N], f[N];
void dfs(int v, int par)
{
    pr[v][0]=par;
    for(auto p : g[v])
    {
        if(p==par) continue;
        xr[p]=xr[v]+1;
        dfs(p,v);
    }
}
int walk(int u, int d)
{
    for (int i = 0; i < 20; i++)
            if((1<<i)&d) u=pr[u][i];
    return u;
}
int lca(int a, int b)
{
    if(xr[a] > xr[b]) swap(a,b);
    b = walk(b, xr[b]-xr[a]);
    if(a == b) return a;
    for(int i = 20 - 1; i >= 0; i--)
        if(pr[a][i] != pr[b][i]) a = pr[a][i], b = pr[b][i];
    return pr[a][0];
}
int main()
{
    fastio;
    cin >> n >> m >> q ;
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        g[a].ad(b);
        g[b].ad(a);
    }
    dfs(1,0);
    for(int j = 1; j < 20; j++)
        for (int i = 1; i <= n; i++)
            pr[i][j]=pr[pr[i][j-1]][j-1];
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
        f[a[i]].insert(i);
        if(i) b[i - 1]=lca(a[i], a[i-1]), fp[b[i - 1]].insert(i - 1);
    }
    while(q--)
    {
        int A;
        cin>>A;
        if(A==1)
        {
            int i1, x;
            cin>>i1>>x;
            i1--;
            f[a[i1]].erase(i1);
            a[i1]=x;
            f[a[i1]].insert(i1);
            if(i1)
            {
                fp[b[i1 - 1]].erase(i1-1);
                b[i1-1]=lca(a[i1-1],a[i1]);
                fp[b[i1-1]].insert(i1-1);
            }
            if(i1 < m - 1)
            {
                fp[b[i1]].erase(i1);
                b[i1]=lca(a[i1], a[i1+1]);
                fp[b[i1]].insert(i1);
            }
        }
        else
        {
            int l, r, x;
            cin>>l>>r>>x;
            l--,r--;
            auto i = f[x].lower_bound(l);
            if(i != f[x].end() && *i <= r)
            {
                cout<<*i+1<<" "<<*i+1<<"\n";
                continue;
            }
            r--;
            auto i1 = fp[x].lower_bound(l);
            if(i1 == fp[x].end() || *i1 > r) cout<<"-1 -1\n";
            else cout<<*i1+1<<" "<<*i1+2<<"\n";
        }
    }
    return 0;
}

/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
    __
  *(><)*
    \/ /
    ||/
  --||
    ||
    /\
   /  \
  /    \

*/
# Verdict Execution time Memory Grader output
1 Correct 61 ms 117668 KB n=5
2 Correct 59 ms 117764 KB n=100
3 Correct 60 ms 117732 KB n=100
4 Correct 59 ms 117656 KB n=100
5 Correct 64 ms 117736 KB n=100
6 Correct 61 ms 117684 KB n=100
7 Correct 67 ms 117700 KB n=100
8 Correct 60 ms 117736 KB n=100
9 Correct 61 ms 117712 KB n=100
10 Correct 64 ms 117656 KB n=100
11 Correct 60 ms 117736 KB n=100
12 Correct 65 ms 117696 KB n=100
13 Correct 63 ms 117772 KB n=100
14 Correct 68 ms 117776 KB n=100
15 Correct 64 ms 117664 KB n=100
16 Correct 62 ms 117684 KB n=100
17 Correct 62 ms 117708 KB n=100
18 Correct 64 ms 117672 KB n=100
19 Correct 64 ms 117708 KB n=100
20 Correct 63 ms 117684 KB n=100
21 Correct 64 ms 117768 KB n=100
22 Correct 61 ms 117700 KB n=100
23 Correct 62 ms 117696 KB n=100
24 Correct 62 ms 117744 KB n=100
25 Correct 63 ms 117748 KB n=100
26 Correct 62 ms 117676 KB n=12
27 Correct 62 ms 117764 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 61 ms 117668 KB n=5
2 Correct 59 ms 117764 KB n=100
3 Correct 60 ms 117732 KB n=100
4 Correct 59 ms 117656 KB n=100
5 Correct 64 ms 117736 KB n=100
6 Correct 61 ms 117684 KB n=100
7 Correct 67 ms 117700 KB n=100
8 Correct 60 ms 117736 KB n=100
9 Correct 61 ms 117712 KB n=100
10 Correct 64 ms 117656 KB n=100
11 Correct 60 ms 117736 KB n=100
12 Correct 65 ms 117696 KB n=100
13 Correct 63 ms 117772 KB n=100
14 Correct 68 ms 117776 KB n=100
15 Correct 64 ms 117664 KB n=100
16 Correct 62 ms 117684 KB n=100
17 Correct 62 ms 117708 KB n=100
18 Correct 64 ms 117672 KB n=100
19 Correct 64 ms 117708 KB n=100
20 Correct 63 ms 117684 KB n=100
21 Correct 64 ms 117768 KB n=100
22 Correct 61 ms 117700 KB n=100
23 Correct 62 ms 117696 KB n=100
24 Correct 62 ms 117744 KB n=100
25 Correct 63 ms 117748 KB n=100
26 Correct 62 ms 117676 KB n=12
27 Correct 62 ms 117764 KB n=100
28 Correct 61 ms 117796 KB n=500
29 Correct 63 ms 117828 KB n=500
30 Correct 62 ms 117824 KB n=500
31 Correct 62 ms 117776 KB n=500
32 Correct 62 ms 117772 KB n=500
33 Correct 61 ms 117876 KB n=500
34 Correct 62 ms 117852 KB n=500
35 Correct 63 ms 117868 KB n=500
36 Correct 62 ms 117828 KB n=500
37 Correct 63 ms 117780 KB n=500
38 Correct 63 ms 117800 KB n=500
39 Correct 62 ms 117828 KB n=500
40 Correct 67 ms 117840 KB n=500
41 Correct 63 ms 117840 KB n=500
42 Correct 70 ms 117872 KB n=500
43 Correct 61 ms 117800 KB n=500
44 Correct 63 ms 117876 KB n=500
45 Correct 61 ms 117852 KB n=500
46 Correct 70 ms 117816 KB n=500
47 Correct 63 ms 117856 KB n=500
48 Correct 63 ms 117852 KB n=500
49 Correct 63 ms 118000 KB n=500
50 Correct 64 ms 117780 KB n=500
51 Correct 63 ms 117820 KB n=500
52 Correct 61 ms 117900 KB n=500
53 Correct 63 ms 117884 KB n=500
54 Correct 63 ms 117896 KB n=500
55 Correct 61 ms 117760 KB n=278
56 Correct 64 ms 117852 KB n=500
57 Correct 63 ms 117872 KB n=500
58 Correct 62 ms 117860 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 61 ms 117668 KB n=5
2 Correct 59 ms 117764 KB n=100
3 Correct 60 ms 117732 KB n=100
4 Correct 59 ms 117656 KB n=100
5 Correct 64 ms 117736 KB n=100
6 Correct 61 ms 117684 KB n=100
7 Correct 67 ms 117700 KB n=100
8 Correct 60 ms 117736 KB n=100
9 Correct 61 ms 117712 KB n=100
10 Correct 64 ms 117656 KB n=100
11 Correct 60 ms 117736 KB n=100
12 Correct 65 ms 117696 KB n=100
13 Correct 63 ms 117772 KB n=100
14 Correct 68 ms 117776 KB n=100
15 Correct 64 ms 117664 KB n=100
16 Correct 62 ms 117684 KB n=100
17 Correct 62 ms 117708 KB n=100
18 Correct 64 ms 117672 KB n=100
19 Correct 64 ms 117708 KB n=100
20 Correct 63 ms 117684 KB n=100
21 Correct 64 ms 117768 KB n=100
22 Correct 61 ms 117700 KB n=100
23 Correct 62 ms 117696 KB n=100
24 Correct 62 ms 117744 KB n=100
25 Correct 63 ms 117748 KB n=100
26 Correct 62 ms 117676 KB n=12
27 Correct 62 ms 117764 KB n=100
28 Correct 61 ms 117796 KB n=500
29 Correct 63 ms 117828 KB n=500
30 Correct 62 ms 117824 KB n=500
31 Correct 62 ms 117776 KB n=500
32 Correct 62 ms 117772 KB n=500
33 Correct 61 ms 117876 KB n=500
34 Correct 62 ms 117852 KB n=500
35 Correct 63 ms 117868 KB n=500
36 Correct 62 ms 117828 KB n=500
37 Correct 63 ms 117780 KB n=500
38 Correct 63 ms 117800 KB n=500
39 Correct 62 ms 117828 KB n=500
40 Correct 67 ms 117840 KB n=500
41 Correct 63 ms 117840 KB n=500
42 Correct 70 ms 117872 KB n=500
43 Correct 61 ms 117800 KB n=500
44 Correct 63 ms 117876 KB n=500
45 Correct 61 ms 117852 KB n=500
46 Correct 70 ms 117816 KB n=500
47 Correct 63 ms 117856 KB n=500
48 Correct 63 ms 117852 KB n=500
49 Correct 63 ms 118000 KB n=500
50 Correct 64 ms 117780 KB n=500
51 Correct 63 ms 117820 KB n=500
52 Correct 61 ms 117900 KB n=500
53 Correct 63 ms 117884 KB n=500
54 Correct 63 ms 117896 KB n=500
55 Correct 61 ms 117760 KB n=278
56 Correct 64 ms 117852 KB n=500
57 Correct 63 ms 117872 KB n=500
58 Correct 62 ms 117860 KB n=500
59 Correct 67 ms 118224 KB n=2000
60 Correct 72 ms 118340 KB n=2000
61 Correct 64 ms 118300 KB n=2000
62 Correct 65 ms 118288 KB n=2000
63 Correct 70 ms 118196 KB n=2000
64 Correct 65 ms 118288 KB n=2000
65 Correct 65 ms 118196 KB n=2000
66 Correct 73 ms 118232 KB n=2000
67 Correct 65 ms 118220 KB n=2000
68 Correct 66 ms 118312 KB n=2000
69 Correct 65 ms 118212 KB n=2000
70 Correct 64 ms 118148 KB n=2000
71 Correct 64 ms 118264 KB n=2000
72 Correct 64 ms 118248 KB n=2000
73 Correct 66 ms 118196 KB n=2000
74 Correct 65 ms 118220 KB n=1844
75 Correct 69 ms 118148 KB n=2000
76 Correct 64 ms 118196 KB n=2000
77 Correct 65 ms 118128 KB n=2000
78 Correct 66 ms 118184 KB n=2000
79 Correct 65 ms 118276 KB n=2000
80 Correct 68 ms 118340 KB n=2000
81 Correct 64 ms 118212 KB n=2000
82 Correct 66 ms 118220 KB n=2000
83 Correct 65 ms 118252 KB n=2000
84 Correct 71 ms 118148 KB n=2000
85 Correct 65 ms 118372 KB n=2000
86 Correct 66 ms 118252 KB n=2000
87 Correct 67 ms 118260 KB n=2000
88 Correct 75 ms 118312 KB n=2000
89 Correct 65 ms 118340 KB n=2000
90 Correct 65 ms 118340 KB n=2000
91 Correct 64 ms 118184 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 61 ms 117668 KB n=5
2 Correct 59 ms 117764 KB n=100
3 Correct 60 ms 117732 KB n=100
4 Correct 59 ms 117656 KB n=100
5 Correct 64 ms 117736 KB n=100
6 Correct 61 ms 117684 KB n=100
7 Correct 67 ms 117700 KB n=100
8 Correct 60 ms 117736 KB n=100
9 Correct 61 ms 117712 KB n=100
10 Correct 64 ms 117656 KB n=100
11 Correct 60 ms 117736 KB n=100
12 Correct 65 ms 117696 KB n=100
13 Correct 63 ms 117772 KB n=100
14 Correct 68 ms 117776 KB n=100
15 Correct 64 ms 117664 KB n=100
16 Correct 62 ms 117684 KB n=100
17 Correct 62 ms 117708 KB n=100
18 Correct 64 ms 117672 KB n=100
19 Correct 64 ms 117708 KB n=100
20 Correct 63 ms 117684 KB n=100
21 Correct 64 ms 117768 KB n=100
22 Correct 61 ms 117700 KB n=100
23 Correct 62 ms 117696 KB n=100
24 Correct 62 ms 117744 KB n=100
25 Correct 63 ms 117748 KB n=100
26 Correct 62 ms 117676 KB n=12
27 Correct 62 ms 117764 KB n=100
28 Correct 61 ms 117796 KB n=500
29 Correct 63 ms 117828 KB n=500
30 Correct 62 ms 117824 KB n=500
31 Correct 62 ms 117776 KB n=500
32 Correct 62 ms 117772 KB n=500
33 Correct 61 ms 117876 KB n=500
34 Correct 62 ms 117852 KB n=500
35 Correct 63 ms 117868 KB n=500
36 Correct 62 ms 117828 KB n=500
37 Correct 63 ms 117780 KB n=500
38 Correct 63 ms 117800 KB n=500
39 Correct 62 ms 117828 KB n=500
40 Correct 67 ms 117840 KB n=500
41 Correct 63 ms 117840 KB n=500
42 Correct 70 ms 117872 KB n=500
43 Correct 61 ms 117800 KB n=500
44 Correct 63 ms 117876 KB n=500
45 Correct 61 ms 117852 KB n=500
46 Correct 70 ms 117816 KB n=500
47 Correct 63 ms 117856 KB n=500
48 Correct 63 ms 117852 KB n=500
49 Correct 63 ms 118000 KB n=500
50 Correct 64 ms 117780 KB n=500
51 Correct 63 ms 117820 KB n=500
52 Correct 61 ms 117900 KB n=500
53 Correct 63 ms 117884 KB n=500
54 Correct 63 ms 117896 KB n=500
55 Correct 61 ms 117760 KB n=278
56 Correct 64 ms 117852 KB n=500
57 Correct 63 ms 117872 KB n=500
58 Correct 62 ms 117860 KB n=500
59 Correct 67 ms 118224 KB n=2000
60 Correct 72 ms 118340 KB n=2000
61 Correct 64 ms 118300 KB n=2000
62 Correct 65 ms 118288 KB n=2000
63 Correct 70 ms 118196 KB n=2000
64 Correct 65 ms 118288 KB n=2000
65 Correct 65 ms 118196 KB n=2000
66 Correct 73 ms 118232 KB n=2000
67 Correct 65 ms 118220 KB n=2000
68 Correct 66 ms 118312 KB n=2000
69 Correct 65 ms 118212 KB n=2000
70 Correct 64 ms 118148 KB n=2000
71 Correct 64 ms 118264 KB n=2000
72 Correct 64 ms 118248 KB n=2000
73 Correct 66 ms 118196 KB n=2000
74 Correct 65 ms 118220 KB n=1844
75 Correct 69 ms 118148 KB n=2000
76 Correct 64 ms 118196 KB n=2000
77 Correct 65 ms 118128 KB n=2000
78 Correct 66 ms 118184 KB n=2000
79 Correct 65 ms 118276 KB n=2000
80 Correct 68 ms 118340 KB n=2000
81 Correct 64 ms 118212 KB n=2000
82 Correct 66 ms 118220 KB n=2000
83 Correct 65 ms 118252 KB n=2000
84 Correct 71 ms 118148 KB n=2000
85 Correct 65 ms 118372 KB n=2000
86 Correct 66 ms 118252 KB n=2000
87 Correct 67 ms 118260 KB n=2000
88 Correct 75 ms 118312 KB n=2000
89 Correct 65 ms 118340 KB n=2000
90 Correct 65 ms 118340 KB n=2000
91 Correct 64 ms 118184 KB n=2000
92 Correct 874 ms 169340 KB n=200000
93 Correct 1022 ms 175692 KB n=200000
94 Correct 990 ms 180176 KB n=200000
95 Correct 899 ms 168992 KB n=200000
96 Correct 875 ms 169084 KB n=200000
97 Correct 1119 ms 174440 KB n=200000
98 Correct 879 ms 169172 KB n=200000
99 Correct 1002 ms 169384 KB n=200000
100 Correct 885 ms 169120 KB n=200000
101 Correct 1034 ms 181776 KB n=200000
102 Correct 558 ms 170308 KB n=200000
103 Correct 579 ms 170312 KB n=200000
104 Correct 564 ms 170320 KB n=200000
105 Correct 586 ms 170628 KB n=200000
106 Correct 603 ms 170856 KB n=200000
107 Correct 590 ms 170796 KB n=200000
108 Correct 978 ms 169252 KB n=200000
109 Correct 935 ms 169232 KB n=200000
110 Correct 944 ms 169208 KB n=200000
111 Correct 866 ms 168652 KB n=200000
112 Correct 1020 ms 180448 KB n=200000
113 Correct 1061 ms 174516 KB n=200000
114 Correct 866 ms 168628 KB n=200000
115 Correct 1177 ms 171596 KB n=200000
116 Correct 875 ms 169248 KB n=200000
117 Correct 1033 ms 181072 KB n=200000
118 Correct 1115 ms 173080 KB n=200000
119 Correct 843 ms 169284 KB n=200000
120 Correct 937 ms 180872 KB n=200000
121 Correct 943 ms 180996 KB n=200000
122 Correct 970 ms 181184 KB n=200000
123 Correct 578 ms 170452 KB n=200000
124 Correct 298 ms 133356 KB n=25264