(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.

제출 #286459

#제출 시각아이디문제언어결과실행 시간메모리
286459errorgornDynamic Diameter (CEOI19_diameter)C++14
100 / 100
814 ms57852 KiB
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << " is " << x << endl #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> //change less to less_equal for non distinct pbds, but erase will bug mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); struct node{ int s,e,m; ll a=0,b=0,c=0,ab=0,bc=0,abc=0,lazy=0; 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); } } void propo(){ if (lazy){ a+=lazy; b-=lazy*2; c+=lazy; ab-=lazy; bc-=lazy; if (s!=e){ l->lazy+=lazy; r->lazy+=lazy; } lazy=0; } } void update(int i,int j,ll k){ if (s==i && e==j) lazy+=k; else{ if (j<=m) l->update(i,j,k); else if (m<i) r->update(i,j,k); else l->update(i,m,k),r->update(m+1,j,k); l->propo(),r->propo(); a=max(l->a,r->a); b=max(l->b,r->b); c=max(l->c,r->c); ab=max({l->ab,r->ab,l->a+r->b}); bc=max({l->bc,r->bc,l->b+r->c}); abc=max({l->abc,r->abc,l->a+r->bc,l->ab+r->c}); } } } *root=new node(0,200005); ll n,q,w0; vector<ii> al[100005]; ll w[100005]; int id[100005]; //assoc weight to node int in[100005]; int out[100005]; int TIME=0; void dfs(int i,int p){ in[i]=TIME++; for (auto &it:al[i]){ if (it.fi==p) continue; dfs(it.fi,i); id[it.se]=it.fi; out[i]=TIME++; } if (out[i]==0) out[i]=in[i]; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin>>n>>q>>w0; ll a,b,c; rep(x,0,n-1){ cin>>a>>b>>c; al[a].push_back(ii(b,x)); al[b].push_back(ii(a,x)); w[x]=c; } dfs(1,-1); rep(x,0,n-1){ root->update(in[id[x]],out[id[x]],w[x]); } ll lastans=0; while (q--){ cin>>a>>b; a=(a+lastans)%(n-1),b=(b+lastans)%w0; root->update(in[id[a]],out[id[a]],b-w[a]); w[a]=b; lastans=root->abc; cout<<lastans<<endl; } }

컴파일 시 표준 에러 (stderr) 메시지

diameter.cpp: In constructor 'node::node(int, int)':
diameter.cpp:34:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |   s=_s,e=_e,m=s+e>>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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...