(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 #951836

#TimeUsernameProblemLanguageResultExecution timeMemory
951836MinbaevDynamic Diameter (CEOI19_diameter)C++17
100 / 100
191 ms80644 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define f first #define int long long #define s second #define pii pair<int,int> template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;} template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;} typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int N = 1e6 + 5; const int inf = 1e17 + 7; const int mod = 1e9 + 7; int n,m,k; vector<tuple<int,int,int>>g[N]; vector<int>edge; struct st{ int pref,suff,sum,ans,all,usuff,upref; }; st t[N*4]; pii p[N*4]; void dfs(int x, int pr){ for(auto [to,w,ind] : g[x]){ if(to == pr)continue; edge.pb(w); p[ind].f = edge.size(); dfs(to,x); edge.pb(-w); p[ind].s = edge.size(); } } void merge(int ind){ #define seg t #define allans all #define prefans upref #define suffans usuff seg[ind].pref=max(seg[2*ind].pref, seg[2*ind].sum+seg[2*ind+1].pref); seg[ind].suff=max(seg[2*ind+1].suff, -seg[2*ind+1].sum+seg[2*ind].suff); seg[ind].sum=seg[2*ind].sum+seg[2*ind+1].sum; seg[ind].allans=max(seg[2*ind].allans+seg[2*ind+1].sum, -seg[2*ind].sum+seg[2*ind+1].allans); seg[ind].prefans=max({seg[2*ind].prefans, seg[2*ind].allans+seg[2*ind+1].pref, -seg[2*ind].sum+seg[2*ind+1].prefans}); seg[ind].suffans=max({seg[2*ind+1].suffans, seg[2*ind+1].allans+seg[2*ind].suff, seg[2*ind+1].sum+seg[2*ind].suffans}); seg[ind].ans=max({seg[2*ind].ans, seg[2*ind+1].ans, seg[2*ind].suffans+seg[2*ind+1].pref, seg[2*ind].suff+seg[2*ind+1].prefans}); } void build(int l, int r, int ind){ if(r==l){ t[ind].pref=max(0LL, edge[l-1]); t[ind].suff=max(0LL, -edge[l-1]); t[ind].ans=t[ind].upref=t[ind].usuff=t[ind].all=abs(edge[l-1]); t[ind].sum=edge[l-1]; } else{ int mid=(r+l)>>1; build(l, mid, 2*ind); build(mid+1, r, 2*ind+1); merge(ind); }/* cout << ind << "\n"; cout<<seg[ind].pref<<"\n"<<seg[ind].suff<<"\n"<<seg[ind].sum<<"\n"<<seg[ind].allans<<"\n"<<seg[ind].prefans<<"\n"<<seg[ind].suffans<<"\n"<<seg[ind].ans<<"\n"; cout << "\n";*/ } void update(int tl, int tr, int v, int pos, int val){ if(tl == tr){ t[v].pref = max(0ll, val); t[v].suff = max(0ll, -val); t[v].sum = val; t[v].all = abs(val); t[v].upref = abs(val); t[v].usuff = abs(val); t[v].ans = abs(val); return; } int tm = (tl+tr)/2; if(pos <= tm){ update(tl,tm,v*2,pos,val); } else update(tm+1,tr,v*2+1,pos,val); merge(v); } void solve(){ cin >> n >> m >> k; for(int i = 1;i<n;i++){ int a,b,c; cin >> a >> b >> c; g[a].pb({b,c,i-1}); g[b].pb({a,c,i-1}); } dfs(1,-1); build(1,edge.size(),1); /* int ind = 1; cout << t[ind].pref<<"\n" << t[ind].suff<<"\n" << t[ind].sum<<"\n" << t[ind].all<<"\n" << t[ind].upref<<"\n" << t[ind].usuff<<"\n" << t[ind].ans<<"\n";*/ //etu huyni ya daje ne sam zakonchil, pizdec, chas nochi, poydu podrochu int last = 0; while(m--){ int a,b; cin >> a >> b; a = (a+last)%(n-1); b = (b+last)%k; update(1,edge.size(),1,p[a].f,b); update(1,edge.size(),1,p[a].s,-b); //~ cout << p[a].f<<" "<<p[a].s<<"\n"; cout << t[1].ans<<"\n"; last = t[1].ans; } } /* // Success consists of going from failure to failure without loss of enthusiasm // Problems means that you are trying // Soberis dolboyeb */ signed main() { // freopen("seq.in", "r", stdin); // freopen("seq.out", "w", stdout); ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); int tt=1;//cin>>tt; while(tt--)solve(); }
#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...