Submission #207440

# Submission time Handle Problem Language Result Execution time Memory
207440 2020-03-07T14:40:09 Z mohamedsobhi777 Birthday gift (IZhO18_treearray) C++14
0 / 100
7 ms 4984 KB
#include<bits/stdc++.h> 
 
using namespace std ;

const int N = 2e5 + 7 ; 

int n , t , m, q; 
vector<int> adj[N] ; 

vector<int> path; 
int st[N] , en[N] ; 
int a[N] , lcaA[N]; 
int col[N] , up[N][24]; 

int isp(int x , int y )
{
    return (st[y]>=st[x] &&  en[y] <=en[x]);
}

void dfs(int x , int p)
{   
    st[x] = t++ ; 
    path.push_back(x);
    up[x][0] = p ; 
    for(int i = 1 ; i < 24 ; i++)
        up[x][i] = up[ up[x][i-1] ][i-1];
    for(auto u : adj[x])
    {       
        if(u==p)
        continue;
        dfs(u , x) ; 
    }
    en[x] = t++; 
    path.push_back(x) ; 
}

bool inside(int L, int R , int l , int r)
{
    return (l>=L && l<=R && r>=L && r<=R);
}

int lca(int x , int y)
{
    if(isp(x , y))
        return x ; 
    if(isp(y , x))
        return y ; 
    for(int i = 23 ; i>=0 ; i--)
    {
        if(!isp(up[x][i] , y))
            x = up[x][i] ; 
    }
    return up[x][0] ; 
}


int main() 
{
    freopen("in.in" , "r" , stdin) ; 
    cin>>n>>m>>q; 
    for(int i = 0 ; i < n-1 ; i++)
    {
        int a, b ; 
        cin>>a>>b ; 
        adj[a].push_back(b) ; 
        adj[b].push_back(a) ; 
    }
    dfs(1 , 1) ; 
    for(int i = 0 ; i<m ; i++)
    {
        cin>>a[i] ; 
        if(i) 
         lcaA[i] = lca(a[i] , a[i-1] ) ; 
    }
    while(q--)
    {
        int idx , A , B; 
        cin>>idx>>A>>B ; 

        if(idx==1)
        {
            a[A-1] = B; 
            if(A>1)
              lcaA[A-1] = lca(a[A-1] , lcaA[A-2]) ; 
            if(A<m)
                lcaA[A] = lca(a[A] , a[A-1]) ;
        }
        else
        {
            int C; 
            cin>>C ; 
            int l = st[C] , r = en[C] ;  
            int nodeA = -2 , nodeB = -2;
            if(a[A-1]==C)
                nodeA = nodeB = A-1 ; 
            for(int i = A ; i<=B-1 ;i++)
            {
                if(lcaA[i]==C)
                {
                    nodeA = i-1 ;  
                    nodeB = i;
                    break; 
                }
                if(a[i]==C)
                {
                    nodeA = i ; 
                    nodeB = i ; 
                    break;
                }
            }
            
            cout<<nodeA+1<<" " <<nodeB+1<<"\n" ; 
        }
        
    }
    return 0 ;  
}

Compilation message

treearray.cpp: In function 'int main()':
treearray.cpp:92:17: warning: unused variable 'l' [-Wunused-variable]
             int l = st[C] , r = en[C] ;  
                 ^
treearray.cpp:92:29: warning: unused variable 'r' [-Wunused-variable]
             int l = st[C] , r = en[C] ;  
                             ^
treearray.cpp:59:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("in.in" , "r" , stdin) ; 
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4984 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4984 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4984 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 4984 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -