제출 #597129

#제출 시각아이디문제언어결과실행 시간메모리
597129Valaki2Dynamic Diameter (CEOI19_diameter)C++14
7 / 100
203 ms9032 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back const int maxn = 1e5; struct edge { int to, wei; edge() : to(0), wei(0) {} edge(int to_, int wei_) : to(to_), wei(wei_) {} }; int n, q, w; vector<int> wei; multiset<int> m; int query() { int res = 0; auto it = m.rbegin(); res += *it; it++; if(it != m.rend()) { res += *it; } return res; } void solve() { cin >> n >> q >> w; wei.assign(n - 1, 0); for(int i = 0; i < n - 1; i++) { int a, b, c; cin >> a >> b >> c; wei[i] = c; m.insert(c); } int last = 0; while(q--) { int d, e; cin >> d >> e; d = (d + last) % (n - 1); e = (e + last) % w; // ----- changable ----- m.erase(m.find(wei[d])); wei[d] = e; m.insert(wei[d]); int result = query(); // ----- changable ----- cout << result << "\n"; last = result; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); 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...