Submission #542352

# Submission time Handle Problem Language Result Execution time Memory
542352 2022-03-26T09:05:37 Z krit3379 Birthday gift (IZhO18_treearray) C++14
0 / 100
7 ms 10196 KB
#include<bits/stdc++.h>
using namespace std;
#define N 200005

struct A{
    int v,l,r;
    bool operator<(const A& o)const{
        if(v!=o.v)return v<o.v;
        if(l!=o.l)return l<o.l;
        return r<o.r;
    }
};

int dep[N],bp[20][N],val[N];
vector<int> g[N];
multiset<A> s;

void dfs(int s,int f){
    dep[s]=dep[f]+1;
    bp[0][s]=f;
    for(auto x:g[s])if(x!=f)dfs(x,s);
}

int lca(int a,int b){
    if(dep[a]>dep[b])swap(a,b);
    int i,dif=dep[b]-dep[a];
    for(i=0;i<20;i++)if(dif&(1<<i))b=bp[i][b];
    if(a==b)return a;
    for(i=19;i>=0;i--)if(bp[i][a]!=bp[i][b]){
        a=bp[i][a];
        b=bp[i][b];
    }
    return bp[0][a];
}

int main(){
    int n,m,q,i,j,a,b,op,pos,v,l,r;
    scanf("%d %d %d",&n,&m,&q);
    for(i=1;i<n;i++){
        scanf("%d %d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(i=1;i<=m;i++)scanf("%d",&val[i]),s.insert({val[i],i,i});
    dfs(1,0);
    for(i=1;i<20;i++)for(j=1;j<=n;j++)bp[i][j]=bp[i-1][bp[i-1][j]];
    for(i=2;i<=n;i++)s.insert({lca(val[i],val[i-1]),i-1,i});
    while(q--){
        scanf("%d",&op);
        if(op==1){
            scanf("%d %d",&pos,&v);
            s.erase(s.find({val[pos],pos,pos}));
            if(pos>1)s.erase(s.find({lca(val[pos],val[pos-1]),pos-1,pos}));
            if(pos<m)s.erase(s.find({lca(val[pos],val[pos+1]),pos,pos+1}));
            val[pos]=v;
            s.insert({val[pos],pos,pos});
            if(pos>1)s.insert({lca(val[pos],val[pos-1]),pos-1,pos});
            if(pos<m)s.insert({lca(val[pos],val[pos+1]),pos,pos+1});
        }
        else{
            scanf("%d %d %d",&l,&r,&v);
            auto it=s.lower_bound({v,l,-1});
            A x=*it;
            if(x.v==v&&l<=x.l&&x.r<=r)printf("%d %d\n",x.l,x.r);
            else printf("-1 -1\n");
        }
    }
    return 0;
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d %d %d",&n,&m,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
treearray.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
treearray.cpp:44:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     for(i=1;i<=m;i++)scanf("%d",&val[i]),s.insert({val[i],i,i});
      |                      ~~~~~^~~~~~~~~~~~~~
treearray.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         scanf("%d",&op);
      |         ~~~~~^~~~~~~~~~
treearray.cpp:51:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |             scanf("%d %d",&pos,&v);
      |             ~~~~~^~~~~~~~~~~~~~~~~
treearray.cpp:61:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |             scanf("%d %d %d",&l,&r,&v);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB n=5
2 Correct 4 ms 5136 KB n=100
3 Correct 3 ms 5076 KB n=100
4 Correct 3 ms 5076 KB n=100
5 Correct 4 ms 5076 KB n=100
6 Correct 3 ms 5076 KB n=100
7 Correct 4 ms 5076 KB n=100
8 Correct 3 ms 5076 KB n=100
9 Correct 3 ms 5076 KB n=100
10 Correct 3 ms 5076 KB n=100
11 Correct 3 ms 5132 KB n=100
12 Correct 3 ms 5076 KB n=100
13 Correct 3 ms 5076 KB n=100
14 Correct 3 ms 5076 KB n=100
15 Correct 3 ms 5076 KB n=100
16 Correct 4 ms 5136 KB n=100
17 Correct 3 ms 5076 KB n=100
18 Correct 3 ms 5076 KB n=100
19 Correct 3 ms 5076 KB n=100
20 Correct 3 ms 5076 KB n=100
21 Correct 3 ms 5076 KB n=100
22 Correct 3 ms 5076 KB n=100
23 Correct 3 ms 5076 KB n=100
24 Correct 3 ms 5076 KB n=100
25 Correct 3 ms 5076 KB n=100
26 Runtime error 7 ms 10196 KB Execution killed with signal 6
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB n=5
2 Correct 4 ms 5136 KB n=100
3 Correct 3 ms 5076 KB n=100
4 Correct 3 ms 5076 KB n=100
5 Correct 4 ms 5076 KB n=100
6 Correct 3 ms 5076 KB n=100
7 Correct 4 ms 5076 KB n=100
8 Correct 3 ms 5076 KB n=100
9 Correct 3 ms 5076 KB n=100
10 Correct 3 ms 5076 KB n=100
11 Correct 3 ms 5132 KB n=100
12 Correct 3 ms 5076 KB n=100
13 Correct 3 ms 5076 KB n=100
14 Correct 3 ms 5076 KB n=100
15 Correct 3 ms 5076 KB n=100
16 Correct 4 ms 5136 KB n=100
17 Correct 3 ms 5076 KB n=100
18 Correct 3 ms 5076 KB n=100
19 Correct 3 ms 5076 KB n=100
20 Correct 3 ms 5076 KB n=100
21 Correct 3 ms 5076 KB n=100
22 Correct 3 ms 5076 KB n=100
23 Correct 3 ms 5076 KB n=100
24 Correct 3 ms 5076 KB n=100
25 Correct 3 ms 5076 KB n=100
26 Runtime error 7 ms 10196 KB Execution killed with signal 6
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB n=5
2 Correct 4 ms 5136 KB n=100
3 Correct 3 ms 5076 KB n=100
4 Correct 3 ms 5076 KB n=100
5 Correct 4 ms 5076 KB n=100
6 Correct 3 ms 5076 KB n=100
7 Correct 4 ms 5076 KB n=100
8 Correct 3 ms 5076 KB n=100
9 Correct 3 ms 5076 KB n=100
10 Correct 3 ms 5076 KB n=100
11 Correct 3 ms 5132 KB n=100
12 Correct 3 ms 5076 KB n=100
13 Correct 3 ms 5076 KB n=100
14 Correct 3 ms 5076 KB n=100
15 Correct 3 ms 5076 KB n=100
16 Correct 4 ms 5136 KB n=100
17 Correct 3 ms 5076 KB n=100
18 Correct 3 ms 5076 KB n=100
19 Correct 3 ms 5076 KB n=100
20 Correct 3 ms 5076 KB n=100
21 Correct 3 ms 5076 KB n=100
22 Correct 3 ms 5076 KB n=100
23 Correct 3 ms 5076 KB n=100
24 Correct 3 ms 5076 KB n=100
25 Correct 3 ms 5076 KB n=100
26 Runtime error 7 ms 10196 KB Execution killed with signal 6
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB n=5
2 Correct 4 ms 5136 KB n=100
3 Correct 3 ms 5076 KB n=100
4 Correct 3 ms 5076 KB n=100
5 Correct 4 ms 5076 KB n=100
6 Correct 3 ms 5076 KB n=100
7 Correct 4 ms 5076 KB n=100
8 Correct 3 ms 5076 KB n=100
9 Correct 3 ms 5076 KB n=100
10 Correct 3 ms 5076 KB n=100
11 Correct 3 ms 5132 KB n=100
12 Correct 3 ms 5076 KB n=100
13 Correct 3 ms 5076 KB n=100
14 Correct 3 ms 5076 KB n=100
15 Correct 3 ms 5076 KB n=100
16 Correct 4 ms 5136 KB n=100
17 Correct 3 ms 5076 KB n=100
18 Correct 3 ms 5076 KB n=100
19 Correct 3 ms 5076 KB n=100
20 Correct 3 ms 5076 KB n=100
21 Correct 3 ms 5076 KB n=100
22 Correct 3 ms 5076 KB n=100
23 Correct 3 ms 5076 KB n=100
24 Correct 3 ms 5076 KB n=100
25 Correct 3 ms 5076 KB n=100
26 Runtime error 7 ms 10196 KB Execution killed with signal 6
27 Halted 0 ms 0 KB -