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