제출 #865733

#제출 시각아이디문제언어결과실행 시간메모리
865733vjudge1Birthday gift (IZhO18_treearray)C++17
100 / 100
668 ms77328 KiB
//gm --- akezhon #include <bits/stdc++.h> //#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ll long long #define pb push_back #define F first #define S second #define all(v) v.begin(),v.end() #define pii pair<int,int> #define tm (tl+tr)/2 #define TL v+v, tl, tm #define TR v+v+1, tm+1, tr #define DA l <= tl && tr <= r #define NET r < tl || tr < l #define double long double using namespace std; const int N=2e5+7; const int M=1e9+7; const int inf=1e9; vector <int> g[N]; int tin[N], tout[N], timer; int up[N][20]; int n, m, q; int a[N]; void dfs(int v=1, int p=1){ 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 is(int a, int b){ return tin[a] <= tin[b] && tout[b] <= tout[a]; } int lca(int a, int b){ if(is(a, b))return a; if(is(b, a))return b; for(int i=18; i >= 0; i--){ if(!is(up[a][i], b))a=up[a][i]; } return up[a][0]; } set <int> pos1[N], pos2[N]; void AlemAmenov(){ cin >> n >> m >> q; for(int i=1; i < n; i++){ int x, y; cin >> x >> y; g[x].pb(y); g[y].pb(x); } dfs(); for(int i=1; i <= m; i++){ cin >> a[i]; pos1[a[i]].insert(i); if(1 < i)pos2[lca(a[i], a[i-1])].insert(i-1); } while(q--){ int t, pos, l, r, v; cin >> t; if(t == 1){ cin >> pos >> v; pos1[a[pos]].erase(pos); pos1[v].insert(pos); if(1 < pos){ pos2[lca(a[pos-1], a[pos])].erase(pos-1); pos2[lca(a[pos-1], v)].insert(pos-1); } if(pos < m){ pos2[lca(a[pos+1], a[pos])].erase(pos); pos2[lca(a[pos+1], v)].insert(pos); } a[pos] = v; } else { cin >> l >> r >> v; pos = *pos1[v].lower_bound(l); if(l <= pos && pos <= r)cout << pos << ' ' << pos << '\n'; else { pos = *pos2[v].lower_bound(l); if(l <= pos && pos < r)cout << pos << ' ' << pos+1 << '\n'; else cout << "-1 -1\n"; } } } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("promote.in", "r", stdin); // freopen("promote.out", "w", stdout); int RealName=1; // cin >> RealName; // int C=0; while(RealName--){ // cout << "Case " << ++C << ":\n"; AlemAmenov(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...