답안 #1074784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1074784 2024-08-25T13:59:01 Z coolboy19521 돌 무게 재기 (IZhO11_stones) C++17
100 / 100
286 ms 7796 KB
#include "bits/stdc++.h"
#define ll long long

using namespace std;

struct STree {
    vector<int> st, lz;
    int sz, n;
    STree(int N): sz(4 * N + 100), n(N) {
        st.assign(sz, 0);
        lz.assign(sz, 0);
    }
    void relax(int v) {
        st[v] += lz[v];
        if (v * 2 < sz)
            lz[v * 2] += lz[v];
        if (v * 2 + 1 < sz)
            lz[v * 2 + 1] += lz[v];
        lz[v] = 0;
    }
    void upd(int lo, int hi, int ix, int v, int k) {
        relax(v);
        if (lo > ix) return;
        if (hi <= ix) {
            lz[v] += k;
            relax(v);
            //cout << "updd: " << lo << ' ' << hi << ' ' << st[v] << '\n';
        } else {
            int mi = (lo + hi) / 2;
            upd(lo, mi, ix, v * 2, k);
            upd(mi + 1, hi, ix, v * 2 + 1, k);
            st[v] = min(st[v * 2], st[v * 2 + 1]);
            //cout << "upd: " << lo << ' ' << hi << ' ' << st[v * 2] << ' ' << st[v * 2 + 1] << '\n';
        }
    }
    int qry(int lo, int hi, int ql, int qr, int v) {
        relax(v);
        if (lo > qr || ql > hi) return 2e5;
        if (ql <= lo && hi <= qr) return st[v];
        int mi = (lo + hi) / 2;
        int lq = qry(lo, mi, ql, qr, v * 2);
        int rq = qry(mi + 1, hi, ql, qr, v * 2 + 1);
        return min(lq, rq);
    }
};

int main() {
    int n;
    cin >> n;

    STree le(n), ri(n);

    for (int i = 0; i < n; i ++) {
        int a, b;
        cin >> a >> b;
        if (1 == b) {
            le.upd(1, n, a, 1, -1);
            ri.upd(1, n, a, 1, 1);
        } else {
            le.upd(1, n, a, 1, 1);
            ri.upd(1, n, a, 1, -1);
        }
        int lq = le.qry(1, n, 1, n, 1), rq = ri.qry(1, n, 1, n, 1);
        //cout << "hi: " << lq << ' ' << rq << ' ' << le.qry(1, n, 5, 5, 1) << '\n';
        if (0 > lq && rq >= 0)
            cout << ">\n";
        else if (0 > rq && lq >= 0)
            cout << "<\n";
        else cout << "?\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 2 ms 440 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 15 ms 1060 KB Output is correct
11 Correct 141 ms 4604 KB Output is correct
12 Correct 186 ms 6740 KB Output is correct
13 Correct 184 ms 7508 KB Output is correct
14 Correct 181 ms 7492 KB Output is correct
15 Correct 183 ms 7508 KB Output is correct
16 Correct 185 ms 7472 KB Output is correct
17 Correct 286 ms 7796 KB Output is correct
18 Correct 223 ms 7596 KB Output is correct
19 Correct 223 ms 7472 KB Output is correct
20 Correct 201 ms 7636 KB Output is correct
21 Correct 201 ms 7512 KB Output is correct
22 Correct 220 ms 7508 KB Output is correct
23 Correct 182 ms 7504 KB Output is correct
24 Correct 190 ms 7512 KB Output is correct
25 Correct 189 ms 7596 KB Output is correct