Submission #333647

# Submission time Handle Problem Language Result Execution time Memory
333647 2020-12-07T09:56:08 Z apostoldaniel854 Weighting stones (IZhO11_stones) C++14
100 / 100
75 ms 6124 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

struct SegTree {
    int n;
    vector <int> mx;
    vector <int> mn;
    vector <int> lazy;
    SegTree (int n) {
        this->n = n;
        mx.resize (1 + 4 * n);
        mn.resize (1 + 4 * n);
        lazy.resize (1 + 4 * n);
    }
    void push (int node) {
        int l = node * 2, r = node * 2 + 1;
        mn[l] += lazy[node];
        mx[l] += lazy[node];
        mn[r] += lazy[node];
        mx[r] += lazy[node];
        lazy[l] += lazy[node];
        lazy[r] += lazy[node];
        lazy[node] = 0;
    }
    void update (int node, int lb, int rb, int x, int y, int val) {
        if (x <= lb && rb <= y) {
            mn[node] += val;
            mx[node] += val;
            lazy[node] += val;
            return;
        }
        int mid = (lb + rb) / 2, lNode = node * 2, rNode = node * 2 + 1;
        push (node);
        if (x <= mid)
            update (lNode, lb, mid, x, y, val);
        if (mid + 1 <= y)
            update (rNode, mid + 1, rb, x, y, val);
        mn[node] = min (mn[lNode], mn[rNode]);
        mx[node] = max (mx[lNode], mx[rNode]);
    }
    char query () { /// 1 means >, -1 means <, and 0 means ?
        if (mn[1] >= 0)
            return '>';
        if (mx[1] <= 0)
            return '<';
        return '?';
    }
};

int main () {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    int n;
    cin >> n;
    SegTree seg (n);
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        seg.update (1, 1, n, 1, x, (y == 1) ? 1 : -1);
        cout << seg.query () << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 6 ms 876 KB Output is correct
11 Correct 51 ms 3564 KB Output is correct
12 Correct 74 ms 5484 KB Output is correct
13 Correct 63 ms 5996 KB Output is correct
14 Correct 61 ms 5996 KB Output is correct
15 Correct 61 ms 5996 KB Output is correct
16 Correct 75 ms 6016 KB Output is correct
17 Correct 63 ms 6124 KB Output is correct
18 Correct 64 ms 5996 KB Output is correct
19 Correct 63 ms 5996 KB Output is correct
20 Correct 66 ms 5996 KB Output is correct
21 Correct 65 ms 5996 KB Output is correct
22 Correct 62 ms 5996 KB Output is correct
23 Correct 61 ms 5996 KB Output is correct
24 Correct 62 ms 5996 KB Output is correct
25 Correct 63 ms 5996 KB Output is correct