Submission #905351

# Submission time Handle Problem Language Result Execution time Memory
905351 2024-01-13T02:00:51 Z juliany2 Examination (JOI19_examination) C++17
100 / 100
1912 ms 16060 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()

template<class T> struct BIT {
    int n;
    vector<T> bit;

    void init(int sz) { bit = vector<T> (n = sz + 7); }

    void upd(int i, T x) { 
        for (i++; i < n; i += i & -i) bit[i] += x;
    }

    T query(int i) {
        T ret = 0;
        for (i++; i > 0; i -= i & -i) ret += bit[i];
        return ret;
    }

    T query(int l, int r) { return query(r) - query(l - 1); };
};

const int N = 1e5 + 7, B = 330;
int n, q;
array<int, 2> a[N];
vector<array<int, 3>> p[N];
int pos[N], pos2[N], ans[N];
BIT<int> bit[B];
vector<int> srt[N];

int main() {
    cin.tie(0)->sync_with_stdio(false);

    cin >> n >> q;

    for (int i = 0; i < n; i++)
        cin >> a[i][0] >> a[i][1];

    sort(a, a + n, greater<>());

    vector<int> ord(n);
    iota(all(ord), 0);
    sort(all(ord), [&](int x, int y) { return a[x][1] > a[y][1]; });

    for (int i = 0; i < n; i++)
        pos[ord[i]] = i;

    for (int l = 0; l < n; l += B) {
        int b = l / B;
        bit[b].init(B);
        for (int i = l; i < min(l + B, n); i++)
            srt[b].push_back(ord[i]);

        sort(all(srt[b]), [&](int x, int y) { return a[x][0] + a[x][1] > a[y][0] + a[y][1]; });

        for (int i = 0; i < srt[b].size(); i++)
            pos2[srt[b][i]] = i;
    }

    for (int i = 0; i < q; i++) {
        int x, y, z;
        cin >> x >> y >> z;

        if (x <= a[0][0]) {
            array<int, 2> cur = {x, 0};
            int j = upper_bound(a, a + n, cur, greater<>()) - a - 1;
            p[j].push_back({y, z, i});
        }
    }

    auto process = [&](int b, int z) {
        int lo = 0, hi = srt[b].size() - 1, r = -1;
        while (lo <= hi) {
            int mid = (lo + hi) / 2;

            int idx = srt[b][mid];
            if (a[idx][0] + a[idx][1] >= z)
                r = mid, lo = mid + 1;
            else
                hi = mid - 1;
        }

        return (r >= 0 ? bit[b].query(0, r) : 0);
    };

    for (int i = 0; i < n; i++) {
        bit[pos[i] / B].upd(pos2[i], 1);

        for (auto &[y, z, j] : p[i]) {
            int p = 0;
            while (p < n && a[ord[p]][1] >= y) {
                if (p % B == 0 && p + B - 1 < n && a[ord[p + B - 1]][1] >= y) {
                    ans[j] += process(p / B, z);
                    p += B;
                }
                else {
                    ans[j] += ord[p] <= i && a[ord[p]][0] + a[ord[p]][1] >= z;
                    p++;
                }
            }
        }
    }

    for (int i = 0; i < q; i++)
        cout << ans[i] << '\n';

    return 0;
}


Compilation message

examination.cpp: In function 'int main()':
examination.cpp:58:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for (int i = 0; i < srt[b].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 2 ms 6756 KB Output is correct
4 Correct 3 ms 6744 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6744 KB Output is correct
7 Correct 6 ms 6744 KB Output is correct
8 Correct 6 ms 6748 KB Output is correct
9 Correct 6 ms 6748 KB Output is correct
10 Correct 6 ms 6748 KB Output is correct
11 Correct 6 ms 6744 KB Output is correct
12 Correct 6 ms 6792 KB Output is correct
13 Correct 7 ms 7004 KB Output is correct
14 Correct 6 ms 7004 KB Output is correct
15 Correct 7 ms 6800 KB Output is correct
16 Correct 4 ms 6864 KB Output is correct
17 Correct 6 ms 6884 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 608 ms 11340 KB Output is correct
2 Correct 599 ms 13824 KB Output is correct
3 Correct 592 ms 13596 KB Output is correct
4 Correct 596 ms 12860 KB Output is correct
5 Correct 545 ms 12744 KB Output is correct
6 Correct 473 ms 11848 KB Output is correct
7 Correct 656 ms 13324 KB Output is correct
8 Correct 1129 ms 13500 KB Output is correct
9 Correct 1080 ms 13244 KB Output is correct
10 Correct 320 ms 11248 KB Output is correct
11 Correct 647 ms 12576 KB Output is correct
12 Correct 130 ms 9964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 608 ms 11340 KB Output is correct
2 Correct 599 ms 13824 KB Output is correct
3 Correct 592 ms 13596 KB Output is correct
4 Correct 596 ms 12860 KB Output is correct
5 Correct 545 ms 12744 KB Output is correct
6 Correct 473 ms 11848 KB Output is correct
7 Correct 656 ms 13324 KB Output is correct
8 Correct 1129 ms 13500 KB Output is correct
9 Correct 1080 ms 13244 KB Output is correct
10 Correct 320 ms 11248 KB Output is correct
11 Correct 647 ms 12576 KB Output is correct
12 Correct 130 ms 9964 KB Output is correct
13 Correct 1168 ms 13900 KB Output is correct
14 Correct 972 ms 13976 KB Output is correct
15 Correct 633 ms 13600 KB Output is correct
16 Correct 1216 ms 13232 KB Output is correct
17 Correct 614 ms 12956 KB Output is correct
18 Correct 600 ms 11924 KB Output is correct
19 Correct 1131 ms 14036 KB Output is correct
20 Correct 1175 ms 14008 KB Output is correct
21 Correct 1485 ms 13936 KB Output is correct
22 Correct 262 ms 11244 KB Output is correct
23 Correct 464 ms 12584 KB Output is correct
24 Correct 99 ms 10024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 2 ms 6756 KB Output is correct
4 Correct 3 ms 6744 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6744 KB Output is correct
7 Correct 6 ms 6744 KB Output is correct
8 Correct 6 ms 6748 KB Output is correct
9 Correct 6 ms 6748 KB Output is correct
10 Correct 6 ms 6748 KB Output is correct
11 Correct 6 ms 6744 KB Output is correct
12 Correct 6 ms 6792 KB Output is correct
13 Correct 7 ms 7004 KB Output is correct
14 Correct 6 ms 7004 KB Output is correct
15 Correct 7 ms 6800 KB Output is correct
16 Correct 4 ms 6864 KB Output is correct
17 Correct 6 ms 6884 KB Output is correct
18 Correct 3 ms 6748 KB Output is correct
19 Correct 608 ms 11340 KB Output is correct
20 Correct 599 ms 13824 KB Output is correct
21 Correct 592 ms 13596 KB Output is correct
22 Correct 596 ms 12860 KB Output is correct
23 Correct 545 ms 12744 KB Output is correct
24 Correct 473 ms 11848 KB Output is correct
25 Correct 656 ms 13324 KB Output is correct
26 Correct 1129 ms 13500 KB Output is correct
27 Correct 1080 ms 13244 KB Output is correct
28 Correct 320 ms 11248 KB Output is correct
29 Correct 647 ms 12576 KB Output is correct
30 Correct 130 ms 9964 KB Output is correct
31 Correct 1168 ms 13900 KB Output is correct
32 Correct 972 ms 13976 KB Output is correct
33 Correct 633 ms 13600 KB Output is correct
34 Correct 1216 ms 13232 KB Output is correct
35 Correct 614 ms 12956 KB Output is correct
36 Correct 600 ms 11924 KB Output is correct
37 Correct 1131 ms 14036 KB Output is correct
38 Correct 1175 ms 14008 KB Output is correct
39 Correct 1485 ms 13936 KB Output is correct
40 Correct 262 ms 11244 KB Output is correct
41 Correct 464 ms 12584 KB Output is correct
42 Correct 99 ms 10024 KB Output is correct
43 Correct 1212 ms 16060 KB Output is correct
44 Correct 1066 ms 16056 KB Output is correct
45 Correct 892 ms 15896 KB Output is correct
46 Correct 1170 ms 14420 KB Output is correct
47 Correct 543 ms 14384 KB Output is correct
48 Correct 505 ms 11740 KB Output is correct
49 Correct 823 ms 15512 KB Output is correct
50 Correct 1912 ms 15960 KB Output is correct
51 Correct 1684 ms 15544 KB Output is correct
52 Correct 314 ms 12800 KB Output is correct
53 Correct 580 ms 13440 KB Output is correct