제출 #379336

#제출 시각아이디문제언어결과실행 시간메모리
379336balbitBirthday gift (IZhO18_treearray)C++14
56 / 100
24 ms24300 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define y1 zck_is_king
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define REP(i,n) for (int i = 0; i<n; ++i)
#define RREP(i,n) for (int i = n-1; i>=0; --i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 1e5+5;

int par[maxn], skip[maxn], dep[maxn];

vector<int> g[maxn];

void dfs(int v, int p) {
    if (p != -1) {
        dep[v] = dep[p] + 1;
        par[v] = p;
        if (dep[skip[skip[p]]] - dep[skip[p]] == dep[skip[p]] - dep[p]) {
            skip[v] = skip[skip[p]];
        }else{
            skip[v] = p;
        }
    }
    for (int u : g[v]) {
        if (u!=p) dfs(u,v);
    }
}

int lca(int a, int b) {
    if (dep[a] < dep[b]) {
        swap(a,b);
    }
    while (dep[a] > dep[b]) {
        if (dep[skip[a]]>=dep[b]) a = skip[a];
        else a = par[a];
    }
    if (a == b) return a;
    while (par[a] != par[b]) {
        if (skip[a] != skip[b]) {
            a=skip[a]; b = skip[b];
        }else{
            a=par[a]; b = par[b];
        }
    }
    return par[a];
}

int a[maxn];

set<int> where2[maxn], where1[maxn];



signed main(){
    IOS();
    int n,m,q; cin>>n>>m>>q;
    REP(i,n-1) {
        int a,b; cin>>a>>b; --a; --b;
        g[a].pb(b); g[b].pb(a);
    }
    dfs(0,-1);
//    REP(i,q){
//        int a,b; cin>>a>>b;
//        cout<<lca(a-1,b-1)+1<<endl;
//    }
    REP(i,m) {
        cin>>a[i]; --a[i];
        where1[a[i]].insert(i);
        if (i)
            where2[lca(a[i], a[i-1])].insert(i-1);
    }
    REP(x,q) {
        int tp; cin>>tp;
        if (tp == 1) {
            int i,v; cin>>i>>v; --v; --i;
            where1[a[i]].erase(i);
            if (i-1>=0)
                where2[lca(a[i], a[i-1])].erase(i-1);
            if (i+1<m)
                where2[lca(a[i], a[i+1])].erase(i);
            a[i] = v;
            where1[a[i]].insert(i);
            if (i-1>=0)
                where2[lca(a[i], a[i-1])].insert(i-1);
            if (i+1<m)
                where2[lca(a[i], a[i+1])].insert(i);
        }else{
            int l,r,v; cin>>l>>r>>v; --v;
            auto it = where1[v].lower_bound(l-1);
            if (it!=where1[v].end() && *it <= r-1) {
                cout<<*it+1<<' '<<*it+1<<endl; continue;
            }
            it = where2[v].lower_bound(l-1);
            bug(l-1, *it);
            if (it!=where2[v].end() && *it < r-1) {
                cout<<*it+1<<' '<<*it+2<<endl; continue;
            }
            cout<<-1<<' '<<-1<<endl;
        }
    }

}

/*
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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...