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>
#define int long long
#define sz(a) (int)a.size()
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int q, L;
cin >> q >> L;
vector<int> cnt(500500);
vector<int> mx(500500);
int ans = 0;
while (q--) {
int t, x, a;
cin >> t >> x >> a;
x += 11;
if (x % 2 == 1) {
ans -= min(cnt[x], cnt[x + 1]);
cnt[x] += a;
ans += min(cnt[x], cnt[x + 1]);
}
else {
ans -= min(cnt[x], cnt[x - 1]);
cnt[x] += a;
ans += min(cnt[x], cnt[x - 1]);
}
if (x % 2 == 1) {
ans -= min(mx[x + 3], mx[x + 4]);
ans -= min(mx[x + 1], mx[x + 2]);
ans -= min(mx[x - 1], mx[x]);
ans -= min(mx[x - 3], mx[x - 1]);
mx[x] = max(0ll, cnt[x] - cnt[x + 1]);
mx[x + 1] = max(0ll, cnt[x + 1] - cnt[x]);
ans += min(mx[x + 3], mx[x + 4]);
ans += min(mx[x + 1], mx[x + 2]);
ans += min(mx[x - 1], mx[x]);
ans += min(mx[x - 3], mx[x - 1]);
}
else {
ans -= min(mx[x + 2], mx[x + 3]);
ans -= min(mx[x], mx[x + 1]);
ans -= min(mx[x - 2], mx[x - 1]);
ans -= min(mx[x - 4], mx[x - 2]);
mx[x] = max(0ll, cnt[x] - cnt[x - 1]);
mx[x - 1] = max(0ll, cnt[x - 1] - cnt[x]);
ans += min(mx[x + 2], mx[x + 3]);
ans += min(mx[x], mx[x + 1]);
ans += min(mx[x - 2], mx[x - 1]);
ans += min(mx[x - 4], mx[x - 2]);
}
cout << ans << '\n';
}
}
# | 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... |