Submission #879000

# Submission time Handle Problem Language Result Execution time Memory
879000 2023-11-26T04:33:55 Z imarn Birthday gift (IZhO18_treearray) C++14
0 / 100
7 ms 25948 KB
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
#define sz(x) (int)x.size()
#define pii pair<ll,ll>
using namespace std;
const int N=2e5+5;
vector<int>g[N];
int pr[N][20],dep[N]{0};
void dfs(int u,int p,int l){
    dep[u]=l;pr[u][0]=p;
    for(int i=1;i<20;i++)pr[u][i]=pr[pr[u][i-1]][i-1];
    for(auto v:g[u]){
        if(v==p)continue;
        dfs(v,u,l+1);
    }
}
int lca(int a,int b){
    if(dep[a]>dep[b])swap(a,b);
    for(int i=19;i>=0;i--)if(dep[b]-(1<<i)>=dep[a])b=pr[b][i];
    if(a==b)return a;
    for(int i=19;i>=0;i--)if(pr[a][i]!=pr[b][i])a=pr[a][i],b=pr[b][i];
    return pr[a][0];
}
set<int>d[N],dd[N];
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n,m,q;cin>>n>>m>>q;
    for(int i=1,u,v;i<=n-1;i++)cin>>u>>v,g[u].pb(v),g[v].pb(u);
    dfs(1,1,0);int v[m+1];
    for(int i=1;i<=n;i++)d[i].insert(1e9),dd[i].insert(1e9);
    for(int i=1;i<=m;i++)cin>>v[i],dd[v[i]].insert(i);
    for(int i=1;i<=m-1;i++)d[lca(v[i],v[i+1])].insert(i);
    while(q--){
        int o;cin>>o;
        if(o==1){
            int p,x;cin>>p>>x;
            dd[v[p]].erase(dd[v[p]].lower_bound(p));
            dd[x].insert(p);
            if(p<m){
                int u = lca(v[p],v[p+1]);
                d[u].erase(d[u].lower_bound(p));
                u = lca(x,v[p+1]);
                d[u].insert(p);
            }
            if(p>1){
                int u = lca(v[p-1],v[p]);
                d[u].erase(d[u].lower_bound(p-1));
                u = lca(v[p-1],x);
                d[u].insert(p-1);
            }v[p]=x;
        }
        else {
            int l,r,v;cin>>l>>r>>v;
            auto x = dd[v].lower_bound(l);
            if(*x<=r){cout<<0<<" "<<0<<'\n';continue;}
            x = d[v].lower_bound(l);
            if(*x>r)cout<<0<<" "<<0<<'\n';
            else cout<<0<<" "<<0<<'\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 25948 KB Wrong output format.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 25948 KB Wrong output format.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 25948 KB Wrong output format.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 25948 KB Wrong output format.
2 Halted 0 ms 0 KB -