Submission #922915

# Submission time Handle Problem Language Result Execution time Memory
922915 2024-02-06T09:21:10 Z Aiperiii Birthday gift (IZhO18_treearray) C++14
0 / 100
2 ms 7784 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=2e5+5;
vector <int> g[N];
int p[N],d[N],jmp[N][20];
void dfs(int v,int par){
   p[v]=par;
   for(auto to : g[v]){
      if(to!=par){
         d[to]=d[v]+1;
         dfs(to,v);
      }
   }
}
int lca(int a,int b){
   if(d[a]<d[b])swap(a,b);
   for(int i=19;i>=0;i--){
      if(d[jmp[a][i]]>=d[b]){
         a=jmp[a][i];
      }
   }
   if(a==b)return a;
   for(int i=19;i>=0;i--){
      if(jmp[a][i]!=jmp[b][i]){
         a=jmp[a][i];
         b=jmp[b][i];
      }
   }
   return p[a];
}
signed main(){
   ios_base::sync_with_stdio();
   cin.tie(0);cout.tie(0);
   int n,m,q;
   cin>>n>>m>>q;
   for(int i=0;i<n-1;i++){
      int u,v;
      cin>>u>>v;
      g[u].pb(v);g[v].pb(u);
   }
   dfs(1,1);
   for(int i=1;i<=n;i++){
      jmp[i][0]=p[i];
   }
   for(int i=1;i<20;i++){
      for(int j=1;j<=n;j++){
         jmp[j][i]=jmp[jmp[j][i-1]][i-1];
      }
   }
   vector <int> a(m+1);
   for(int i=1;i<=m;i++)cin>>a[i];
   set <int> pairs[n+1],ver[n+1];
      
      for(int i=1;i<m;i++){
         pairs[lca(a[i],a[i+1])].insert(i);
         ver[a[i]].insert(i);
      }
   while(q--){
     int type,l,r,v,pos;
     cin>>type;
     if(type==1){
        cin>>pos>>v;
        ver[a[pos]].erase(pos);
        ver[v].insert(pos);
        if(pos+1<=m){
           pairs[lca(a[pos],a[pos+1])].erase(pos);
           pairs[lca(v,a[pos+1])].insert(pos);
        }
        if(pos-1>=1){
           pairs[lca(a[pos-1],a[pos])].erase(pos-1);
           pairs[lca(a[pos-1],v)].insert(pos-1);
        }
        a[pos]=v;
     }
     else{
        cin>>l>>r>>v;
        int L=-1,R=-1;
        auto it=pairs[v].lower_bound(l);
        if(it!=pairs[v].end() && *it+1<=r && *it>=l){
           L=*it;R=*it+1;
        }
        it=ver[v].lower_bound(l);
        if(it!=ver[v].end() && *it<=r && *it>=l){
           L=*it;R=*it;
        }
        cout<<L<<" "<<R<<"\n";
     }
  }
}
 
/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
 */
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB n=5
2 Correct 2 ms 7772 KB n=100
3 Correct 2 ms 7772 KB n=100
4 Correct 2 ms 7772 KB n=100
5 Correct 2 ms 7784 KB n=100
6 Correct 2 ms 7772 KB n=100
7 Correct 2 ms 7772 KB n=100
8 Correct 2 ms 7772 KB n=100
9 Correct 2 ms 7772 KB n=100
10 Correct 2 ms 7768 KB n=100
11 Correct 2 ms 7768 KB n=100
12 Correct 2 ms 7772 KB n=100
13 Correct 2 ms 7768 KB n=100
14 Correct 2 ms 7772 KB n=100
15 Correct 2 ms 7772 KB n=100
16 Correct 2 ms 7772 KB n=100
17 Incorrect 2 ms 7772 KB Jury has the answer but participant has not
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB n=5
2 Correct 2 ms 7772 KB n=100
3 Correct 2 ms 7772 KB n=100
4 Correct 2 ms 7772 KB n=100
5 Correct 2 ms 7784 KB n=100
6 Correct 2 ms 7772 KB n=100
7 Correct 2 ms 7772 KB n=100
8 Correct 2 ms 7772 KB n=100
9 Correct 2 ms 7772 KB n=100
10 Correct 2 ms 7768 KB n=100
11 Correct 2 ms 7768 KB n=100
12 Correct 2 ms 7772 KB n=100
13 Correct 2 ms 7768 KB n=100
14 Correct 2 ms 7772 KB n=100
15 Correct 2 ms 7772 KB n=100
16 Correct 2 ms 7772 KB n=100
17 Incorrect 2 ms 7772 KB Jury has the answer but participant has not
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB n=5
2 Correct 2 ms 7772 KB n=100
3 Correct 2 ms 7772 KB n=100
4 Correct 2 ms 7772 KB n=100
5 Correct 2 ms 7784 KB n=100
6 Correct 2 ms 7772 KB n=100
7 Correct 2 ms 7772 KB n=100
8 Correct 2 ms 7772 KB n=100
9 Correct 2 ms 7772 KB n=100
10 Correct 2 ms 7768 KB n=100
11 Correct 2 ms 7768 KB n=100
12 Correct 2 ms 7772 KB n=100
13 Correct 2 ms 7768 KB n=100
14 Correct 2 ms 7772 KB n=100
15 Correct 2 ms 7772 KB n=100
16 Correct 2 ms 7772 KB n=100
17 Incorrect 2 ms 7772 KB Jury has the answer but participant has not
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB n=5
2 Correct 2 ms 7772 KB n=100
3 Correct 2 ms 7772 KB n=100
4 Correct 2 ms 7772 KB n=100
5 Correct 2 ms 7784 KB n=100
6 Correct 2 ms 7772 KB n=100
7 Correct 2 ms 7772 KB n=100
8 Correct 2 ms 7772 KB n=100
9 Correct 2 ms 7772 KB n=100
10 Correct 2 ms 7768 KB n=100
11 Correct 2 ms 7768 KB n=100
12 Correct 2 ms 7772 KB n=100
13 Correct 2 ms 7768 KB n=100
14 Correct 2 ms 7772 KB n=100
15 Correct 2 ms 7772 KB n=100
16 Correct 2 ms 7772 KB n=100
17 Incorrect 2 ms 7772 KB Jury has the answer but participant has not
18 Halted 0 ms 0 KB -