Submission #336102

# Submission time Handle Problem Language Result Execution time Memory
336102 2020-12-14T17:57:58 Z nikatamliani Weighting stones (IZhO11_stones) C++14
100 / 100
330 ms 4620 KB
#include <bits/stdc++.h>
#define mn first
#define mx second
using namespace std;
const int N = 1e5+10;
pair<int,int> tree[4*N];
int lazy[4*N];
void push(int l, int r, int p) {
    if(l < r) {
        lazy[p << 1] += lazy[p];
        lazy[p << 1 | 1] += lazy[p];
    }
    tree[p].mn += lazy[p];
    tree[p].mx += lazy[p];
    lazy[p] = 0;
}
void add(int l, int r, int L, int R, int val, int p) {
    push(l, r, p);
    if(l > R || L > r) return;
    if(L <= l && R >= r) {
        lazy[p] += val;
        push(l, r, p);
    } else {
        int m = l + r >> 1;
        add(l, m, L, R, val, p << 1);
        add(m+1, r, L, R, val, p << 1 | 1);
        tree[p].mn = min(tree[p << 1].mn, tree[p << 1 | 1].mn);
        tree[p].mx = max(tree[p << 1].mx, tree[p << 1 | 1].mx);
    }
}
int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        int x, where;
        cin >> x >> where;
        if(where == 1) {
            add(1, n, 1, x, 1, 1);
        } else {
            add(1, n, 1, x, -1, 1);
        }
        if(tree[1].mn >= 0) {
            cout << ">\n"; 
        } else if(tree[1].mx <= 0) {
            cout << "<\n";
        } else {
            cout << "?\n";
        }
    }
}

Compilation message

stones.cpp: In function 'void add(int, int, int, int, int, int)':
stones.cpp:24:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |         int m = l + r >> 1;
      |                 ~~^~~
# 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 2 ms 364 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 4 ms 364 KB Output is correct
9 Correct 4 ms 364 KB Output is correct
10 Correct 29 ms 748 KB Output is correct
11 Correct 184 ms 2028 KB Output is correct
12 Correct 299 ms 4620 KB Output is correct
13 Correct 320 ms 4332 KB Output is correct
14 Correct 316 ms 4332 KB Output is correct
15 Correct 317 ms 4332 KB Output is correct
16 Correct 318 ms 4476 KB Output is correct
17 Correct 319 ms 4332 KB Output is correct
18 Correct 319 ms 4460 KB Output is correct
19 Correct 318 ms 4460 KB Output is correct
20 Correct 316 ms 4460 KB Output is correct
21 Correct 317 ms 4588 KB Output is correct
22 Correct 314 ms 4332 KB Output is correct
23 Correct 324 ms 4460 KB Output is correct
24 Correct 314 ms 4460 KB Output is correct
25 Correct 330 ms 4332 KB Output is correct