This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
a *= -1;
cout << a << "\n";
last = a;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |