Submission #334835

# Submission time Handle Problem Language Result Execution time Memory
334835 2020-12-10T05:01:41 Z juggernaut Birthday gift (IZhO18_treearray) C++14
0 / 100
17 ms 23916 KB
#include<bits/stdc++.h>
using namespace std;
int n,m,q,a[200005],up[200005][18],tin[200005],tout[200005],timer;
vector<int>g[200005];
set<int>lc[200005],ar[200005];
set<int>::iterator it;
void dfs(int v,int p){
    tin[v]=++timer;
    up[v][0]=p;
    for(int i=1;i<18;i++)up[v][i]=up[up[v][i-1]][i-1];
    for(int to:g[v])if(to!=p)dfs(to,v);
    tout[v]=++timer;
}
bool upper(int a,int b){
    return tin[a]<=tin[b]&&tout[a]>=tout[b];
}
int lca(int a,int b){
    if(upper(a,b))return a;
    if(upper(b,a))return b;
    for(int i=17;i>=0;i--)
        if(!upper(up[a][i],b))a=up[a][i];
    return up[a][0];
}
int main(){
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<n;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1,1);
    for(int i=1;i<=m;i++){
        scanf("%d",&a[i]);
        ar[a[i]].insert(i);
    }
    for(int i=1;i<m;i++)
        lc[lca(a[i],a[i+1])].insert(i);
    while(q--){
        int type;
        scanf("%d",&type);
        if(type&1){
            int pos,val;
            scanf("%d%d",&pos,&val);
            ar[a[pos]].erase(pos);
            if(pos>1)
                lc[lca(a[pos],a[pos-1])].erase(pos-1);
            if(pos<m)
                lc[lca(a[pos],a[pos+1])].erase(pos);
            a[pos]=val;
            if(pos>1)
                lc[lca(a[pos],a[pos-1])].insert(pos-1);
            if(pos<m)
                lc[lca(a[pos],a[pos+1])].insert(pos);
            ar[a[pos]].insert(pos);
        }else{
            int l,r,v,al=-1,arr=-1;
            scanf("%d%d%d",&l,&r,&v);
            //Case al=arr
            it=ar[v].lower_bound(l);
            if(it!=ar[v].end())
                if(*it<=r)al=arr=*it;
            //Case al+1=arr
            it=lc[v].lower_bound(l);
            if(it!=lc[v].end())
                if(*it<=r)al=*it,arr=al+1;
            cout<<al<<" "<<arr<<"\n";
        }
    }
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     scanf("%d%d%d",&n,&m,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
treearray.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
treearray.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
treearray.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   41 |         scanf("%d",&type);
      |         ~~~~~^~~~~~~~~~~~
treearray.cpp:44:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |             scanf("%d%d",&pos,&val);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
treearray.cpp:58:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |             scanf("%d%d%d",&l,&r,&v);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=5
2 Correct 16 ms 23808 KB n=100
3 Correct 17 ms 23788 KB n=100
4 Correct 17 ms 23788 KB n=100
5 Correct 17 ms 23788 KB n=100
6 Correct 17 ms 23916 KB n=100
7 Correct 16 ms 23788 KB n=100
8 Correct 17 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 17 ms 23788 KB n=100
11 Correct 17 ms 23788 KB n=100
12 Incorrect 16 ms 23788 KB Wrong output format.
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=5
2 Correct 16 ms 23808 KB n=100
3 Correct 17 ms 23788 KB n=100
4 Correct 17 ms 23788 KB n=100
5 Correct 17 ms 23788 KB n=100
6 Correct 17 ms 23916 KB n=100
7 Correct 16 ms 23788 KB n=100
8 Correct 17 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 17 ms 23788 KB n=100
11 Correct 17 ms 23788 KB n=100
12 Incorrect 16 ms 23788 KB Wrong output format.
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=5
2 Correct 16 ms 23808 KB n=100
3 Correct 17 ms 23788 KB n=100
4 Correct 17 ms 23788 KB n=100
5 Correct 17 ms 23788 KB n=100
6 Correct 17 ms 23916 KB n=100
7 Correct 16 ms 23788 KB n=100
8 Correct 17 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 17 ms 23788 KB n=100
11 Correct 17 ms 23788 KB n=100
12 Incorrect 16 ms 23788 KB Wrong output format.
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23788 KB n=5
2 Correct 16 ms 23808 KB n=100
3 Correct 17 ms 23788 KB n=100
4 Correct 17 ms 23788 KB n=100
5 Correct 17 ms 23788 KB n=100
6 Correct 17 ms 23916 KB n=100
7 Correct 16 ms 23788 KB n=100
8 Correct 17 ms 23788 KB n=100
9 Correct 16 ms 23788 KB n=100
10 Correct 17 ms 23788 KB n=100
11 Correct 17 ms 23788 KB n=100
12 Incorrect 16 ms 23788 KB Wrong output format.
13 Halted 0 ms 0 KB -