Submission #791098

#TimeUsernameProblemLanguageResultExecution timeMemory
791098max0000561Ants and Sugar (JOI22_sugar)C++17
0 / 100
135 ms19924 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...