Submission #831465

#TimeUsernameProblemLanguageResultExecution timeMemory
831465CookieBirthday gift (IZhO18_treearray)C++14
56 / 100
4037 ms36904 KiB
#include<bits/stdc++.h> #include<fstream> #pragma GCC optimize("Ofast,O3,unroll-loops") #pragma GCC target("avx2") using namespace std; //ifstream fin("FEEDING.INP"); //ofstream fout("FEEDING.OUT"); #define sz(a) (int)a.size() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const int base = 74; const int mxn = 2e5 + 5; int n, m, q; vt<int>adj[mxn + 1]; int dep[mxn + 1], up[mxn + 1][18], a[mxn + 1], tin[mxn + 1], tt = 0, tout[mxn + 1], inf = 1e9; void dfs(int s, int pre){ tin[s] = ++tt; for(auto i: adj[s]){ if(i != pre){ dep[i] = dep[s] + 1; dfs(i, s); up[i][0] = s; } } tout[s] = tt; } int lca(int u, int v){ if(dep[u] < dep[v])swap(u, v); int k = dep[u] - dep[v]; forr(i, 0, 18){ if(k & (1 << i)){ u = up[u][i]; } } if(u == v)return(u); dorr(i, 17, 0){ if(up[u][i] != up[v][i]){ u = up[u][i]; v = up[v][i]; } } return(up[u][0]); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> q; forr(i, 1, n){ int u, v; cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } for(int i = 1; i <= m; i++)cin >> a[i]; dfs(1, -1); forr(i, 1, 18){ for(int j = 1; j <= n; j++){ up[j][i] = up[up[j][i - 1]][i - 1]; } } while(q--){ int idq; cin >> idq; if(idq == 1){ int id, x; cin >> id >> x; a[id] = x; }else{ int l, r, v; cin >> l >> r >> v; int last = l, mn = inf, mx = -1, valmn = -1, valmx = -1; bool ok = 0; for(int i = l; i <= r; i++){ if(tin[a[i]] < tin[v] | tin[a[i]] > tout[v]){ mn = inf; mx = -1; valmn = -1; valmx = -1; continue; }else{ if(tin[a[i]] < mn){ mn = tin[a[i]]; valmn = i; }if(tin[a[i]] > mx){ mx = tin[a[i]]; valmx = i; } int cand = lca(a[valmn], a[valmx]); if(cand == v){ cout << min(valmn, valmx) << " " << max(valmn, valmx) << "\n"; ok = 1; break; } } } if(!ok)cout << -1 << " " << -1 << "\n"; } } return(0); }

Compilation message (stderr)

treearray.cpp: In function 'int main()':
treearray.cpp:75:30: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   75 |                 if(tin[a[i]] < tin[v] | tin[a[i]] > tout[v]){
      |                    ~~~~~~~~~~^~~~~~~~
treearray.cpp:72:17: warning: unused variable 'last' [-Wunused-variable]
   72 |             int last = l, mn = inf, mx = -1, valmn = -1, valmx = -1;
      |                 ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...