제출 #1040636

#제출 시각아이디문제언어결과실행 시간메모리
1040636antonDynamic Diameter (CEOI19_diameter)C++17
0 / 100
273 ms28608 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> int N, Q, W; const int MAX_N = 1e5; vector<unordered_map<int, int>> adj; signed main(){ cin>>N>>Q>>W; adj.resize(N+1); vector<pii> edges; vector<int> lazy(N+1, 0); vector<pii> tr(N+1, {0, 0}); auto upd =[&](int u){ tr[u].first = max(tr[u*2].first, tr[u*2+1].first) + lazy[u]; tr[u].second = max(max(tr[u*2].second, tr[u*2+1].second), tr[u*2].first + tr[u*2+1].first); }; for(int i = 0; i<N-1; i++){ int a, b, c; cin>>a>>b>>c; adj[a][b] = c; adj[b][a] = c; if(b<a){ swap(a, b); } lazy[b] = c; tr[b].first = c; edges.push_back({a, b}); } for(int i = N/2; i>=1; i--){ upd(i); } int root =0; int last= 0; for(int i = 0; i<Q; i++){ int d, e; cin>>d>>e; d = (d+last)%(N-1) +1; e = (e +last)%W +1; int a = edges[d].first; int b= edges[d].second; int delta = e-adj[a][b]; adj[a][b] = e; adj[b][a] =e; if(a>b){ swap(a, b); } lazy[b] += delta; tr[b].first += delta; for(int i = a; i>=1; i/=2){ upd(i); } cout<<tr[1].second<<endl; } }

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

diameter.cpp: In function 'int main()':
diameter.cpp:48:9: warning: unused variable 'root' [-Wunused-variable]
   48 |     int root =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...