Submission #994191

# Submission time Handle Problem Language Result Execution time Memory
994191 2024-06-07T08:33:26 Z Sharky Examination (JOI19_examination) C++17
43 / 100
246 ms 39168 KB
#include <bits/stdc++.h>
using namespace std;

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

const int N = 100001;
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 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 7 ms 9088 KB Output is correct
8 Correct 6 ms 9052 KB Output is correct
9 Correct 6 ms 9052 KB Output is correct
10 Correct 7 ms 9308 KB Output is correct
11 Correct 6 ms 9052 KB Output is correct
12 Correct 5 ms 9048 KB Output is correct
13 Correct 6 ms 9052 KB Output is correct
14 Correct 6 ms 9052 KB Output is correct
15 Correct 6 ms 9052 KB Output is correct
16 Correct 5 ms 9224 KB Output is correct
17 Correct 6 ms 9052 KB Output is correct
18 Correct 4 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 205 ms 36952 KB Output is correct
2 Correct 219 ms 36472 KB Output is correct
3 Correct 211 ms 36544 KB Output is correct
4 Correct 165 ms 35520 KB Output is correct
5 Correct 165 ms 35776 KB Output is correct
6 Correct 130 ms 34920 KB Output is correct
7 Correct 204 ms 36540 KB Output is correct
8 Correct 206 ms 36280 KB Output is correct
9 Correct 202 ms 36288 KB Output is correct
10 Correct 144 ms 35748 KB Output is correct
11 Correct 151 ms 36028 KB Output is correct
12 Correct 111 ms 34492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 205 ms 36952 KB Output is correct
2 Correct 219 ms 36472 KB Output is correct
3 Correct 211 ms 36544 KB Output is correct
4 Correct 165 ms 35520 KB Output is correct
5 Correct 165 ms 35776 KB Output is correct
6 Correct 130 ms 34920 KB Output is correct
7 Correct 204 ms 36540 KB Output is correct
8 Correct 206 ms 36280 KB Output is correct
9 Correct 202 ms 36288 KB Output is correct
10 Correct 144 ms 35748 KB Output is correct
11 Correct 151 ms 36028 KB Output is correct
12 Correct 111 ms 34492 KB Output is correct
13 Correct 235 ms 36796 KB Output is correct
14 Correct 229 ms 36808 KB Output is correct
15 Correct 211 ms 36540 KB Output is correct
16 Correct 176 ms 36028 KB Output is correct
17 Correct 175 ms 36028 KB Output is correct
18 Correct 130 ms 34960 KB Output is correct
19 Correct 245 ms 37004 KB Output is correct
20 Correct 246 ms 37216 KB Output is correct
21 Correct 225 ms 36920 KB Output is correct
22 Correct 143 ms 35512 KB Output is correct
23 Correct 153 ms 35260 KB Output is correct
24 Correct 112 ms 34416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 7 ms 9088 KB Output is correct
8 Correct 6 ms 9052 KB Output is correct
9 Correct 6 ms 9052 KB Output is correct
10 Correct 7 ms 9308 KB Output is correct
11 Correct 6 ms 9052 KB Output is correct
12 Correct 5 ms 9048 KB Output is correct
13 Correct 6 ms 9052 KB Output is correct
14 Correct 6 ms 9052 KB Output is correct
15 Correct 6 ms 9052 KB Output is correct
16 Correct 5 ms 9224 KB Output is correct
17 Correct 6 ms 9052 KB Output is correct
18 Correct 4 ms 9052 KB Output is correct
19 Correct 205 ms 36952 KB Output is correct
20 Correct 219 ms 36472 KB Output is correct
21 Correct 211 ms 36544 KB Output is correct
22 Correct 165 ms 35520 KB Output is correct
23 Correct 165 ms 35776 KB Output is correct
24 Correct 130 ms 34920 KB Output is correct
25 Correct 204 ms 36540 KB Output is correct
26 Correct 206 ms 36280 KB Output is correct
27 Correct 202 ms 36288 KB Output is correct
28 Correct 144 ms 35748 KB Output is correct
29 Correct 151 ms 36028 KB Output is correct
30 Correct 111 ms 34492 KB Output is correct
31 Correct 235 ms 36796 KB Output is correct
32 Correct 229 ms 36808 KB Output is correct
33 Correct 211 ms 36540 KB Output is correct
34 Correct 176 ms 36028 KB Output is correct
35 Correct 175 ms 36028 KB Output is correct
36 Correct 130 ms 34960 KB Output is correct
37 Correct 245 ms 37004 KB Output is correct
38 Correct 246 ms 37216 KB Output is correct
39 Correct 225 ms 36920 KB Output is correct
40 Correct 143 ms 35512 KB Output is correct
41 Correct 153 ms 35260 KB Output is correct
42 Correct 112 ms 34416 KB Output is correct
43 Incorrect 234 ms 39168 KB Output isn't correct
44 Halted 0 ms 0 KB -