# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1022421 | 2024-07-13T13:26:13 Z | hasan2006 | Birthday gift (IZhO18_treearray) | C++17 | 74 ms | 119636 KB |
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define se second #define fi first #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 5e5 + 9 , mod = 1e9 + 7; ll a[N] , b[N] , dp[N] , c[N] , d[N] , p[N][25] , us[N] , us1[N] , timer = 0; vector<int>v[N]; void dfs(int n , int par = 0){ p[n][0] = par; us[n] = ++timer; for(int i = 1; i <= 20; i++) p[n][i] = p[p[n][i - 1]][i - 1]; for(auto to : v[n]) if(to != par) dfs(to , n); us1[n] = ++timer; } bool ok(int x , int y){ return (us[x] <= us[y] && us1[x] >= us1[y]); } ll lca(ll x , ll y){ if(ok(x , y)) return x; if(ok(y , x)) return y; for(int i = 20; i >= 0; i--) if(p[x][i] && !ok(p[x][i] , y)) x = p[x][i]; return p[x][0]; } set<int>st[N] , ss[N]; void solve() { ll n , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mn = 1e18, mx = 0 ; cin>>n>>m>>q; for(i = 1; i < n; i++){ cin>>l>>r; v[l].pb(r); v[r].pb(l); } dfs(1); for(i = 1; i <= m; i++){ cin>>a[i]; ss[a[i]].insert(i); if(i != 1) b[i] = lca(a[i] , a[i - 1]) , st[b[i]].insert(i); } while(q--){ cin>>k>>x>>y; if(k == 1){ ss[a[x]].erase(x); a[x] = y; ss[a[x]].insert(x); if(x != m){ st[b[x + 1]].erase(x + 1); b[x + 1] = lca(a[x + 1], a[x]); st[b[x + 1]].insert(x + 1); } if(x != 1){ st[b[x]].erase(x); b[x] = lca(a[x - 1], a[x]); st[b[x]].insert(x); } }else { cin>>k; auto it = st[k].upper_bound(x); if(it != st[k].end() && *it <= y){ cout<<*it - 1 << " "<<*it<<"\n"; continue; } auto it1 = ss[k].upper_bound(x - 1); if(it1 != ss[k].end() && *it1 <= y){ cout<<*it1 << " "<<*it1<<"\n"; continue; } cout<<-1<<" "<<-1<<"\n"; } } } int main(){ TL; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin>>t; while(t--) { solve(); } } // Author : حسن
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 74 ms | 119636 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 74 ms | 119636 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 74 ms | 119636 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Runtime error | 74 ms | 119636 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |