답안 #683433

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683433 2023-01-18T11:44:44 Z nifeshe 돌 무게 재기 (IZhO11_stones) C++17
100 / 100
43 ms 9940 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma comment (linker, "/STACK: 16777216")

#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define int long long

using namespace std;
using namespace __gnu_pbds;

template <typename T> inline bool umax(T &a, const T &b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool umin(T &a, const T &b) { if(a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

ll mod = 998244353;
const ll base = 1e6 + 5;
const ll inf = 1e18;
const int MAX = 1e6;
const int lg = 20;

random_device rd;
mt19937 gen(rd());
uniform_int_distribution<ll> dis(1, inf);

struct node {
    int s = 0;
    int sf = 0;
    int sm = 0;
};

node combine(node a, node b) {
    node res;
    res.s = a.s + b.s;
    res.sf = max(b.sf, a.sf + b.s);
    res.sm = min(b.sm, a.sm + b.s);
    return res;
}

int n;
vector<node> t;

void update(int i, int x, int v = 0, int l = 0, int r = n) {
    if(r - l == 1) {
        t[v].s = x;
        t[v].sm = min(x, 0LL);
        t[v].sf = max(x, 0LL);
        return;
    }
    int m = (l + r) / 2;
    if(i < m) update(i, x, 2 * v + 1, l, m);
    else update(i, x, 2 * v + 2, m, r);
    t[v] = combine(t[2 * v + 1], t[2 * v + 2]);
}

void solve() {
    cin >> n;
    t.resize(4 * n + 5);
    for(int it = 0; it < n; it++) {
        int i, x;
        cin >> i >> x;
        i--;
        if(x == 2) x = 1;
        else x = -1;
        update(i, x);
        if(t[0].sf > 0 && t[0].sm < 0) cout << "?\n";
        else if(t[0].sf > 0) cout << "<\n";
        else if(t[0].sm < 0) cout << ">\n";
    }
}

signed main() {
//    freopen("stones.in", "r", stdin); freopen("stones.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int ttt = 1;
//    cin >> ttt;
    while(ttt--) {
        solve();
    }
    return 0;
}

Compilation message

stones.cpp:8: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    8 | #pragma comment (linker, "/STACK: 16777216")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 428 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
11 Correct 23 ms 5688 KB Output is correct
12 Correct 35 ms 8928 KB Output is correct
13 Correct 32 ms 9896 KB Output is correct
14 Correct 36 ms 9880 KB Output is correct
15 Correct 33 ms 9940 KB Output is correct
16 Correct 32 ms 9840 KB Output is correct
17 Correct 31 ms 9900 KB Output is correct
18 Correct 32 ms 9852 KB Output is correct
19 Correct 32 ms 9896 KB Output is correct
20 Correct 32 ms 9876 KB Output is correct
21 Correct 34 ms 9860 KB Output is correct
22 Correct 43 ms 9900 KB Output is correct
23 Correct 42 ms 9888 KB Output is correct
24 Correct 32 ms 9840 KB Output is correct
25 Correct 32 ms 9940 KB Output is correct