Submission #994193

# Submission time Handle Problem Language Result Execution time Memory
994193 2024-06-07T08:34:12 Z Sharky Examination (JOI19_examination) C++17
100 / 100
261 ms 43968 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int, int>

const int N = 200001;
const int INF = 1e9;

int n, q, cntq = 0, ans[N], fen[N];
vector<array<int, 3>> v;

struct Crit {
    int a, b, c, id;
    bool operator < (const Crit& o) const {
        return c > o.c;
    }
} crit[N];

struct Query {
    int ty, x, y, f, id, ti;
} qry[N << 2], tq[N << 2];

void upd(int idx, int k) {
    for (; idx <= N; idx += (idx & -idx)) fen[idx] += k;
}

int query(int idx) {
    int res = 0;
    for (; idx; idx -= (idx & -idx)) res += fen[idx];
    return res;
}

void dnc(int l, int r) {
    if (l == r) return;
    int mid = (l + r) / 2;
    for (int i = l; i <= r; i++) {
        if (qry[i].ty == 1 && qry[i].ti <= mid) upd(qry[i].y, qry[i].f);
        else if (qry[i].ty == 2 && qry[i].ti > mid) ans[qry[i].id] += qry[i].f * query(qry[i].y);
    }
    int p1 = l - 1, p2 = mid;
    for (int i = l; i <= r; i++) {
        if (qry[i].ty == 1 && qry[i].ti <= mid) upd(qry[i].y, -qry[i].f);
        if (qry[i].ti <= mid) tq[++p1] = qry[i];
        else tq[++p2] = qry[i]; 
    }
    for (int i = l; i <= r; i++) qry[i] = tq[i];
    dnc(l, mid);
    dnc(mid + 1, r);
}

void Add(int ty, int x, int y, int f, int ask, int cnt) {
    qry[cnt] = (Query) {ty, x, y, f, ask, cnt};
}

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> q;
    for (int i = 1, v1, v2; i <= n; i++) {
        cin >> v1 >> v2;
        v.push_back({INF - v1, INF - v2, v1 + v2});
    }
    sort(v.begin(), v.end(), [] (array<int, 3> lhs, array<int, 3> rhs) { return lhs[2] > rhs[2]; });
    for (int i = 1; i <= q; i++) {
        cin >> crit[i].a >> crit[i].b >> crit[i].c;
        crit[i].id = i;
        crit[i].a = INF - crit[i].a, crit[i].b = INF - crit[i].b;
    }
    int ptr = 0;
    sort(crit + 1, crit + q + 1);
    vector<int> dx, dy;
    for (int i = 1; i <= q; i++) {
        while (ptr < n && v[ptr][2] >= crit[i].c) {
            Add(1, v[ptr][0], v[ptr][1], 1, 0, ++cntq);
            dx.push_back(v[ptr][0] + 1);
            dy.push_back(v[ptr][1] + 1);
            ptr++;
        }
        Add(2, crit[i].a, crit[i].b, 1, crit[i].id, ++cntq);
        dx.push_back(crit[i].a);
        dy.push_back(crit[i].b);
    }
    sort(dx.begin(), dx.end());
    dx.erase(unique(dx.begin(), dx.end()), dx.end());
    sort(dy.begin(), dy.end());
    dy.erase(unique(dy.begin(), dy.end()), dy.end());
    for (int i = 1; i <= cntq; i++) {
        qry[i].x = lower_bound(dx.begin(), dx.end(), qry[i].x) - dx.begin() + 1;
        qry[i].y = lower_bound(dy.begin(), dy.end(), qry[i].y) - dy.begin() + 1;
    }
    sort(qry + 1, qry + cntq + 1, [] (Query lhs, Query rhs) { return tie(lhs.x, lhs.y, lhs.ty) < tie(rhs.x, rhs.y, rhs.ty); });
    dnc(1, cntq);
    for (int i = 1; i <= q; i++) cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 6 ms 11140 KB Output is correct
8 Correct 7 ms 11100 KB Output is correct
9 Correct 6 ms 11100 KB Output is correct
10 Correct 6 ms 11096 KB Output is correct
11 Correct 6 ms 11096 KB Output is correct
12 Correct 5 ms 11100 KB Output is correct
13 Correct 6 ms 11132 KB Output is correct
14 Correct 6 ms 11100 KB Output is correct
15 Correct 7 ms 11100 KB Output is correct
16 Correct 6 ms 11028 KB Output is correct
17 Correct 7 ms 11100 KB Output is correct
18 Correct 4 ms 11100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 39100 KB Output is correct
2 Correct 212 ms 39100 KB Output is correct
3 Correct 231 ms 39260 KB Output is correct
4 Correct 188 ms 39328 KB Output is correct
5 Correct 161 ms 39084 KB Output is correct
6 Correct 152 ms 39332 KB Output is correct
7 Correct 211 ms 39616 KB Output is correct
8 Correct 203 ms 39096 KB Output is correct
9 Correct 209 ms 39616 KB Output is correct
10 Correct 144 ms 39352 KB Output is correct
11 Correct 177 ms 39616 KB Output is correct
12 Correct 143 ms 38852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 212 ms 39100 KB Output is correct
2 Correct 212 ms 39100 KB Output is correct
3 Correct 231 ms 39260 KB Output is correct
4 Correct 188 ms 39328 KB Output is correct
5 Correct 161 ms 39084 KB Output is correct
6 Correct 152 ms 39332 KB Output is correct
7 Correct 211 ms 39616 KB Output is correct
8 Correct 203 ms 39096 KB Output is correct
9 Correct 209 ms 39616 KB Output is correct
10 Correct 144 ms 39352 KB Output is correct
11 Correct 177 ms 39616 KB Output is correct
12 Correct 143 ms 38852 KB Output is correct
13 Correct 261 ms 39064 KB Output is correct
14 Correct 231 ms 39100 KB Output is correct
15 Correct 216 ms 39104 KB Output is correct
16 Correct 198 ms 39296 KB Output is correct
17 Correct 176 ms 39236 KB Output is correct
18 Correct 151 ms 39096 KB Output is correct
19 Correct 248 ms 39096 KB Output is correct
20 Correct 235 ms 39308 KB Output is correct
21 Correct 227 ms 39096 KB Output is correct
22 Correct 145 ms 39208 KB Output is correct
23 Correct 181 ms 39280 KB Output is correct
24 Correct 142 ms 38764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8792 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 6 ms 11140 KB Output is correct
8 Correct 7 ms 11100 KB Output is correct
9 Correct 6 ms 11100 KB Output is correct
10 Correct 6 ms 11096 KB Output is correct
11 Correct 6 ms 11096 KB Output is correct
12 Correct 5 ms 11100 KB Output is correct
13 Correct 6 ms 11132 KB Output is correct
14 Correct 6 ms 11100 KB Output is correct
15 Correct 7 ms 11100 KB Output is correct
16 Correct 6 ms 11028 KB Output is correct
17 Correct 7 ms 11100 KB Output is correct
18 Correct 4 ms 11100 KB Output is correct
19 Correct 212 ms 39100 KB Output is correct
20 Correct 212 ms 39100 KB Output is correct
21 Correct 231 ms 39260 KB Output is correct
22 Correct 188 ms 39328 KB Output is correct
23 Correct 161 ms 39084 KB Output is correct
24 Correct 152 ms 39332 KB Output is correct
25 Correct 211 ms 39616 KB Output is correct
26 Correct 203 ms 39096 KB Output is correct
27 Correct 209 ms 39616 KB Output is correct
28 Correct 144 ms 39352 KB Output is correct
29 Correct 177 ms 39616 KB Output is correct
30 Correct 143 ms 38852 KB Output is correct
31 Correct 261 ms 39064 KB Output is correct
32 Correct 231 ms 39100 KB Output is correct
33 Correct 216 ms 39104 KB Output is correct
34 Correct 198 ms 39296 KB Output is correct
35 Correct 176 ms 39236 KB Output is correct
36 Correct 151 ms 39096 KB Output is correct
37 Correct 248 ms 39096 KB Output is correct
38 Correct 235 ms 39308 KB Output is correct
39 Correct 227 ms 39096 KB Output is correct
40 Correct 145 ms 39208 KB Output is correct
41 Correct 181 ms 39280 KB Output is correct
42 Correct 142 ms 38764 KB Output is correct
43 Correct 247 ms 39608 KB Output is correct
44 Correct 248 ms 43960 KB Output is correct
45 Correct 245 ms 43968 KB Output is correct
46 Correct 194 ms 42428 KB Output is correct
47 Correct 191 ms 42940 KB Output is correct
48 Correct 148 ms 40128 KB Output is correct
49 Correct 257 ms 43964 KB Output is correct
50 Correct 245 ms 43960 KB Output is correct
51 Correct 234 ms 43964 KB Output is correct
52 Correct 165 ms 42432 KB Output is correct
53 Correct 184 ms 41664 KB Output is correct