Submission #1112244

# Submission time Handle Problem Language Result Execution time Memory
1112244 2024-11-13T21:06:37 Z SteveBro Birthday gift (IZhO18_treearray) C++17
100 / 100
643 ms 76360 KB
#include <bits/stdc++.h>

using namespace std;
const int nmax=2e5+1;
vector <int> g[nmax];
int ab[nmax*8],t[nmax*2];
void build(int nod, int st, int dr)
{
    if(st==dr)
        ab[nod]=t[st];
    else
    {
        int mij=(st+dr)/2;
        build(nod*2,st,mij);
        build(nod*2+1,mij+1,dr);
        ab[nod]=min(ab[nod*2],ab[nod*2+1]);
    }
}
int k,n;
bool ok[nmax];
int prim[nmax],l[nmax];
void tur(int nod)
{
    t[++k]=nod;
    prim[nod]=k;
    ok[nod]=true;
    for(auto x : g[nod])
    {
        if(!ok[x])
        {
            tur(x);
            t[++k]=nod;
        }
    }
}
int a,b,rez;
void qry(int nod, int st, int dr)
{
    if(a<=st&&dr<=b)
    {
        rez=min(rez,ab[nod]);
    }
    else
    {
        int mij=(st+dr)/2;
        if(a<=mij)
            qry(nod*2,st,mij);
        if(b>mij)
            qry(nod*2+1,mij+1,dr);
    }
}
set <int> sol1[nmax],sol2[nmax];
void lca(int x, int y)
{
    a=min(prim[x],prim[y]);
    b=max(prim[x],prim[y]);
    rez=n+1;
    qry(1,1,n*2-1);
}
std :: set <int> :: iterator it;
int main()
{
    ///freopen("test.in","r",stdin);
    ///freopen("test.out","w",stdout);
    ios :: sync_with_stdio(false);
    cin.tie(0);
    int m,q,i,x,y;
    cin>>n>>m>>q;
    for(i=1;i<n;i++)
    {
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    tur(1);
    build(1,1,n*2-1);
    for(i=1;i<=m;i++)
    {
        cin>>l[i];
        sol1[l[i]].insert(i);
    }
    for(i=1;i<m;i++)
    {
        lca(l[i],l[i+1]);
        sol2[rez].insert(i);
    }
    int tip,st,dr;
    bool found;
    while(q>0)
    {
        q--;
        cin>>tip;
        if(tip==1)
        {
            cin>>x>>y;
            sol1[l[x]].erase(x);
            sol1[y].insert(x);
            if(x!=1)
            {
                lca(l[x],l[x-1]);
                sol2[rez].erase(x-1);
                lca(y,l[x-1]);
                sol2[rez].insert(x-1);
            }
            if(x!=m)
            {
                lca(l[x],l[x+1]);
                sol2[rez].erase(x);
                lca(y,l[x+1]);
                sol2[rez].insert(x);
            }
            l[x]=y;
        }
        else
        {
            cin>>st>>dr>>x;
            found=false;
            if(!sol1[x].empty())
            {
                it=sol1[x].lower_bound(st);
                if(it!=sol1[x].end()&&*it<=dr)
                {
                    found=true;
                    cout<<*it<<" "<<*it<<'\n';
                }
            }
            if(!found&&!sol2[x].empty())
            {
                it=sol2[x].lower_bound(st);
                if(it!=sol2[x].end()&&*it<dr)
                {
                    found=true;
                    cout<<*it<<" "<<*it+1<<'\n';
                }
            }
            if(!found)
                cout<<"-1 -1"<<'\n';
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29264 KB n=5
2 Correct 5 ms 29264 KB n=100
3 Correct 5 ms 29276 KB n=100
4 Correct 5 ms 29424 KB n=100
5 Correct 5 ms 29264 KB n=100
6 Correct 5 ms 29264 KB n=100
7 Correct 5 ms 29264 KB n=100
8 Correct 5 ms 29264 KB n=100
9 Correct 5 ms 29264 KB n=100
10 Correct 5 ms 29432 KB n=100
11 Correct 5 ms 29372 KB n=100
12 Correct 5 ms 29264 KB n=100
13 Correct 6 ms 29264 KB n=100
14 Correct 5 ms 29264 KB n=100
15 Correct 5 ms 29264 KB n=100
16 Correct 5 ms 29264 KB n=100
17 Correct 5 ms 29424 KB n=100
18 Correct 5 ms 29264 KB n=100
19 Correct 5 ms 29264 KB n=100
20 Correct 5 ms 29264 KB n=100
21 Correct 6 ms 29204 KB n=100
22 Correct 5 ms 29264 KB n=100
23 Correct 5 ms 29264 KB n=100
24 Correct 5 ms 29264 KB n=100
25 Correct 6 ms 29264 KB n=100
26 Correct 6 ms 29436 KB n=12
27 Correct 6 ms 29264 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29264 KB n=5
2 Correct 5 ms 29264 KB n=100
3 Correct 5 ms 29276 KB n=100
4 Correct 5 ms 29424 KB n=100
5 Correct 5 ms 29264 KB n=100
6 Correct 5 ms 29264 KB n=100
7 Correct 5 ms 29264 KB n=100
8 Correct 5 ms 29264 KB n=100
9 Correct 5 ms 29264 KB n=100
10 Correct 5 ms 29432 KB n=100
11 Correct 5 ms 29372 KB n=100
12 Correct 5 ms 29264 KB n=100
13 Correct 6 ms 29264 KB n=100
14 Correct 5 ms 29264 KB n=100
15 Correct 5 ms 29264 KB n=100
16 Correct 5 ms 29264 KB n=100
17 Correct 5 ms 29424 KB n=100
18 Correct 5 ms 29264 KB n=100
19 Correct 5 ms 29264 KB n=100
20 Correct 5 ms 29264 KB n=100
21 Correct 6 ms 29204 KB n=100
22 Correct 5 ms 29264 KB n=100
23 Correct 5 ms 29264 KB n=100
24 Correct 5 ms 29264 KB n=100
25 Correct 6 ms 29264 KB n=100
26 Correct 6 ms 29436 KB n=12
27 Correct 6 ms 29264 KB n=100
28 Correct 6 ms 29264 KB n=500
29 Correct 5 ms 29520 KB n=500
30 Correct 6 ms 29264 KB n=500
31 Correct 6 ms 29520 KB n=500
32 Correct 6 ms 29264 KB n=500
33 Correct 6 ms 29264 KB n=500
34 Correct 5 ms 29264 KB n=500
35 Correct 7 ms 29520 KB n=500
36 Correct 5 ms 29264 KB n=500
37 Correct 6 ms 29276 KB n=500
38 Correct 6 ms 29468 KB n=500
39 Correct 6 ms 29436 KB n=500
40 Correct 6 ms 29264 KB n=500
41 Correct 5 ms 29264 KB n=500
42 Correct 6 ms 29264 KB n=500
43 Correct 6 ms 29264 KB n=500
44 Correct 6 ms 29264 KB n=500
45 Correct 6 ms 29432 KB n=500
46 Correct 6 ms 29520 KB n=500
47 Correct 6 ms 29520 KB n=500
48 Correct 5 ms 29264 KB n=500
49 Correct 6 ms 29520 KB n=500
50 Correct 6 ms 29264 KB n=500
51 Correct 6 ms 29520 KB n=500
52 Correct 7 ms 29520 KB n=500
53 Correct 7 ms 29264 KB n=500
54 Correct 8 ms 29520 KB n=500
55 Correct 6 ms 29264 KB n=278
56 Correct 6 ms 29520 KB n=500
57 Correct 7 ms 29520 KB n=500
58 Correct 7 ms 29264 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29264 KB n=5
2 Correct 5 ms 29264 KB n=100
3 Correct 5 ms 29276 KB n=100
4 Correct 5 ms 29424 KB n=100
5 Correct 5 ms 29264 KB n=100
6 Correct 5 ms 29264 KB n=100
7 Correct 5 ms 29264 KB n=100
8 Correct 5 ms 29264 KB n=100
9 Correct 5 ms 29264 KB n=100
10 Correct 5 ms 29432 KB n=100
11 Correct 5 ms 29372 KB n=100
12 Correct 5 ms 29264 KB n=100
13 Correct 6 ms 29264 KB n=100
14 Correct 5 ms 29264 KB n=100
15 Correct 5 ms 29264 KB n=100
16 Correct 5 ms 29264 KB n=100
17 Correct 5 ms 29424 KB n=100
18 Correct 5 ms 29264 KB n=100
19 Correct 5 ms 29264 KB n=100
20 Correct 5 ms 29264 KB n=100
21 Correct 6 ms 29204 KB n=100
22 Correct 5 ms 29264 KB n=100
23 Correct 5 ms 29264 KB n=100
24 Correct 5 ms 29264 KB n=100
25 Correct 6 ms 29264 KB n=100
26 Correct 6 ms 29436 KB n=12
27 Correct 6 ms 29264 KB n=100
28 Correct 6 ms 29264 KB n=500
29 Correct 5 ms 29520 KB n=500
30 Correct 6 ms 29264 KB n=500
31 Correct 6 ms 29520 KB n=500
32 Correct 6 ms 29264 KB n=500
33 Correct 6 ms 29264 KB n=500
34 Correct 5 ms 29264 KB n=500
35 Correct 7 ms 29520 KB n=500
36 Correct 5 ms 29264 KB n=500
37 Correct 6 ms 29276 KB n=500
38 Correct 6 ms 29468 KB n=500
39 Correct 6 ms 29436 KB n=500
40 Correct 6 ms 29264 KB n=500
41 Correct 5 ms 29264 KB n=500
42 Correct 6 ms 29264 KB n=500
43 Correct 6 ms 29264 KB n=500
44 Correct 6 ms 29264 KB n=500
45 Correct 6 ms 29432 KB n=500
46 Correct 6 ms 29520 KB n=500
47 Correct 6 ms 29520 KB n=500
48 Correct 5 ms 29264 KB n=500
49 Correct 6 ms 29520 KB n=500
50 Correct 6 ms 29264 KB n=500
51 Correct 6 ms 29520 KB n=500
52 Correct 7 ms 29520 KB n=500
53 Correct 7 ms 29264 KB n=500
54 Correct 8 ms 29520 KB n=500
55 Correct 6 ms 29264 KB n=278
56 Correct 6 ms 29520 KB n=500
57 Correct 7 ms 29520 KB n=500
58 Correct 7 ms 29264 KB n=500
59 Correct 8 ms 29520 KB n=2000
60 Correct 8 ms 29776 KB n=2000
61 Correct 10 ms 29776 KB n=2000
62 Correct 8 ms 29520 KB n=2000
63 Correct 8 ms 29520 KB n=2000
64 Correct 9 ms 29776 KB n=2000
65 Correct 9 ms 29520 KB n=2000
66 Correct 7 ms 29776 KB n=2000
67 Correct 10 ms 29720 KB n=2000
68 Correct 8 ms 29776 KB n=2000
69 Correct 7 ms 29520 KB n=2000
70 Correct 9 ms 29536 KB n=2000
71 Correct 7 ms 29696 KB n=2000
72 Correct 7 ms 29520 KB n=2000
73 Correct 8 ms 29520 KB n=2000
74 Correct 8 ms 29520 KB n=1844
75 Correct 7 ms 29520 KB n=2000
76 Correct 9 ms 29540 KB n=2000
77 Correct 8 ms 29520 KB n=2000
78 Correct 8 ms 29520 KB n=2000
79 Correct 7 ms 29520 KB n=2000
80 Correct 7 ms 29776 KB n=2000
81 Correct 7 ms 29776 KB n=2000
82 Correct 7 ms 29688 KB n=2000
83 Correct 8 ms 29776 KB n=2000
84 Correct 8 ms 29520 KB n=2000
85 Correct 8 ms 29776 KB n=2000
86 Correct 8 ms 29520 KB n=2000
87 Correct 8 ms 29520 KB n=2000
88 Correct 9 ms 29776 KB n=2000
89 Correct 8 ms 29776 KB n=2000
90 Correct 9 ms 29836 KB n=2000
91 Correct 7 ms 29520 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 5 ms 29264 KB n=5
2 Correct 5 ms 29264 KB n=100
3 Correct 5 ms 29276 KB n=100
4 Correct 5 ms 29424 KB n=100
5 Correct 5 ms 29264 KB n=100
6 Correct 5 ms 29264 KB n=100
7 Correct 5 ms 29264 KB n=100
8 Correct 5 ms 29264 KB n=100
9 Correct 5 ms 29264 KB n=100
10 Correct 5 ms 29432 KB n=100
11 Correct 5 ms 29372 KB n=100
12 Correct 5 ms 29264 KB n=100
13 Correct 6 ms 29264 KB n=100
14 Correct 5 ms 29264 KB n=100
15 Correct 5 ms 29264 KB n=100
16 Correct 5 ms 29264 KB n=100
17 Correct 5 ms 29424 KB n=100
18 Correct 5 ms 29264 KB n=100
19 Correct 5 ms 29264 KB n=100
20 Correct 5 ms 29264 KB n=100
21 Correct 6 ms 29204 KB n=100
22 Correct 5 ms 29264 KB n=100
23 Correct 5 ms 29264 KB n=100
24 Correct 5 ms 29264 KB n=100
25 Correct 6 ms 29264 KB n=100
26 Correct 6 ms 29436 KB n=12
27 Correct 6 ms 29264 KB n=100
28 Correct 6 ms 29264 KB n=500
29 Correct 5 ms 29520 KB n=500
30 Correct 6 ms 29264 KB n=500
31 Correct 6 ms 29520 KB n=500
32 Correct 6 ms 29264 KB n=500
33 Correct 6 ms 29264 KB n=500
34 Correct 5 ms 29264 KB n=500
35 Correct 7 ms 29520 KB n=500
36 Correct 5 ms 29264 KB n=500
37 Correct 6 ms 29276 KB n=500
38 Correct 6 ms 29468 KB n=500
39 Correct 6 ms 29436 KB n=500
40 Correct 6 ms 29264 KB n=500
41 Correct 5 ms 29264 KB n=500
42 Correct 6 ms 29264 KB n=500
43 Correct 6 ms 29264 KB n=500
44 Correct 6 ms 29264 KB n=500
45 Correct 6 ms 29432 KB n=500
46 Correct 6 ms 29520 KB n=500
47 Correct 6 ms 29520 KB n=500
48 Correct 5 ms 29264 KB n=500
49 Correct 6 ms 29520 KB n=500
50 Correct 6 ms 29264 KB n=500
51 Correct 6 ms 29520 KB n=500
52 Correct 7 ms 29520 KB n=500
53 Correct 7 ms 29264 KB n=500
54 Correct 8 ms 29520 KB n=500
55 Correct 6 ms 29264 KB n=278
56 Correct 6 ms 29520 KB n=500
57 Correct 7 ms 29520 KB n=500
58 Correct 7 ms 29264 KB n=500
59 Correct 8 ms 29520 KB n=2000
60 Correct 8 ms 29776 KB n=2000
61 Correct 10 ms 29776 KB n=2000
62 Correct 8 ms 29520 KB n=2000
63 Correct 8 ms 29520 KB n=2000
64 Correct 9 ms 29776 KB n=2000
65 Correct 9 ms 29520 KB n=2000
66 Correct 7 ms 29776 KB n=2000
67 Correct 10 ms 29720 KB n=2000
68 Correct 8 ms 29776 KB n=2000
69 Correct 7 ms 29520 KB n=2000
70 Correct 9 ms 29536 KB n=2000
71 Correct 7 ms 29696 KB n=2000
72 Correct 7 ms 29520 KB n=2000
73 Correct 8 ms 29520 KB n=2000
74 Correct 8 ms 29520 KB n=1844
75 Correct 7 ms 29520 KB n=2000
76 Correct 9 ms 29540 KB n=2000
77 Correct 8 ms 29520 KB n=2000
78 Correct 8 ms 29520 KB n=2000
79 Correct 7 ms 29520 KB n=2000
80 Correct 7 ms 29776 KB n=2000
81 Correct 7 ms 29776 KB n=2000
82 Correct 7 ms 29688 KB n=2000
83 Correct 8 ms 29776 KB n=2000
84 Correct 8 ms 29520 KB n=2000
85 Correct 8 ms 29776 KB n=2000
86 Correct 8 ms 29520 KB n=2000
87 Correct 8 ms 29520 KB n=2000
88 Correct 9 ms 29776 KB n=2000
89 Correct 8 ms 29776 KB n=2000
90 Correct 9 ms 29836 KB n=2000
91 Correct 7 ms 29520 KB n=2000
92 Correct 554 ms 67052 KB n=200000
93 Correct 616 ms 71840 KB n=200000
94 Correct 487 ms 75152 KB n=200000
95 Correct 572 ms 66756 KB n=200000
96 Correct 490 ms 67004 KB n=200000
97 Correct 574 ms 71076 KB n=200000
98 Correct 588 ms 66716 KB n=200000
99 Correct 541 ms 66888 KB n=200000
100 Correct 499 ms 66904 KB n=200000
101 Correct 519 ms 76360 KB n=200000
102 Correct 283 ms 68056 KB n=200000
103 Correct 278 ms 67912 KB n=200000
104 Correct 286 ms 67884 KB n=200000
105 Correct 278 ms 68300 KB n=200000
106 Correct 266 ms 68492 KB n=200000
107 Correct 254 ms 68424 KB n=200000
108 Correct 543 ms 66904 KB n=200000
109 Correct 590 ms 66888 KB n=200000
110 Correct 601 ms 66888 KB n=200000
111 Correct 566 ms 66364 KB n=200000
112 Correct 524 ms 75480 KB n=200000
113 Correct 643 ms 71048 KB n=200000
114 Correct 549 ms 66252 KB n=200000
115 Correct 543 ms 69192 KB n=200000
116 Correct 534 ms 66960 KB n=200000
117 Correct 551 ms 75900 KB n=200000
118 Correct 519 ms 69796 KB n=200000
119 Correct 532 ms 67036 KB n=200000
120 Correct 403 ms 75316 KB n=200000
121 Correct 442 ms 75336 KB n=200000
122 Correct 446 ms 75848 KB n=200000
123 Correct 295 ms 68168 KB n=200000
124 Correct 133 ms 41844 KB n=25264