Submission #90380

# Submission time Handle Problem Language Result Execution time Memory
90380 2018-12-21T12:24:31 Z Bodo171 Birthday gift (IZhO18_treearray) C++14
100 / 100
3121 ms 145680 KB
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
using namespace std;
const int nmax=200005;
vector<int> v[nmax];
set<int> s[nmax],og[nmax];
int l[nmax],r[nmax],seq[nmax];
int tt[20][nmax];
int n,m,q,i,j,poz,val,nr,a,b,tip,x,ll,rr;
void dfs(int x)
{
    l[x]=++nr;
    for(int i=0;i<v[x].size();i++)
        if(!l[v[x][i]])
    {
        tt[0][v[x][i]]=x;
        dfs(v[x][i]);
    }
    r[x]=nr;
}
bool cup(int x,int y)
{
    return (l[x]<=l[y]&&l[y]<=r[x]);
}
int lca(int a,int b)
{
    for(int p=17;p>=0;p--)
        if(tt[p][a]&&(!cup(tt[p][a],b)))
          a=tt[p][a];
    if(!cup(a,b))
         a=tt[0][a];
    return a;
}
void prc()
{
    for(i=1;i<=17;i++)
        for(j=1;j<=n;j++)
          tt[i][j]=tt[i-1][tt[i-1][j]];
}
int main()
{
    //freopen("data.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n>>m>>q;
    for(i=1;i<=n-1;i++)
    {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1);
    prc();
    for(i=1;i<=n;i++)
        s[i].insert(m+1),og[i].insert(m+1);
    for(i=1;i<=m;i++)
    {
        cin>>seq[i];
        og[seq[i]].insert(i);
    }
    for(i=1;i<m;i++)
    {
        s[lca(seq[i],seq[i+1])].insert(i);
    }
    for(i=1;i<=q;i++)
    {
        cin>>tip;
        if(tip==1)
        {
            cin>>poz>>val;
            if(poz>1) s[lca(seq[poz-1],seq[poz])].erase(poz-1);
            if(poz<m) s[lca(seq[poz],seq[poz+1])].erase(poz);
            og[seq[poz]].erase(poz);
            seq[poz]=val;
            if(poz>1) s[lca(seq[poz-1],seq[poz])].insert(poz-1);
            if(poz<m) s[lca(seq[poz],seq[poz+1])].insert(poz);
            og[seq[poz]].insert(poz);
        }
        else
        {
            cin>>ll>>rr>>x;
            poz=(*s[x].lower_bound(ll));
            if(poz<rr) cout<<poz<<' '<<poz+1<<'\n';
            else
            {
                poz=(*og[x].lower_bound(ll));
                if(poz<=rr) cout<<poz<<' '<<poz<<'\n';
                else cout<<"-1 -1\n";
            }
        }
    }
    return 0;
}

Compilation message

treearray.cpp: In function 'void dfs(int)':
treearray.cpp:15:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB n=5
2 Correct 23 ms 24180 KB n=100
3 Correct 23 ms 24180 KB n=100
4 Correct 20 ms 24180 KB n=100
5 Correct 19 ms 24180 KB n=100
6 Correct 19 ms 24180 KB n=100
7 Correct 19 ms 24180 KB n=100
8 Correct 19 ms 24180 KB n=100
9 Correct 23 ms 24248 KB n=100
10 Correct 20 ms 24284 KB n=100
11 Correct 23 ms 24284 KB n=100
12 Correct 22 ms 24284 KB n=100
13 Correct 19 ms 24284 KB n=100
14 Correct 19 ms 24284 KB n=100
15 Correct 22 ms 24284 KB n=100
16 Correct 23 ms 24352 KB n=100
17 Correct 23 ms 24352 KB n=100
18 Correct 23 ms 24352 KB n=100
19 Correct 23 ms 24352 KB n=100
20 Correct 23 ms 24352 KB n=100
21 Correct 23 ms 24352 KB n=100
22 Correct 23 ms 24352 KB n=100
23 Correct 22 ms 24352 KB n=100
24 Correct 23 ms 24352 KB n=100
25 Correct 22 ms 24352 KB n=100
26 Correct 22 ms 24352 KB n=12
27 Correct 23 ms 24352 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB n=5
2 Correct 23 ms 24180 KB n=100
3 Correct 23 ms 24180 KB n=100
4 Correct 20 ms 24180 KB n=100
5 Correct 19 ms 24180 KB n=100
6 Correct 19 ms 24180 KB n=100
7 Correct 19 ms 24180 KB n=100
8 Correct 19 ms 24180 KB n=100
9 Correct 23 ms 24248 KB n=100
10 Correct 20 ms 24284 KB n=100
11 Correct 23 ms 24284 KB n=100
12 Correct 22 ms 24284 KB n=100
13 Correct 19 ms 24284 KB n=100
14 Correct 19 ms 24284 KB n=100
15 Correct 22 ms 24284 KB n=100
16 Correct 23 ms 24352 KB n=100
17 Correct 23 ms 24352 KB n=100
18 Correct 23 ms 24352 KB n=100
19 Correct 23 ms 24352 KB n=100
20 Correct 23 ms 24352 KB n=100
21 Correct 23 ms 24352 KB n=100
22 Correct 23 ms 24352 KB n=100
23 Correct 22 ms 24352 KB n=100
24 Correct 23 ms 24352 KB n=100
25 Correct 22 ms 24352 KB n=100
26 Correct 22 ms 24352 KB n=12
27 Correct 23 ms 24352 KB n=100
28 Correct 42 ms 24528 KB n=500
29 Correct 20 ms 24528 KB n=500
30 Correct 24 ms 24528 KB n=500
31 Correct 21 ms 24528 KB n=500
32 Correct 21 ms 24528 KB n=500
33 Correct 21 ms 24528 KB n=500
34 Correct 21 ms 24528 KB n=500
35 Correct 21 ms 24528 KB n=500
36 Correct 23 ms 24528 KB n=500
37 Correct 24 ms 24528 KB n=500
38 Correct 24 ms 24540 KB n=500
39 Correct 21 ms 24552 KB n=500
40 Correct 21 ms 24568 KB n=500
41 Correct 34 ms 24584 KB n=500
42 Correct 20 ms 24636 KB n=500
43 Correct 20 ms 24636 KB n=500
44 Correct 20 ms 24636 KB n=500
45 Correct 24 ms 24640 KB n=500
46 Correct 24 ms 24648 KB n=500
47 Correct 20 ms 24664 KB n=500
48 Correct 24 ms 24680 KB n=500
49 Correct 23 ms 24692 KB n=500
50 Correct 24 ms 24708 KB n=500
51 Correct 24 ms 24720 KB n=500
52 Correct 24 ms 24736 KB n=500
53 Correct 26 ms 24752 KB n=500
54 Correct 24 ms 24768 KB n=500
55 Correct 24 ms 24780 KB n=278
56 Correct 24 ms 24868 KB n=500
57 Correct 24 ms 24868 KB n=500
58 Correct 25 ms 24868 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB n=5
2 Correct 23 ms 24180 KB n=100
3 Correct 23 ms 24180 KB n=100
4 Correct 20 ms 24180 KB n=100
5 Correct 19 ms 24180 KB n=100
6 Correct 19 ms 24180 KB n=100
7 Correct 19 ms 24180 KB n=100
8 Correct 19 ms 24180 KB n=100
9 Correct 23 ms 24248 KB n=100
10 Correct 20 ms 24284 KB n=100
11 Correct 23 ms 24284 KB n=100
12 Correct 22 ms 24284 KB n=100
13 Correct 19 ms 24284 KB n=100
14 Correct 19 ms 24284 KB n=100
15 Correct 22 ms 24284 KB n=100
16 Correct 23 ms 24352 KB n=100
17 Correct 23 ms 24352 KB n=100
18 Correct 23 ms 24352 KB n=100
19 Correct 23 ms 24352 KB n=100
20 Correct 23 ms 24352 KB n=100
21 Correct 23 ms 24352 KB n=100
22 Correct 23 ms 24352 KB n=100
23 Correct 22 ms 24352 KB n=100
24 Correct 23 ms 24352 KB n=100
25 Correct 22 ms 24352 KB n=100
26 Correct 22 ms 24352 KB n=12
27 Correct 23 ms 24352 KB n=100
28 Correct 42 ms 24528 KB n=500
29 Correct 20 ms 24528 KB n=500
30 Correct 24 ms 24528 KB n=500
31 Correct 21 ms 24528 KB n=500
32 Correct 21 ms 24528 KB n=500
33 Correct 21 ms 24528 KB n=500
34 Correct 21 ms 24528 KB n=500
35 Correct 21 ms 24528 KB n=500
36 Correct 23 ms 24528 KB n=500
37 Correct 24 ms 24528 KB n=500
38 Correct 24 ms 24540 KB n=500
39 Correct 21 ms 24552 KB n=500
40 Correct 21 ms 24568 KB n=500
41 Correct 34 ms 24584 KB n=500
42 Correct 20 ms 24636 KB n=500
43 Correct 20 ms 24636 KB n=500
44 Correct 20 ms 24636 KB n=500
45 Correct 24 ms 24640 KB n=500
46 Correct 24 ms 24648 KB n=500
47 Correct 20 ms 24664 KB n=500
48 Correct 24 ms 24680 KB n=500
49 Correct 23 ms 24692 KB n=500
50 Correct 24 ms 24708 KB n=500
51 Correct 24 ms 24720 KB n=500
52 Correct 24 ms 24736 KB n=500
53 Correct 26 ms 24752 KB n=500
54 Correct 24 ms 24768 KB n=500
55 Correct 24 ms 24780 KB n=278
56 Correct 24 ms 24868 KB n=500
57 Correct 24 ms 24868 KB n=500
58 Correct 25 ms 24868 KB n=500
59 Correct 28 ms 25340 KB n=2000
60 Correct 27 ms 25648 KB n=2000
61 Correct 29 ms 25648 KB n=2000
62 Correct 29 ms 25648 KB n=2000
63 Correct 28 ms 25648 KB n=2000
64 Correct 28 ms 25652 KB n=2000
65 Correct 24 ms 25708 KB n=2000
66 Correct 29 ms 25888 KB n=2000
67 Correct 29 ms 25888 KB n=2000
68 Correct 29 ms 25888 KB n=2000
69 Correct 30 ms 25928 KB n=2000
70 Correct 28 ms 25980 KB n=2000
71 Correct 28 ms 26032 KB n=2000
72 Correct 28 ms 26100 KB n=2000
73 Correct 29 ms 26200 KB n=2000
74 Correct 27 ms 26212 KB n=1844
75 Correct 28 ms 26336 KB n=2000
76 Correct 28 ms 26336 KB n=2000
77 Correct 28 ms 26364 KB n=2000
78 Correct 29 ms 26544 KB n=2000
79 Correct 28 ms 26544 KB n=2000
80 Correct 28 ms 26644 KB n=2000
81 Correct 29 ms 26644 KB n=2000
82 Correct 28 ms 26644 KB n=2000
83 Correct 28 ms 26804 KB n=2000
84 Correct 28 ms 26804 KB n=2000
85 Correct 30 ms 26804 KB n=2000
86 Correct 28 ms 26840 KB n=2000
87 Correct 28 ms 26896 KB n=2000
88 Correct 29 ms 27076 KB n=2000
89 Correct 28 ms 27132 KB n=2000
90 Correct 28 ms 27188 KB n=2000
91 Correct 25 ms 27188 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB n=5
2 Correct 23 ms 24180 KB n=100
3 Correct 23 ms 24180 KB n=100
4 Correct 20 ms 24180 KB n=100
5 Correct 19 ms 24180 KB n=100
6 Correct 19 ms 24180 KB n=100
7 Correct 19 ms 24180 KB n=100
8 Correct 19 ms 24180 KB n=100
9 Correct 23 ms 24248 KB n=100
10 Correct 20 ms 24284 KB n=100
11 Correct 23 ms 24284 KB n=100
12 Correct 22 ms 24284 KB n=100
13 Correct 19 ms 24284 KB n=100
14 Correct 19 ms 24284 KB n=100
15 Correct 22 ms 24284 KB n=100
16 Correct 23 ms 24352 KB n=100
17 Correct 23 ms 24352 KB n=100
18 Correct 23 ms 24352 KB n=100
19 Correct 23 ms 24352 KB n=100
20 Correct 23 ms 24352 KB n=100
21 Correct 23 ms 24352 KB n=100
22 Correct 23 ms 24352 KB n=100
23 Correct 22 ms 24352 KB n=100
24 Correct 23 ms 24352 KB n=100
25 Correct 22 ms 24352 KB n=100
26 Correct 22 ms 24352 KB n=12
27 Correct 23 ms 24352 KB n=100
28 Correct 42 ms 24528 KB n=500
29 Correct 20 ms 24528 KB n=500
30 Correct 24 ms 24528 KB n=500
31 Correct 21 ms 24528 KB n=500
32 Correct 21 ms 24528 KB n=500
33 Correct 21 ms 24528 KB n=500
34 Correct 21 ms 24528 KB n=500
35 Correct 21 ms 24528 KB n=500
36 Correct 23 ms 24528 KB n=500
37 Correct 24 ms 24528 KB n=500
38 Correct 24 ms 24540 KB n=500
39 Correct 21 ms 24552 KB n=500
40 Correct 21 ms 24568 KB n=500
41 Correct 34 ms 24584 KB n=500
42 Correct 20 ms 24636 KB n=500
43 Correct 20 ms 24636 KB n=500
44 Correct 20 ms 24636 KB n=500
45 Correct 24 ms 24640 KB n=500
46 Correct 24 ms 24648 KB n=500
47 Correct 20 ms 24664 KB n=500
48 Correct 24 ms 24680 KB n=500
49 Correct 23 ms 24692 KB n=500
50 Correct 24 ms 24708 KB n=500
51 Correct 24 ms 24720 KB n=500
52 Correct 24 ms 24736 KB n=500
53 Correct 26 ms 24752 KB n=500
54 Correct 24 ms 24768 KB n=500
55 Correct 24 ms 24780 KB n=278
56 Correct 24 ms 24868 KB n=500
57 Correct 24 ms 24868 KB n=500
58 Correct 25 ms 24868 KB n=500
59 Correct 28 ms 25340 KB n=2000
60 Correct 27 ms 25648 KB n=2000
61 Correct 29 ms 25648 KB n=2000
62 Correct 29 ms 25648 KB n=2000
63 Correct 28 ms 25648 KB n=2000
64 Correct 28 ms 25652 KB n=2000
65 Correct 24 ms 25708 KB n=2000
66 Correct 29 ms 25888 KB n=2000
67 Correct 29 ms 25888 KB n=2000
68 Correct 29 ms 25888 KB n=2000
69 Correct 30 ms 25928 KB n=2000
70 Correct 28 ms 25980 KB n=2000
71 Correct 28 ms 26032 KB n=2000
72 Correct 28 ms 26100 KB n=2000
73 Correct 29 ms 26200 KB n=2000
74 Correct 27 ms 26212 KB n=1844
75 Correct 28 ms 26336 KB n=2000
76 Correct 28 ms 26336 KB n=2000
77 Correct 28 ms 26364 KB n=2000
78 Correct 29 ms 26544 KB n=2000
79 Correct 28 ms 26544 KB n=2000
80 Correct 28 ms 26644 KB n=2000
81 Correct 29 ms 26644 KB n=2000
82 Correct 28 ms 26644 KB n=2000
83 Correct 28 ms 26804 KB n=2000
84 Correct 28 ms 26804 KB n=2000
85 Correct 30 ms 26804 KB n=2000
86 Correct 28 ms 26840 KB n=2000
87 Correct 28 ms 26896 KB n=2000
88 Correct 29 ms 27076 KB n=2000
89 Correct 28 ms 27132 KB n=2000
90 Correct 28 ms 27188 KB n=2000
91 Correct 25 ms 27188 KB n=2000
92 Correct 1384 ms 95268 KB n=200000
93 Correct 2374 ms 106384 KB n=200000
94 Correct 2275 ms 110044 KB n=200000
95 Correct 1362 ms 110044 KB n=200000
96 Correct 1375 ms 110044 KB n=200000
97 Correct 3121 ms 110044 KB n=200000
98 Correct 1421 ms 110044 KB n=200000
99 Correct 1573 ms 110044 KB n=200000
100 Correct 1368 ms 110044 KB n=200000
101 Correct 2664 ms 122436 KB n=200000
102 Correct 768 ms 122436 KB n=200000
103 Correct 877 ms 124868 KB n=200000
104 Correct 742 ms 127592 KB n=200000
105 Correct 800 ms 127592 KB n=200000
106 Correct 809 ms 127592 KB n=200000
107 Correct 814 ms 127592 KB n=200000
108 Correct 1305 ms 127592 KB n=200000
109 Correct 1354 ms 127592 KB n=200000
110 Correct 1098 ms 127592 KB n=200000
111 Correct 1412 ms 127592 KB n=200000
112 Correct 2746 ms 134040 KB n=200000
113 Correct 2866 ms 134040 KB n=200000
114 Correct 1197 ms 134040 KB n=200000
115 Correct 2202 ms 134040 KB n=200000
116 Correct 1212 ms 134040 KB n=200000
117 Correct 2901 ms 141708 KB n=200000
118 Correct 2844 ms 141708 KB n=200000
119 Correct 1268 ms 141708 KB n=200000
120 Correct 2707 ms 142476 KB n=200000
121 Correct 2687 ms 142476 KB n=200000
122 Correct 2165 ms 145680 KB n=200000
123 Correct 779 ms 145680 KB n=200000
124 Correct 434 ms 145680 KB n=25264