Submission #607716

# Submission time Handle Problem Language Result Execution time Memory
607716 2022-07-27T01:41:02 Z bgnbvnbv Birthday gift (IZhO18_treearray) C++14
56 / 100
1450 ms 111944 KB
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll maxN=3e5+1;
vector<ll> g[maxN];
ll par[maxN][20],h[maxN],p[maxN];
void dfs(ll u, ll pp)
{
    for(auto v:g[u])
    {
        if(v!=pp)
        {
            p[v]=u;
            par[v][0]=u;
            h[v]=h[u]+1;
            for(int i=1;i<=18;i++) par[v][i]=par[par[v][i-1]][i-1];
            dfs(v,u);
        }
    }
}
ll LCA(ll u, ll v)
{
    if(h[u]<h[v]) swap(u,v);
    ll log=log2(h[u])+1;
    for(int i=log;i>=0;i--)
    {
        if(h[par[u][i]]>=h[v]) u=par[u][i];
    }
    if(u==v) return u;
    for(int i=log;i>=0;i--)
    {
        if(par[u][i]!=par[v][i]) u=par[u][i],v=par[v][i];
    }
    return p[u];
}
ll n,m,q;
set<int> s[maxN],t[maxN];
ll a[maxN];
#define pb push_back
ll lca[maxN];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >>n>>m>>q;
    for(int i=1;i<n;i++)
    {
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    p[1]=1;
    for(int i=0;i<=18;i++) par[1][i]=1;
    dfs(1,0);
    for(int i=1;i<=m;i++) cin >> a[i],s[a[i]].insert(i);
    for(int i=1;i<m;i++)
    {
        lca[i]=LCA(a[i],a[i+1]);
        t[lca[i]].insert(i);
    }
    //for(auto z:t[1]) cout << z<<' ';
    //cout << '\n';
    for(int i=1;i<=q;i++)
    {
        ll type,l,r,k;
        cin >> type;
        if(type==1)
        {
            cin >> l >> r;
            s[a[l]].erase(l);
            t[lca[l]].erase(l);
            t[lca[l-1]].erase(l-1);
            a[l]=r;
            s[a[l]].insert(l);
            if(l<n)
            {
                lca[l]=LCA(a[l],a[l+1]);
                t[lca[l]].insert(l);
            }
            if(l>1)
            {
                lca[l-1]=LCA(a[l-1],a[l]);
                t[lca[l-1]].insert(l-1);
            }
        }
        else
        {
            cin >> l >> r >> k;
            auto x=s[k].upper_bound(l-1);
            if(*x<=r&&x!=s[k].end())
            {
                cout << *x <<' '<<*x<<'\n';
            }
            else
            {
                x=t[k].upper_bound(l-1);
                if(*x<=r-1&&x!=t[k].end())
                {
                    cout << *x<<' '<<*x+1<<'\n';

                }
                else
                {
                    cout <<-1<< ' '<<-1<<'\n';
                }
            }
        }
    }

}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35540 KB n=5
2 Correct 20 ms 35580 KB n=100
3 Correct 19 ms 35540 KB n=100
4 Correct 17 ms 35600 KB n=100
5 Correct 20 ms 35548 KB n=100
6 Correct 18 ms 35532 KB n=100
7 Correct 18 ms 35588 KB n=100
8 Correct 19 ms 35540 KB n=100
9 Correct 17 ms 35524 KB n=100
10 Correct 17 ms 35564 KB n=100
11 Correct 17 ms 35604 KB n=100
12 Correct 21 ms 35552 KB n=100
13 Correct 19 ms 35540 KB n=100
14 Correct 21 ms 35540 KB n=100
15 Correct 17 ms 35540 KB n=100
16 Correct 17 ms 35540 KB n=100
17 Correct 18 ms 35508 KB n=100
18 Correct 21 ms 35604 KB n=100
19 Correct 21 ms 35604 KB n=100
20 Correct 17 ms 35484 KB n=100
21 Correct 20 ms 35540 KB n=100
22 Correct 21 ms 35540 KB n=100
23 Correct 17 ms 35564 KB n=100
24 Correct 20 ms 35540 KB n=100
25 Correct 17 ms 35576 KB n=100
26 Correct 17 ms 35560 KB n=12
27 Correct 21 ms 35540 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35540 KB n=5
2 Correct 20 ms 35580 KB n=100
3 Correct 19 ms 35540 KB n=100
4 Correct 17 ms 35600 KB n=100
5 Correct 20 ms 35548 KB n=100
6 Correct 18 ms 35532 KB n=100
7 Correct 18 ms 35588 KB n=100
8 Correct 19 ms 35540 KB n=100
9 Correct 17 ms 35524 KB n=100
10 Correct 17 ms 35564 KB n=100
11 Correct 17 ms 35604 KB n=100
12 Correct 21 ms 35552 KB n=100
13 Correct 19 ms 35540 KB n=100
14 Correct 21 ms 35540 KB n=100
15 Correct 17 ms 35540 KB n=100
16 Correct 17 ms 35540 KB n=100
17 Correct 18 ms 35508 KB n=100
18 Correct 21 ms 35604 KB n=100
19 Correct 21 ms 35604 KB n=100
20 Correct 17 ms 35484 KB n=100
21 Correct 20 ms 35540 KB n=100
22 Correct 21 ms 35540 KB n=100
23 Correct 17 ms 35564 KB n=100
24 Correct 20 ms 35540 KB n=100
25 Correct 17 ms 35576 KB n=100
26 Correct 17 ms 35560 KB n=12
27 Correct 21 ms 35540 KB n=100
28 Correct 16 ms 35668 KB n=500
29 Correct 20 ms 35756 KB n=500
30 Correct 19 ms 35748 KB n=500
31 Correct 18 ms 35668 KB n=500
32 Correct 18 ms 35668 KB n=500
33 Correct 17 ms 35688 KB n=500
34 Correct 17 ms 35704 KB n=500
35 Correct 17 ms 35756 KB n=500
36 Correct 19 ms 35796 KB n=500
37 Correct 18 ms 35668 KB n=500
38 Correct 18 ms 35620 KB n=500
39 Correct 19 ms 35624 KB n=500
40 Correct 18 ms 35740 KB n=500
41 Correct 18 ms 35656 KB n=500
42 Correct 18 ms 35668 KB n=500
43 Correct 18 ms 35660 KB n=500
44 Correct 17 ms 35668 KB n=500
45 Correct 18 ms 35688 KB n=500
46 Correct 21 ms 35668 KB n=500
47 Correct 17 ms 35668 KB n=500
48 Correct 19 ms 35668 KB n=500
49 Correct 17 ms 35644 KB n=500
50 Correct 19 ms 35740 KB n=500
51 Correct 16 ms 35668 KB n=500
52 Correct 20 ms 35696 KB n=500
53 Correct 18 ms 35668 KB n=500
54 Correct 18 ms 35668 KB n=500
55 Correct 16 ms 35668 KB n=278
56 Correct 17 ms 35668 KB n=500
57 Correct 18 ms 35796 KB n=500
58 Correct 17 ms 35668 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35540 KB n=5
2 Correct 20 ms 35580 KB n=100
3 Correct 19 ms 35540 KB n=100
4 Correct 17 ms 35600 KB n=100
5 Correct 20 ms 35548 KB n=100
6 Correct 18 ms 35532 KB n=100
7 Correct 18 ms 35588 KB n=100
8 Correct 19 ms 35540 KB n=100
9 Correct 17 ms 35524 KB n=100
10 Correct 17 ms 35564 KB n=100
11 Correct 17 ms 35604 KB n=100
12 Correct 21 ms 35552 KB n=100
13 Correct 19 ms 35540 KB n=100
14 Correct 21 ms 35540 KB n=100
15 Correct 17 ms 35540 KB n=100
16 Correct 17 ms 35540 KB n=100
17 Correct 18 ms 35508 KB n=100
18 Correct 21 ms 35604 KB n=100
19 Correct 21 ms 35604 KB n=100
20 Correct 17 ms 35484 KB n=100
21 Correct 20 ms 35540 KB n=100
22 Correct 21 ms 35540 KB n=100
23 Correct 17 ms 35564 KB n=100
24 Correct 20 ms 35540 KB n=100
25 Correct 17 ms 35576 KB n=100
26 Correct 17 ms 35560 KB n=12
27 Correct 21 ms 35540 KB n=100
28 Correct 16 ms 35668 KB n=500
29 Correct 20 ms 35756 KB n=500
30 Correct 19 ms 35748 KB n=500
31 Correct 18 ms 35668 KB n=500
32 Correct 18 ms 35668 KB n=500
33 Correct 17 ms 35688 KB n=500
34 Correct 17 ms 35704 KB n=500
35 Correct 17 ms 35756 KB n=500
36 Correct 19 ms 35796 KB n=500
37 Correct 18 ms 35668 KB n=500
38 Correct 18 ms 35620 KB n=500
39 Correct 19 ms 35624 KB n=500
40 Correct 18 ms 35740 KB n=500
41 Correct 18 ms 35656 KB n=500
42 Correct 18 ms 35668 KB n=500
43 Correct 18 ms 35660 KB n=500
44 Correct 17 ms 35668 KB n=500
45 Correct 18 ms 35688 KB n=500
46 Correct 21 ms 35668 KB n=500
47 Correct 17 ms 35668 KB n=500
48 Correct 19 ms 35668 KB n=500
49 Correct 17 ms 35644 KB n=500
50 Correct 19 ms 35740 KB n=500
51 Correct 16 ms 35668 KB n=500
52 Correct 20 ms 35696 KB n=500
53 Correct 18 ms 35668 KB n=500
54 Correct 18 ms 35668 KB n=500
55 Correct 16 ms 35668 KB n=278
56 Correct 17 ms 35668 KB n=500
57 Correct 18 ms 35796 KB n=500
58 Correct 17 ms 35668 KB n=500
59 Correct 19 ms 36180 KB n=2000
60 Correct 20 ms 36308 KB n=2000
61 Correct 20 ms 36180 KB n=2000
62 Correct 21 ms 36180 KB n=2000
63 Correct 19 ms 36228 KB n=2000
64 Correct 19 ms 36180 KB n=2000
65 Correct 21 ms 36244 KB n=2000
66 Correct 19 ms 36284 KB n=2000
67 Correct 22 ms 36180 KB n=2000
68 Correct 20 ms 36264 KB n=2000
69 Correct 19 ms 36180 KB n=2000
70 Correct 19 ms 36112 KB n=2000
71 Correct 18 ms 36128 KB n=2000
72 Correct 18 ms 36228 KB n=2000
73 Correct 18 ms 36180 KB n=2000
74 Correct 19 ms 36180 KB n=1844
75 Correct 19 ms 36128 KB n=2000
76 Correct 21 ms 36196 KB n=2000
77 Correct 19 ms 36216 KB n=2000
78 Correct 19 ms 36204 KB n=2000
79 Correct 19 ms 36180 KB n=2000
80 Correct 19 ms 36312 KB n=2000
81 Correct 20 ms 36144 KB n=2000
82 Correct 20 ms 36204 KB n=2000
83 Correct 20 ms 36180 KB n=2000
84 Correct 19 ms 36180 KB n=2000
85 Correct 19 ms 36252 KB n=2000
86 Correct 21 ms 36180 KB n=2000
87 Correct 19 ms 36180 KB n=2000
88 Correct 19 ms 36292 KB n=2000
89 Correct 19 ms 36336 KB n=2000
90 Correct 22 ms 36308 KB n=2000
91 Correct 19 ms 36180 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 16 ms 35540 KB n=5
2 Correct 20 ms 35580 KB n=100
3 Correct 19 ms 35540 KB n=100
4 Correct 17 ms 35600 KB n=100
5 Correct 20 ms 35548 KB n=100
6 Correct 18 ms 35532 KB n=100
7 Correct 18 ms 35588 KB n=100
8 Correct 19 ms 35540 KB n=100
9 Correct 17 ms 35524 KB n=100
10 Correct 17 ms 35564 KB n=100
11 Correct 17 ms 35604 KB n=100
12 Correct 21 ms 35552 KB n=100
13 Correct 19 ms 35540 KB n=100
14 Correct 21 ms 35540 KB n=100
15 Correct 17 ms 35540 KB n=100
16 Correct 17 ms 35540 KB n=100
17 Correct 18 ms 35508 KB n=100
18 Correct 21 ms 35604 KB n=100
19 Correct 21 ms 35604 KB n=100
20 Correct 17 ms 35484 KB n=100
21 Correct 20 ms 35540 KB n=100
22 Correct 21 ms 35540 KB n=100
23 Correct 17 ms 35564 KB n=100
24 Correct 20 ms 35540 KB n=100
25 Correct 17 ms 35576 KB n=100
26 Correct 17 ms 35560 KB n=12
27 Correct 21 ms 35540 KB n=100
28 Correct 16 ms 35668 KB n=500
29 Correct 20 ms 35756 KB n=500
30 Correct 19 ms 35748 KB n=500
31 Correct 18 ms 35668 KB n=500
32 Correct 18 ms 35668 KB n=500
33 Correct 17 ms 35688 KB n=500
34 Correct 17 ms 35704 KB n=500
35 Correct 17 ms 35756 KB n=500
36 Correct 19 ms 35796 KB n=500
37 Correct 18 ms 35668 KB n=500
38 Correct 18 ms 35620 KB n=500
39 Correct 19 ms 35624 KB n=500
40 Correct 18 ms 35740 KB n=500
41 Correct 18 ms 35656 KB n=500
42 Correct 18 ms 35668 KB n=500
43 Correct 18 ms 35660 KB n=500
44 Correct 17 ms 35668 KB n=500
45 Correct 18 ms 35688 KB n=500
46 Correct 21 ms 35668 KB n=500
47 Correct 17 ms 35668 KB n=500
48 Correct 19 ms 35668 KB n=500
49 Correct 17 ms 35644 KB n=500
50 Correct 19 ms 35740 KB n=500
51 Correct 16 ms 35668 KB n=500
52 Correct 20 ms 35696 KB n=500
53 Correct 18 ms 35668 KB n=500
54 Correct 18 ms 35668 KB n=500
55 Correct 16 ms 35668 KB n=278
56 Correct 17 ms 35668 KB n=500
57 Correct 18 ms 35796 KB n=500
58 Correct 17 ms 35668 KB n=500
59 Correct 19 ms 36180 KB n=2000
60 Correct 20 ms 36308 KB n=2000
61 Correct 20 ms 36180 KB n=2000
62 Correct 21 ms 36180 KB n=2000
63 Correct 19 ms 36228 KB n=2000
64 Correct 19 ms 36180 KB n=2000
65 Correct 21 ms 36244 KB n=2000
66 Correct 19 ms 36284 KB n=2000
67 Correct 22 ms 36180 KB n=2000
68 Correct 20 ms 36264 KB n=2000
69 Correct 19 ms 36180 KB n=2000
70 Correct 19 ms 36112 KB n=2000
71 Correct 18 ms 36128 KB n=2000
72 Correct 18 ms 36228 KB n=2000
73 Correct 18 ms 36180 KB n=2000
74 Correct 19 ms 36180 KB n=1844
75 Correct 19 ms 36128 KB n=2000
76 Correct 21 ms 36196 KB n=2000
77 Correct 19 ms 36216 KB n=2000
78 Correct 19 ms 36204 KB n=2000
79 Correct 19 ms 36180 KB n=2000
80 Correct 19 ms 36312 KB n=2000
81 Correct 20 ms 36144 KB n=2000
82 Correct 20 ms 36204 KB n=2000
83 Correct 20 ms 36180 KB n=2000
84 Correct 19 ms 36180 KB n=2000
85 Correct 19 ms 36252 KB n=2000
86 Correct 21 ms 36180 KB n=2000
87 Correct 19 ms 36180 KB n=2000
88 Correct 19 ms 36292 KB n=2000
89 Correct 19 ms 36336 KB n=2000
90 Correct 22 ms 36308 KB n=2000
91 Correct 19 ms 36180 KB n=2000
92 Correct 705 ms 101004 KB n=200000
93 Correct 1165 ms 106308 KB n=200000
94 Correct 1059 ms 110376 KB n=200000
95 Correct 743 ms 100856 KB n=200000
96 Correct 677 ms 100884 KB n=200000
97 Correct 1450 ms 105196 KB n=200000
98 Correct 720 ms 101132 KB n=200000
99 Correct 891 ms 100780 KB n=200000
100 Correct 643 ms 101176 KB n=200000
101 Correct 1142 ms 111780 KB n=200000
102 Correct 440 ms 102192 KB n=200000
103 Correct 444 ms 102248 KB n=200000
104 Correct 496 ms 102356 KB n=200000
105 Correct 447 ms 101960 KB n=200000
106 Correct 495 ms 101984 KB n=200000
107 Correct 481 ms 101920 KB n=200000
108 Correct 822 ms 100944 KB n=200000
109 Correct 844 ms 100920 KB n=200000
110 Correct 812 ms 100952 KB n=200000
111 Correct 713 ms 100988 KB n=200000
112 Correct 1120 ms 110776 KB n=200000
113 Correct 1212 ms 105308 KB n=200000
114 Correct 729 ms 100996 KB n=200000
115 Correct 1336 ms 102580 KB n=200000
116 Correct 700 ms 100828 KB n=200000
117 Correct 1207 ms 111232 KB n=200000
118 Correct 1407 ms 103760 KB n=200000
119 Correct 748 ms 100748 KB n=200000
120 Correct 1097 ms 111664 KB n=200000
121 Correct 1081 ms 111548 KB n=200000
122 Correct 1085 ms 111944 KB n=200000
123 Correct 450 ms 101652 KB n=200000
124 Incorrect 243 ms 52440 KB Jury has the answer but participant has not
125 Halted 0 ms 0 KB -