Submission #947751

# Submission time Handle Problem Language Result Execution time Memory
947751 2024-03-17T01:40:45 Z Pring Examination (JOI19_examination) C++17
100 / 100
392 ms 70424 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
typedef array<int, 3> p3i;

const int MXN = 100005, LGC = 32, MXC = 2000000005;
int n, m;
pii a[MXN];
p3i c[MXN];
pii rl[MXN], rr[MXN], rd[MXN];
int ans[MXN];

struct P {
    int t, type, id;
    P() {}
    P(int _t, int _ty, int _id) : t(_t), type(_ty), id(_id) {}
    bool operator<(P o) {
        if (t != o.t) return t < o.t;
        if (type != o.type) return type < o.type;
        return id < o.id;
    }
};

vector<P> swp1, swp2;

struct SMG {
#define mid ((l + r) >> 1)
    int val[MXN * LGC], L[MXN * LGC], R[MXN * LGC];
    int nc;

    int new_node() {
        val[nc] = 0;
        L[nc] = 0;
        R[nc] = 0;
        return nc++;
    }

    void init() {
        nc = 1;
        new_node();
    }

    int modify(int id, int l, int r, int p, int v) {
        if (id == 0) id = new_node();
        if (l + 1 == r) {
            val[id] += v;
            return id;
        }
        if (p < mid) L[id] = modify(L[id], l, mid, p, v);
        else R[id] = modify(R[id], mid, r, p, v);
        val[id] = val[L[id]] + val[R[id]];
        return id;
    }

    int query(int id, int l, int r, int _l, int _r) {
        if (_r <= l || r <= _l) return 0;
        if (_l <= l && r <= _r) return val[id];
        return query(L[id], l, mid, _l, _r) + query(R[id], mid, r, _l, _r);
    }

#undef mid
} smg;

void PUT(int id) {
    auto [x, y, z] = c[id];
    rl[id] = mp(0, x);
    swp1.push_back(P(MXC, 1, id));
    if (x + y >= z) {
        rr[id] = mp(x, MXC);
        swp1.push_back(P(y - 1, 2, id));
    } else {
        rr[id] = mp(z - y, MXC);
        swp1.push_back(P(y - 1, 2, id));
        rd[id] = mp(x, z - y);
        swp2.push_back(P(z - 1, 3, id));
    }
}

void RUN(vector<P> &swp) {
    sort(swp.begin(), swp.end());
    smg.init();
    for (auto [t, type, id] : swp) {
        if (type == 0) {
            smg.modify(1, 0, MXC, a[id].fs, 1);
        } else if (type == 1) {
            ans[id] += smg.query(1, 0, MXC, rl[id].fs, rl[id].sc);
        } else if (type == 2) {
            ans[id] += smg.query(1, 0, MXC, rr[id].fs, rr[id].sc);
        } else {
            ans[id] += smg.query(1, 0, MXC, rd[id].fs, rd[id].sc);
        }
    }
}

void SWP1() {
    FOR(i, 0, n) swp1.push_back(P(a[i].sc, 0, i));
    RUN(swp1);
}

void SWP2() {
    FOR(i, 0, n) swp2.push_back(P(a[i].fs + a[i].sc, 0, i));
    RUN(swp2);
}

void miku() {
    cin >> n >> m;
    FOR(i, 0, n) cin >> a[i].fs >> a[i].sc;
    FOR(i, 0, m) cin >> c[i][0] >> c[i][1] >> c[i][2];
    FOR(i, 0, m) PUT(i);
    SWP1();
    SWP2();
    FOR(i, 0, m) cout << n - ans[i] << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14804 KB Output is correct
6 Correct 2 ms 14820 KB Output is correct
7 Correct 8 ms 17544 KB Output is correct
8 Correct 8 ms 17560 KB Output is correct
9 Correct 8 ms 17544 KB Output is correct
10 Correct 8 ms 17680 KB Output is correct
11 Correct 6 ms 15256 KB Output is correct
12 Correct 5 ms 15256 KB Output is correct
13 Correct 7 ms 17496 KB Output is correct
14 Correct 7 ms 17492 KB Output is correct
15 Correct 7 ms 17496 KB Output is correct
16 Correct 5 ms 15192 KB Output is correct
17 Correct 8 ms 17556 KB Output is correct
18 Correct 5 ms 15216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 31504 KB Output is correct
2 Correct 151 ms 31520 KB Output is correct
3 Correct 180 ms 30996 KB Output is correct
4 Correct 136 ms 32588 KB Output is correct
5 Correct 117 ms 30112 KB Output is correct
6 Correct 107 ms 28840 KB Output is correct
7 Correct 141 ms 31808 KB Output is correct
8 Correct 143 ms 31472 KB Output is correct
9 Correct 156 ms 31560 KB Output is correct
10 Correct 99 ms 30128 KB Output is correct
11 Correct 128 ms 30188 KB Output is correct
12 Correct 90 ms 28616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 31504 KB Output is correct
2 Correct 151 ms 31520 KB Output is correct
3 Correct 180 ms 30996 KB Output is correct
4 Correct 136 ms 32588 KB Output is correct
5 Correct 117 ms 30112 KB Output is correct
6 Correct 107 ms 28840 KB Output is correct
7 Correct 141 ms 31808 KB Output is correct
8 Correct 143 ms 31472 KB Output is correct
9 Correct 156 ms 31560 KB Output is correct
10 Correct 99 ms 30128 KB Output is correct
11 Correct 128 ms 30188 KB Output is correct
12 Correct 90 ms 28616 KB Output is correct
13 Correct 192 ms 37160 KB Output is correct
14 Correct 157 ms 31676 KB Output is correct
15 Correct 154 ms 32552 KB Output is correct
16 Correct 169 ms 38180 KB Output is correct
17 Correct 136 ms 33760 KB Output is correct
18 Correct 109 ms 29892 KB Output is correct
19 Correct 187 ms 36160 KB Output is correct
20 Correct 170 ms 36672 KB Output is correct
21 Correct 192 ms 38628 KB Output is correct
22 Correct 103 ms 28776 KB Output is correct
23 Correct 127 ms 31400 KB Output is correct
24 Correct 91 ms 28328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14684 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14804 KB Output is correct
6 Correct 2 ms 14820 KB Output is correct
7 Correct 8 ms 17544 KB Output is correct
8 Correct 8 ms 17560 KB Output is correct
9 Correct 8 ms 17544 KB Output is correct
10 Correct 8 ms 17680 KB Output is correct
11 Correct 6 ms 15256 KB Output is correct
12 Correct 5 ms 15256 KB Output is correct
13 Correct 7 ms 17496 KB Output is correct
14 Correct 7 ms 17492 KB Output is correct
15 Correct 7 ms 17496 KB Output is correct
16 Correct 5 ms 15192 KB Output is correct
17 Correct 8 ms 17556 KB Output is correct
18 Correct 5 ms 15216 KB Output is correct
19 Correct 150 ms 31504 KB Output is correct
20 Correct 151 ms 31520 KB Output is correct
21 Correct 180 ms 30996 KB Output is correct
22 Correct 136 ms 32588 KB Output is correct
23 Correct 117 ms 30112 KB Output is correct
24 Correct 107 ms 28840 KB Output is correct
25 Correct 141 ms 31808 KB Output is correct
26 Correct 143 ms 31472 KB Output is correct
27 Correct 156 ms 31560 KB Output is correct
28 Correct 99 ms 30128 KB Output is correct
29 Correct 128 ms 30188 KB Output is correct
30 Correct 90 ms 28616 KB Output is correct
31 Correct 192 ms 37160 KB Output is correct
32 Correct 157 ms 31676 KB Output is correct
33 Correct 154 ms 32552 KB Output is correct
34 Correct 169 ms 38180 KB Output is correct
35 Correct 136 ms 33760 KB Output is correct
36 Correct 109 ms 29892 KB Output is correct
37 Correct 187 ms 36160 KB Output is correct
38 Correct 170 ms 36672 KB Output is correct
39 Correct 192 ms 38628 KB Output is correct
40 Correct 103 ms 28776 KB Output is correct
41 Correct 127 ms 31400 KB Output is correct
42 Correct 91 ms 28328 KB Output is correct
43 Correct 392 ms 69032 KB Output is correct
44 Correct 327 ms 69508 KB Output is correct
45 Correct 292 ms 64024 KB Output is correct
46 Correct 301 ms 67820 KB Output is correct
47 Correct 149 ms 38640 KB Output is correct
48 Correct 127 ms 35568 KB Output is correct
49 Correct 303 ms 68524 KB Output is correct
50 Correct 351 ms 69388 KB Output is correct
51 Correct 295 ms 70424 KB Output is correct
52 Correct 135 ms 38128 KB Output is correct
53 Correct 209 ms 61868 KB Output is correct