Submission #984935

# Submission time Handle Problem Language Result Execution time Memory
984935 2024-05-17T08:29:54 Z Pannda Examination (JOI19_examination) C++17
41 / 100
688 ms 75312 KB
#include <bits/stdc++.h>
using namespace std;

struct Fenwick2D {
    int n, m;
    vector<vector<int>> bit;
    vector<vector<int>> f;

    Fenwick2D(int n, int m) : n(n), m(m), bit(n + 1), f(n + 1) {}

    void fakeAdd(int i0, int j0) {
        for (int i = i0 + 1; i <= n; i += i & -i) {
            for (int j = j0 + 1; j <= m; j += j & -j) {
                f[i].push_back(j);
            }
        }
    }

    void work() {
        for (int i = 1; i <= n; i++) {
            f[i].push_back(0);
            sort(f[i].begin(), f[i].end());
            f[i].resize(unique(f[i].begin(), f[i].end()) - f[i].begin());
            bit[i].resize(f[i].size(), 0);
        }
    }

    void add(int i0, int j0, int x) {
        for (int i = i0 + 1; i <= n; i += i & -i) {
            for (int j = lower_bound(f[i].begin(), f[i].end(), j0 + 1) - f[i].begin(); j < (int)f[i].size(); j += j & -j) {
                bit[i][j] += x;
            }
        }
    }

    int sum(int i0, int j0) {
        int res = 0;
        for (int i = i0; i > 0; i -= i & -i) {
            for (int j = upper_bound(f[i].begin(), f[i].end(), j0) - f[i].begin() - 1; j > 0; j -= j & -j) {
                res += bit[i][j];
            }
        }
        return res;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    constexpr int C = 100000;
    Fenwick2D fen(C + 1, C + 1);

    int n, q;
    cin >> n >> q;
    vector<array<int, 2>> a(n);
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        a[i] = {x, y};
        fen.fakeAdd(C - x, C - y);
    }

    fen.work();

    sort(a.begin(), a.end(), [&](array<int, 2> x, array<int, 2> y) { return x[0] + x[1] > y[0] + y[1]; });

    vector<array<int, 4>> queries(q);
    vector<int> ans(q);
    for (int i = 0; i < q; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        queries[i] = {x, y, z, i};
    }

    sort(queries.begin(), queries.end(), [&](array<int, 4> x, array<int, 4> y) { return x[2] > y[2]; });

    int ptr = 0;
    for (auto [x, y, z, id] : queries) {
        while (ptr < n && a[ptr][0] + a[ptr][1] >= z) {
            auto [x, y] = a[ptr];
            fen.add(C - x, C - y, +1);
            ptr++;
        }
        ans[id] = fen.sum(C - x + 1, C - y + 1);
    }

    for (int x : ans) {
        cout << x << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 11356 KB Output is correct
2 Correct 10 ms 11344 KB Output is correct
3 Correct 11 ms 11356 KB Output is correct
4 Runtime error 5 ms 9920 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 668 ms 73132 KB Output is correct
2 Correct 661 ms 74044 KB Output is correct
3 Correct 635 ms 73432 KB Output is correct
4 Correct 172 ms 27192 KB Output is correct
5 Correct 194 ms 28344 KB Output is correct
6 Correct 69 ms 18116 KB Output is correct
7 Correct 594 ms 72668 KB Output is correct
8 Correct 596 ms 73128 KB Output is correct
9 Correct 567 ms 74412 KB Output is correct
10 Correct 107 ms 19964 KB Output is correct
11 Correct 104 ms 19964 KB Output is correct
12 Correct 45 ms 15580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 668 ms 73132 KB Output is correct
2 Correct 661 ms 74044 KB Output is correct
3 Correct 635 ms 73432 KB Output is correct
4 Correct 172 ms 27192 KB Output is correct
5 Correct 194 ms 28344 KB Output is correct
6 Correct 69 ms 18116 KB Output is correct
7 Correct 594 ms 72668 KB Output is correct
8 Correct 596 ms 73128 KB Output is correct
9 Correct 567 ms 74412 KB Output is correct
10 Correct 107 ms 19964 KB Output is correct
11 Correct 104 ms 19964 KB Output is correct
12 Correct 45 ms 15580 KB Output is correct
13 Correct 680 ms 74012 KB Output is correct
14 Correct 673 ms 73316 KB Output is correct
15 Correct 647 ms 74428 KB Output is correct
16 Correct 170 ms 27456 KB Output is correct
17 Correct 209 ms 28488 KB Output is correct
18 Correct 72 ms 18116 KB Output is correct
19 Correct 688 ms 74532 KB Output is correct
20 Correct 661 ms 75312 KB Output is correct
21 Correct 641 ms 72976 KB Output is correct
22 Correct 108 ms 19904 KB Output is correct
23 Correct 97 ms 20040 KB Output is correct
24 Correct 45 ms 15748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 11356 KB Output is correct
2 Correct 10 ms 11344 KB Output is correct
3 Correct 11 ms 11356 KB Output is correct
4 Runtime error 5 ms 9920 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -