제출 #495887

#제출 시각아이디문제언어결과실행 시간메모리
495887IerusBirthday gift (IZhO18_treearray)C++17
0 / 100
0 ms332 KiB
#include<bits/stdc++.h> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; */ using namespace std; #pragma GCC optimize ("unroll-loops,Ofast,O3") #pragma GCC target("avx,avx2,fma") #define F first #define S second #define sz(x) (int)x.size() #define pb push_back #define eb emplace_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ; #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) //#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> typedef long long ll; const int E = 1e6+777; const long long inf = 1e18+777; const int N = 2022; const int MOD = 1e9+7; const int LG = 18; int n, m, que, a[N], timer; int tin[N], tout[N], up[N][LG+2]; vector<int> g[N]; void dfs(int v, int p){ tin[v] = ++timer; up[v][0] = p; for(int i = 1; i <= LG; ++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 upper(int v, int u){ return tin[v] <= tin[u] && tout[u] <= tout[v]; } int lca(int v, int u){ if(upper(v, u)) return v; if(upper(u, v)) return u; for(int i = LG; i >= 0; --i){ if(!upper(up[v][i], u)){ v = up[v][i]; } } return up[v][0]; } inline void update(int pos, int v){ a[pos] = v; } inline pair<int,int> get(int L, int R, int v){ if(sz(g[v]) == 1){ for(int i = L; i <= R; ++i) if(v == a[i]) return {i, i}; }else{ int Lv = g[v][1]; // cerr << "Lv: " << Lv << '\n'; for(int i = L; i < R; ++i){ if(upper(Lv, a[i]) && !upper(Lv, a[i+1]) && upper(v, a[i+1])){ return {i, i+1}; } } } return {-1, -1}; } int main(){NFS; cin >> n >> m >> que; for(int i = 1, u, v; i < n; ++i){ cin >> u >> v; g[u].pb(v); g[v].pb(u); } dfs(1, 1); for(int i = 1; i <= m; ++i){ cin >> a[i]; } for(int type,l,r,v; que--;){ cin >> type; if(type == 1){ cin >> l >> v; update(l, v); }else{ cin >> l >> r >> v; pair<int,int> res = get(l, r, v); cout << res.F << ' ' << res.S << '\n'; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...