(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #985752

#TimeUsernameProblemLanguageResultExecution timeMemory
985752alexddDynamic Diameter (CEOI19_diameter)C++17
100 / 100
379 ms45628 KiB
#include<bits/stdc++.h> using namespace std; #define int long long struct node { int a,b,ab,bc,abc; }; node combine(node x, node y) { node aux; aux.a = max(x.a,y.a); aux.b = max(x.b,y.b); aux.ab = max(max(x.ab,y.ab),x.a+y.b); aux.bc = max(max(x.bc,y.bc),x.b+y.a); aux.abc = max({max(x.abc,y.abc),x.a+y.bc,x.ab+y.a}); return aux; } node aint[530000]; int lazy[530000]; void baga(node &x, int newv) { x.a += newv; x.b -= 2*newv; x.ab -= newv; x.bc -= newv; } void propagate(int nod) { baga(aint[nod*2],lazy[nod]);lazy[nod*2]+=lazy[nod]; baga(aint[nod*2+1],lazy[nod]);lazy[nod*2+1]+=lazy[nod]; lazy[nod]=0; } void upd(int nod, int st, int dr, int le, int ri, int newv) { if(le>ri) return; if(le==st && dr==ri) { baga(aint[nod],newv);lazy[nod]+=newv; return; } propagate(nod); int mij=(st+dr)/2; upd(nod*2,st,mij,le,min(mij,ri),newv); upd(nod*2+1,mij+1,dr,max(mij+1,le),ri,newv); aint[nod] = combine(aint[nod*2],aint[nod*2+1]); } int n,q,maxw; vector<int> con[100005]; int tin[100005],tout[100005],timer; int parent[100005]; pair<pair<int,int>,int> e[100005]; void dfs(int nod) { tin[nod]=++timer; for(auto adj:con[nod]) { if(e[adj].first.first==parent[nod]) continue; if(e[adj].first.second==nod) swap(e[adj].first.first,e[adj].first.second); parent[e[adj].first.second]=nod; dfs(e[adj].first.second); timer++; } tout[nod]=timer; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>q>>maxw; for(int i=0;i<n-1;i++) { cin>>e[i].first.first>>e[i].first.second>>e[i].second; con[e[i].first.first].push_back(i); con[e[i].first.second].push_back(i); } dfs(1); for(int i=0;i<n-1;i++) { upd(1,1,timer,tin[e[i].first.second],tout[e[i].first.second],e[i].second); } int u,d,ult=0; while(q--) { cin>>u>>d; u = (u+ult)%(n-1); d = (d+ult)%maxw; upd(1,1,timer,tin[e[u].first.second],tout[e[u].first.second],d-e[u].second); e[u].second = d; ult = aint[1].abc; cout<<ult<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...