This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define ceil(a, b) ((a + b - 1) / (b))
#define all(x) x.begin(), x.end()
#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
int n;
vector<int> cost;
multiset<int> s;
void init_(int _n) {
n = _n;
cost.assign(n - 1, 0);
s.clear();
}
int query(int id, int x) {
s.erase(s.find(cost[id]));
cost[id] = x;
s.insert(cost[id]);
if(n - 1 == 1) return *s.rbegin();
else return *s.rbegin() + *next(s.rbegin());
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, q, w, last = 0;
cin >> n >> q >> w, init_(n);
rep(i, 1, n - 1) {
int a, b, c;
cin >> a >> b >> c;
cost[i - 1] = c;
s.insert(c);
}
while(q --) {
int x, y; cin >> x >> y;
x = (x + last) % (n - 1);
y = (y + last) % w;
int ans = query(x, y);
last = ans;
cout << ans << "\n";
}
return 0;
}
Compilation message (stderr)
diameter.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
diameter.cpp:23:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
23 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
diameter.cpp:23:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
23 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# | 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... |