Submission #909417

#TimeUsernameProblemLanguageResultExecution timeMemory
909417penguin133Birthday gift (IZhO18_treearray)C++17
56 / 100
4013 ms89176 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, m, q; vector <int> adj[300005]; multiset <int> ms[300005]; int S[300005], E[300005], cnt = 1, par[20][200005], dep[200005]; void dfs(int x, int p, int d){ S[x] = cnt++; par[0][x] = p; dep[x] = d; for(auto i : adj[x])if(i != p)dfs(i, x, d + 1); E[x] = cnt - 1; } int lca(int u, int v){ if(dep[u] > dep[v])swap(u, v); int df = dep[v] - dep[u]; for(int i=0;i<19;i++)if(df >> i & 1)v = par[i][v]; if(u == v)return u; for(int i=19;i>=0;i--){ if(par[i][u] != par[i][v])u = par[i][u], v = par[i][v]; } return par[0][u]; } int back[300005]; struct node{ int s, e, m, mn, mx; node *l, *r; node(int _s, int _e){ s = _s, e = _e, m = (s + e) >> 1; if(s != e)l = new node(s, m), r = new node(m+1, e); mn = 1e9, mx = 0; } void upd(int p, int v, int v2){ if(s == e)mn = v, mx = v2; else{ if(p <= m)l->upd(p, v, v2); else r->upd(p, v, v2); mn = min(l->mn, r->mn); mx = max(l->mx, r->mx); } } pi qry(int a, int b){ if(s == a && e == b)return {mn, mx}; else if(b <= m)return l->qry(a, b); else if(a > m)return r->qry(a ,b); else { pi lft = l->qry(a, m), rgt = r->qry(m+1, b); lft.fi = min(lft.fi, rgt.fi); lft.se = max(lft.se, rgt.se); return lft; } } }*root; int A[300005]; void solve(){ cin >> n >> m >> q; for(int i=1;i<n;i++){ int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } dfs(1, -1, 1); for(int i=1;i<=m;i++)cin >> A[i], ms[A[i]].insert(i); /* root = new node(1, n); for(int i=1;i<=n;i++){ if(!ms[i].empty()){ auto it = ms[i].begin(), it2 = --ms[i].end(); root->upd(S[i], *it, *it2); } } */ for(int i=1;i<=n;i++)back[S[i]] = i; for(int i=1;i<=19;i++)for(int j=1;j<=n;j++)par[i][j] = par[i-1][par[i-1][j]]; while(q--){ int t; cin >> t; if(t == 1){ int x, y; cin >> x >> y; /* ms[A[x]].erase(ms[A[x]].find(i)); if(!ms[A[x]].empty()){ auto it = ms[A[x]].begin(), it2 = --ms[A[x]].end(); root->upd(S[i], *it, *it2); } else root->upd(S[i], 1e9, 0); A[x] = y; ms[y].insert(i); if(!ms[y].empty()){ auto it = ms[y].begin(), it2 = --ms[y].end(); root->upd(S[y], *it, *it2); } */ A[x] = y; } else{ int l, r, v; cin >> l >> r >> v; int mn = 1e9, mx = 0, f = 0, st = l; for(int i = l; i <= r; i++){ if(S[A[i]] < S[v] || S[A[i]] > E[v]){ mn = 1e9; mx = 0; st = i + 1; continue; } mn = min(mn, S[A[i]]); mx = max(mx, S[A[i]]); if(lca(back[mn], back[mx]) == v){ f = 1; cout << st << ' ' << i << '\n'; break; } } if(!f)cout << -1 << ' ' << -1 << '\n'; } } } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; for(int tc1=1;tc1<=tc;tc1++){ // cout << "Case #" << tc1 << ": "; solve(); } }

Compilation message (stderr)

treearray.cpp:134:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  134 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...