Submission #314218

#TimeUsernameProblemLanguageResultExecution timeMemory
314218TricksterBirthday gift (IZhO18_treearray)C++14
100 / 100
2182 ms82680 KiB
#include <bits/stdc++.h> #include <algorithm> #include <string.h> #include <iostream> #include <stdio.h> #include <vector> #include <queue> #include <cmath> #include <set> #include <map> using namespace std; #define N 200010 #define ff first #define ss second #define ll long long #define pb push_back #define mod 1000000007 #define pii pair <int, int> #define sz(a) int(a.size()) #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;} set <pii> S[N]; int n, m, q, a, b; vector <int> E[N]; int L[N], Pr[N][30], v[N]; void dfs(int nd, int pr) { L[nd] = L[pr] + 1; Pr[nd][0] = pr; for(auto i: E[nd]) if(i != pr) dfs(i, nd); } int lca(int a, int b) { if(L[a] < L[b]) swap(a, b); for(int i = 20; i >= 0; i--) if(L[a] - (1<<i) >= L[b]) a = Pr[a][i]; if(a == b) return a; for(int i = 20; i >= 0; i--) if(Pr[a][i] != Pr[b][i]) a = Pr[a][i], b = Pr[b][i]; return Pr[a][0]; } int main() { cin >> n >> m >> q; for(int i = 1; i < n; i++) { cin >> a >> b; E[a].pb(b); E[b].pb(a); } dfs(1, 0); for(int i = 1; (1<<i) <= n; i++) for(int h = 1; h <= n; h++) Pr[h][i] = Pr[Pr[h][i-1]][i-1]; for(int i = 1; i <= m; i++) cin >> v[i]; for(int i = 1; i < m; i++) S[lca(v[i], v[i+1])].insert({i, 1}); for(int i = 1; i <= m; i++) S[v[i]].insert({i, 0}); while(q--) { int tp; cin >> tp; if(tp == 1) { int pos, x; cin >> pos >> x; if(pos != 1) { int Lca = lca(v[pos-1], v[pos]); S[Lca].erase({pos-1, 1}); Lca = lca(v[pos-1], x); S[Lca].insert({pos-1, 1}); } if(pos != n) { int Lca = lca(v[pos+1], v[pos]); S[Lca].erase({pos, 1}); Lca = lca(v[pos+1], x); S[Lca].insert({pos, 1}); } S[v[pos]].erase({pos, 0}); v[pos] = x; S[v[pos]].insert({pos, 0}); } else { int l, r, x; cin >> l >> r >> x; pii in = *S[x].lower_bound({l, 0}); if(in.ff+in.ss <= r && in.ff >= l) cout << in.ff << " " << in.ff+in.ss << "\n"; else cout << "-1 -1\n"; } } } /* 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 */

Compilation message (stderr)

treearray.cpp:23: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
   23 | #pragma GCC optimization ("O3")
      | 
treearray.cpp:24: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
   24 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...