Submission #702417

# Submission time Handle Problem Language Result Execution time Memory
702417 2023-02-24T03:10:26 Z PixelCat Examination (JOI19_examination) C++14
100 / 100
592 ms 74196 KB
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 100010;

#define L(id) (id * 2 + 1)
#define R(id) (id * 2 + 2)
struct SegTree {
    vector<int> st[MAXN << 2], t[MAXN << 2];
    void build(int id, int l, int r, vector<int> &vs, vector<vector<int>> &vt) {
        For(it, l, r) for(auto &j:vt[it]) {
            t[id].eb(j);
            st[id].eb(vs[it] + j);
        }
        sort(all(t[id]));
        sort(all(st[id]));
        if(l == r) return;
        int m = (l + r) / 2;
        build(L(id), l, m, vs, vt);
        build(R(id), m + 1, r, vs, vt);
    }
    int count(const vector<int> &v, int x) {
        return v.end() - lower_bound(all(v), x);
    }
    int ask(int id, int l, int r, int L, int R, int type, int x) {
        if(l >= L && r <= R) {
            if(type) return count(t[id], x);
            return count(st[id], x);
        }
        int m = (l + r) / 2;
        if(R <= m) return ask(L(id), l, m, L, R, type, x);
        if(L > m)  return ask(R(id), m + 1, r, L, R, type, x);
        return ask(L(id), l, m, L, R, type, x) +
               ask(R(id), m + 1, r, L, R, type, x);
    }
} seg;

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // nyanyanyanyanya
    int n, q; cin >> n >> q;
    vector<pii> pts;
    vector<int> vs;
    For(i, 1, n) {
        int s, t; cin >> s >> t;
        pts.eb(s, t);
        vs.eb(s);
    }
    sort(all(vs));
    vs.erase(unique(all(vs)), vs.end());
    int m = sz(vs);
    vector<vector<int>> vt(m);
    for(auto &p:pts) {
        int it = lower_bound(all(vs), p.F) - vs.begin();
        vt[it].eb(p.S);
    }
    seg.build(0, 0, m - 1, vs, vt);
    while(q--) {
        int a, b, c; cin >> a >> b >> c;
        int res;
        int p1 = lower_bound(all(vs), a) - vs.begin();
        int p2 = lower_bound(all(vs), c - b) - vs.begin();
        if(p2 <= p1) {
            res = seg.ask(0, 0, m - 1, p1, m, 1, b);
        } else {
            res = seg.ask(0, 0, m - 1, p1, p2 - 1, 0, c) +
                  seg.ask(0, 0, m - 1, p2, m, 1, b);
        }
        cout << res << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 10 ms 19088 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19116 KB Output is correct
5 Correct 10 ms 19040 KB Output is correct
6 Correct 10 ms 19108 KB Output is correct
7 Correct 18 ms 20436 KB Output is correct
8 Correct 20 ms 20464 KB Output is correct
9 Correct 18 ms 20524 KB Output is correct
10 Correct 19 ms 20436 KB Output is correct
11 Correct 13 ms 19540 KB Output is correct
12 Correct 13 ms 19552 KB Output is correct
13 Correct 17 ms 20492 KB Output is correct
14 Correct 18 ms 20468 KB Output is correct
15 Correct 17 ms 20476 KB Output is correct
16 Correct 12 ms 19320 KB Output is correct
17 Correct 16 ms 20472 KB Output is correct
18 Correct 12 ms 19284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 62784 KB Output is correct
2 Correct 416 ms 62944 KB Output is correct
3 Correct 393 ms 62928 KB Output is correct
4 Correct 329 ms 62896 KB Output is correct
5 Correct 140 ms 31532 KB Output is correct
6 Correct 89 ms 31548 KB Output is correct
7 Correct 389 ms 63088 KB Output is correct
8 Correct 359 ms 62984 KB Output is correct
9 Correct 389 ms 62992 KB Output is correct
10 Correct 69 ms 26176 KB Output is correct
11 Correct 241 ms 62716 KB Output is correct
12 Correct 53 ms 25988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 62784 KB Output is correct
2 Correct 416 ms 62944 KB Output is correct
3 Correct 393 ms 62928 KB Output is correct
4 Correct 329 ms 62896 KB Output is correct
5 Correct 140 ms 31532 KB Output is correct
6 Correct 89 ms 31548 KB Output is correct
7 Correct 389 ms 63088 KB Output is correct
8 Correct 359 ms 62984 KB Output is correct
9 Correct 389 ms 62992 KB Output is correct
10 Correct 69 ms 26176 KB Output is correct
11 Correct 241 ms 62716 KB Output is correct
12 Correct 53 ms 25988 KB Output is correct
13 Correct 480 ms 63908 KB Output is correct
14 Correct 487 ms 65808 KB Output is correct
15 Correct 407 ms 65336 KB Output is correct
16 Correct 451 ms 65096 KB Output is correct
17 Correct 142 ms 33620 KB Output is correct
18 Correct 93 ms 32464 KB Output is correct
19 Correct 486 ms 65836 KB Output is correct
20 Correct 487 ms 65944 KB Output is correct
21 Correct 482 ms 65868 KB Output is correct
22 Correct 81 ms 27968 KB Output is correct
23 Correct 254 ms 64612 KB Output is correct
24 Correct 49 ms 26976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 10 ms 19088 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 10 ms 19116 KB Output is correct
5 Correct 10 ms 19040 KB Output is correct
6 Correct 10 ms 19108 KB Output is correct
7 Correct 18 ms 20436 KB Output is correct
8 Correct 20 ms 20464 KB Output is correct
9 Correct 18 ms 20524 KB Output is correct
10 Correct 19 ms 20436 KB Output is correct
11 Correct 13 ms 19540 KB Output is correct
12 Correct 13 ms 19552 KB Output is correct
13 Correct 17 ms 20492 KB Output is correct
14 Correct 18 ms 20468 KB Output is correct
15 Correct 17 ms 20476 KB Output is correct
16 Correct 12 ms 19320 KB Output is correct
17 Correct 16 ms 20472 KB Output is correct
18 Correct 12 ms 19284 KB Output is correct
19 Correct 428 ms 62784 KB Output is correct
20 Correct 416 ms 62944 KB Output is correct
21 Correct 393 ms 62928 KB Output is correct
22 Correct 329 ms 62896 KB Output is correct
23 Correct 140 ms 31532 KB Output is correct
24 Correct 89 ms 31548 KB Output is correct
25 Correct 389 ms 63088 KB Output is correct
26 Correct 359 ms 62984 KB Output is correct
27 Correct 389 ms 62992 KB Output is correct
28 Correct 69 ms 26176 KB Output is correct
29 Correct 241 ms 62716 KB Output is correct
30 Correct 53 ms 25988 KB Output is correct
31 Correct 480 ms 63908 KB Output is correct
32 Correct 487 ms 65808 KB Output is correct
33 Correct 407 ms 65336 KB Output is correct
34 Correct 451 ms 65096 KB Output is correct
35 Correct 142 ms 33620 KB Output is correct
36 Correct 93 ms 32464 KB Output is correct
37 Correct 486 ms 65836 KB Output is correct
38 Correct 487 ms 65944 KB Output is correct
39 Correct 482 ms 65868 KB Output is correct
40 Correct 81 ms 27968 KB Output is correct
41 Correct 254 ms 64612 KB Output is correct
42 Correct 49 ms 26976 KB Output is correct
43 Correct 576 ms 74020 KB Output is correct
44 Correct 524 ms 74072 KB Output is correct
45 Correct 500 ms 74024 KB Output is correct
46 Correct 447 ms 72560 KB Output is correct
47 Correct 151 ms 34740 KB Output is correct
48 Correct 91 ms 32412 KB Output is correct
49 Correct 554 ms 74196 KB Output is correct
50 Correct 585 ms 74044 KB Output is correct
51 Correct 592 ms 73916 KB Output is correct
52 Correct 84 ms 29444 KB Output is correct
53 Correct 282 ms 71592 KB Output is correct