답안 #869943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869943 2023-11-06T11:54:46 Z overwatch9 Examination (JOI19_examination) C++17
2 / 100
1270 ms 338332 KB
#include <iostream>
#include <vector>
#include <array>
#include <map>
using namespace std;
using ll = long long;
int n, q;
vector <pair <ll, ll>> ppl;
vector <array <ll, 3>> queries;
struct stree {
    #define lc v*2
    #define rc v*2+1
    vector <map <int, ll>> tree;
    vector <vector <pair <ll, ll>>> tree_pfx;
    stree (int s) {
        tree.resize(s*4);
        tree_pfx.resize(s*4);
    }
    void pushup(int v, int val) {
        tree[v][val]++;
    }
    void update(int v, int tl, int tr, int p, ll val) {
        if (tl > p || tr < p)
            return;
        if (tl == tr) {
            tree[v][val]++;
            return;
        }
        int tm = (tl + tr) / 2;
        update(lc, tl, tm, p, val);
        update(rc, tm+1, tr, p, val);
        pushup(v, val);
    }
    void build_pfx(int v, int tl, int tr) {
        int p = 0;
        tree_pfx[v].resize(tree[v].size());
        for (auto i : tree[v]) {
            tree_pfx[v][p] = i;
            if (p-1 >= 0)
                tree_pfx[v][p].second += tree_pfx[v][p-1].second;
            p++;
        }
        if (tl == tr)
            return;
        int tm = (tl + tr) / 2;
        build_pfx(lc, tl, tm);
        build_pfx(rc, tm+1, tr);
    }
    int query(int v, int tl, int tr, int l, int r, int val) {
        if (tl > r || tr < l)
            return 0;
        if (tl >= l && tr <= r) {
            pair <ll, ll> tp = {val, 0};
            auto x = lower_bound(tree_pfx[v].begin(), tree_pfx[v].end(), tp) - tree_pfx[v].begin();
            if (x == 0)
                return tree_pfx[v].back().second;
            else
                return tree_pfx[v].back().second - tree_pfx[v][x-1].second;
        }
        int tm = (tl + tr) / 2;
        int a = query(lc, tl, tm, l, r, val);
        int b = query(rc, tm+1, tr, l, r, val);
        return a + b;
    }
};
void subtask1() {
    for (int i = 0; i < q; i++) {
        int ans = 0;
        ll a = queries[i][0], b = queries[i][1], c = queries[i][2];
        for (int j = 0; j < n; j++) {
            if (ppl[j].first + ppl[j].second >= c && ppl[j].first >= a && ppl[j].second >= b)
                ans++;
        }
        cout << ans << '\n';
    }
}
void subtask2() {
    int sz = 1e5 + 50;
    stree tree(sz + 1);
    for (int i = 0; i < n; i++) {
        tree.update(1, 0, sz, ppl[i].first, ppl[i].second);
    }
    tree.build_pfx(1, 0, sz);
    for (int i = 0; i < q; i++) {
        cout << tree.query(1, 0, sz, queries[i][0], sz, queries[i][1]) << '\n';
    }
}
int main() {
    cin >> n >> q;
    ppl.resize(n);
    queries.resize(q);
    for (int i = 0; i < n; i++)
        cin >> ppl[i].first >> ppl[i].second;
    for (int i = 0; i < q; i++)
        cin >> queries[i][0] >> queries[i][1] >> queries[i][2];
    if (n <= 3000 && q <= 3000)
        subtask1();
    else
        subtask2();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 27 ms 344 KB Output is correct
8 Correct 35 ms 348 KB Output is correct
9 Correct 28 ms 344 KB Output is correct
10 Correct 27 ms 548 KB Output is correct
11 Correct 29 ms 348 KB Output is correct
12 Correct 30 ms 552 KB Output is correct
13 Correct 27 ms 348 KB Output is correct
14 Correct 27 ms 348 KB Output is correct
15 Correct 27 ms 348 KB Output is correct
16 Correct 20 ms 556 KB Output is correct
17 Correct 21 ms 348 KB Output is correct
18 Correct 9 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1270 ms 338332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1270 ms 338332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 27 ms 344 KB Output is correct
8 Correct 35 ms 348 KB Output is correct
9 Correct 28 ms 344 KB Output is correct
10 Correct 27 ms 548 KB Output is correct
11 Correct 29 ms 348 KB Output is correct
12 Correct 30 ms 552 KB Output is correct
13 Correct 27 ms 348 KB Output is correct
14 Correct 27 ms 348 KB Output is correct
15 Correct 27 ms 348 KB Output is correct
16 Correct 20 ms 556 KB Output is correct
17 Correct 21 ms 348 KB Output is correct
18 Correct 9 ms 348 KB Output is correct
19 Runtime error 1270 ms 338332 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -