Submission #791098

# Submission time Handle Problem Language Result Execution time Memory
791098 2023-07-23T12:10:49 Z max0000561 Ants and Sugar (JOI22_sugar) C++17
0 / 100
135 ms 19924 KB
#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
1 Correct 3 ms 8148 KB Output is correct
2 Correct 4 ms 8124 KB Output is correct
3 Incorrect 4 ms 8128 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8148 KB Output is correct
2 Correct 3 ms 8148 KB Output is correct
3 Correct 3 ms 8116 KB Output is correct
4 Incorrect 135 ms 19924 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 16340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8148 KB Output is correct
2 Correct 4 ms 8124 KB Output is correct
3 Incorrect 4 ms 8128 KB Output isn't correct
4 Halted 0 ms 0 KB -