Submission #472626

#TimeUsernameProblemLanguageResultExecution timeMemory
472626OzyDynamic Diameter (CEOI19_diameter)C++17
0 / 100
232 ms30248 KiB
#include <iostream> #include <bits/stdc++.h> using namespace std; #define lli long long int #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define repa(i,a,b) for (int i = (a); i >= (b); i--) #define debug(a) cout << #a << " = " << a << endl #define debugsl(a) cout << #a << " = " << a << ", " #define MAX 100000 lli n,q,w,a,b,c,last,id; lli peso[MAX+2]; vector<lli> hijos[MAX+2]; pair<lli,lli> arr[MAX+2]; multiset<lli> maximo; multiset<lli>::iterator it; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q >> w; rep(i,1,n-1) { cin >> a >> b >> c; hijos[a].push_back(b); hijos[b].push_back(a); arr[i] = {a,b}; peso[i] = c; maximo.insert(-c); } last = 0; rep(i,1,q) { //correcto cin >> id >> c; id += last; id %= (n-1); id++; c += last; c %= w; it = maximo.lower_bound(-peso[id]); maximo.erase(it); peso[id] = c; maximo.insert(-c); it = maximo.lower_bound(-w); a = *it; if (n > 2) { it++; b = *it; a += b; } cout << a << "\n"; last = a; } }
#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...