Submission #424672

#TimeUsernameProblemLanguageResultExecution timeMemory
424672cpp219Birthday gift (IZhO18_treearray)C++14
0 / 100
14 ms23812 KiB
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; const ll N = 2e5 + 9; const ll inf = 1e9 + 7; const ll Log2 = 21; typedef pair<ll,ll> LL; vector<ll> g[N]; ll n,m,Q,x,y,a[N],lca[N]; ll par[N][Log2],d[N]; set<ll> fath[N],place[N]; void DFS(ll u,ll p){ for (ll i = 1;i < Log2;i++) if ((i << i) <= d[u]) par[u][i] = par[par[u][i - 1]][i - 1]; for (auto i : g[u]){ if (i == p) continue; par[i][0] = u; d[i] = d[u] + 1; DFS(i,u); } } ll LCA(ll u,ll v){ if (d[u] > d[v]) swap(u,v); for (ll i = Log2 - 1;i >= 0;i--) if ((1 << i) <= d[v] && d[par[v][i]] >= d[u]) v = par[v][i]; if (u == v) return u; for (ll i = Log2 - 1;i >= 0;i--) if (par[u][i] != par[v][i]) u = par[u][i],v = par[v][i]; return par[v][0]; } ll type,pos,v,l,r; int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "tst" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } cin>>n>>m>>Q; for (ll i = 1;i < n;i++){ cin>>x>>y; g[x].push_back(y); g[y].push_back(x); } DFS(1,0); for (ll i = 1;i <= m;i++) place[i].insert(inf),fath[i].insert(inf); for (ll i = 1;i <= m;i++) cin>>a[i],place[a[i]].insert(i); for (ll i = 1;i < m;i++) lca[i] = LCA(a[i],a[i + 1]),fath[lca[i]].insert(i); while(Q--){ cin>>type; if (type == 1){ cin>>pos>>v; place[a[pos]].erase(pos); fath[lca[pos]].erase(pos); fath[lca[pos - 1]].erase(pos - 1); a[pos] = v; lca[pos] = LCA(a[pos],a[pos + 1]); lca[pos - 1] = LCA(a[pos - 1],a[pos]); place[a[pos]].insert(pos); fath[lca[pos]].insert(pos); fath[lca[pos - 1]].insert(pos - 1); } else{ cin>>l>>r>>v; ll now1 = *fath[v].lower_bound(l),now2 = *place[v].lower_bound(l); if (now2 <= r) cout<<now2<<" "<<now2; else if (now1 < r) cout<<now1<<" "<<now1 + 1; else cout<<-1<<" "<<-1; cout<<"\n"; } } }

Compilation message (stderr)

treearray.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
treearray.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
treearray.cpp: In function 'int main()':
treearray.cpp:72:13: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   72 |             else cout<<-1<<" "<<-1; cout<<"\n";
      |             ^~~~
treearray.cpp:72:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   72 |             else cout<<-1<<" "<<-1; cout<<"\n";
      |                                     ^~~~
treearray.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...