제출 #334912

#제출 시각아이디문제언어결과실행 시간메모리
334912amunduzbaevBirthday gift (IZhO18_treearray)C++14
30 / 100
2 ms620 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define ll long long #define ld long double #define pii pair<int, int> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define prc(n) fixed << setprecision(n) #define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pi acos(-1); const int inf = 1e9+7; const int N = 505; int n, m, q, a[N], tin[N], tout[N], l; vector<int>edges[N]; vector<int>order; vector<pii>tree; int t; int up[N][32]; void dfs(int u, int p){ tin[u] = ++t; up[u][0] = p; for(int i=1; i<=l; i++){ up[u][i] = up[up[u][i-1]][i-1]; } for(auto x:edges[u]){ if(x == p) continue; dfs(x, u); } tout[u] = ++t; } set<int>ar[N]; set<int>lc[N]; bool upper(int a, int b){ return tin[a] <= tin[b] && tout[a] >= tout[b]; } int lca(int a, int b){ if(upper(a, b)) return a; if(upper(b, a)) return b; for(int i=l; i>=0; i--){ if(!upper(up[a][i], b)) a = up[a][i]; } return up[a][0]; } void solve(){ cin>>n>>m>>q; for(int i=1;i<n;i++){ int a, b; cin>>a>>b; edges[a].pb(b); edges[b].pb(a); } l = 1; while((1<<l) <= n) l++; dfs(1, 1); for(int i=1;i<=m;i++){ cin>>a[i]; ar[a[i]].insert(i); } for(int i=1;i<m;i++){ lc[lca(a[i], a[i+1])].insert(i); } while(q--){ int t; cin>>t; if(t == 1){ int pos, val; cin>>pos>>val; ar[a[pos]].erase(pos); if(pos > 1){ lc[lca(a[pos], a[pos-1])].erase(pos-1); }if(pos < m){ lc[lca(a[pos+1], a[pos])].erase(pos); } a[pos] = val; if(pos > 1){ lc[lca(a[pos], a[pos-1])].insert(pos-1); }if(pos < m){ lc[lca(a[pos+1], a[pos])].insert(pos); } ar[a[pos]].insert(pos); } else{ int l, r, val; cin>>l>>r>>val; int la = -1, ra = -1; auto it = ar[val].lb(l); if(it != ar[val].end()){ if(*it <= r) la = ra = *it; } it = lc[val].lb(l); if(it != lc[val].end()){ if(*it < r) la = *it, ra = *it+1; } cout<<la<<" "<<ra<<"\n"; } } return; } int main(){ fastios int t = 1; //cin>>t; while(t--) solve(); 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...