답안 #209626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209626 2020-03-14T22:34:32 Z tri Examination (JOI19_examination) C++14
100 / 100
730 ms 16228 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef tuple<int, int, int, int> qi;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef tree<
        pi,
        null_type,
        less<pi>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;

#define pb push_back
#define f first
#define s second

namespace debug {
    const int DEBUG = true;

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x);

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x);

    template<class T>
    void pr(const vector<T> &x);

    template<class T>
    void pr(const set<T> &x);

    template<class T1, class T2>
    void pr(const map<T1, T2> &x);

    template<class T>
    void pr(const T &x) { if (DEBUG) cout << x; }

    template<class T, class... Ts>
    void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }

    template<class T>
    void prIn(const T &x) {
        pr("{");
        bool fst = 1;
        for (auto &a : x) {
            pr(fst ? "" : ", ", a), fst = 0;
        }
        pr("}");
    }

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x) { prIn(x); }

    template<class T>
    void pr(const vector<T> &x) { prIn(x); }

    template<class T>
    void pr(const set<T> &x) { prIn(x); }

    template<class T1, class T2>
    void pr(const map<T1, T2> &x) { prIn(x); }

    void ps() { pr("\n"), cout << flush; }

    template<class Arg, class... Args>
    void ps(const Arg &first, const Args &... rest) {
        pr(first, " ");
        ps(rest...);
    }
}
using namespace debug;


const int MAXN = 1e5 + 5;

int N, Q;

pi pts[MAXN];

qi q[MAXN];

int ans[MAXN];

bool lessSum(pi a, pi b) {
    return a.f + a.s < b.f + b.s;
}

int main() {
    cin >> N >> Q;
    for (int i = 0; i < N; i++) {
        cin >> pts[i].f >> pts[i].s;
    }

    for (int i = 0; i < Q; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        z = max(z, x + y);
        q[i] = {z, x, y, i};
    }

    sort(pts, pts + N, lessSum);
    reverse(pts, pts + N);

    sort(q, q + Q);
    reverse(q, q + Q);

    ordered_set byX;
    ordered_set byY;

    int nP = 0;
    for (int i = 0; i < Q; i++) {
        auto cQ = q[i];
        int sum, xL, yL, qI;
        tie(sum, xL, yL, qI) = cQ;

        while (nP < N && pts[nP].f + pts[nP].s >= sum) {
            byX.insert({pts[nP].f, nP});

            byY.insert({pts[nP].s, nP});

            nP++;
        }

        assert(byX.size() == byY.size());
        int cnt = byX.size();
//        cout << cnt << endl;
        cnt -= byX.order_of_key({xL, -1});
        cnt -= byY.order_of_key({yL, -1});

        assert(cnt >= 0);
        ans[qI] = cnt;
    }
    for (int i = 0; i < Q; i++) {
        cout << ans[i] << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 22 ms 760 KB Output is correct
8 Correct 24 ms 764 KB Output is correct
9 Correct 23 ms 760 KB Output is correct
10 Correct 21 ms 760 KB Output is correct
11 Correct 20 ms 760 KB Output is correct
12 Correct 16 ms 760 KB Output is correct
13 Correct 26 ms 760 KB Output is correct
14 Correct 21 ms 760 KB Output is correct
15 Correct 21 ms 760 KB Output is correct
16 Correct 20 ms 760 KB Output is correct
17 Correct 21 ms 760 KB Output is correct
18 Correct 16 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 643 ms 16096 KB Output is correct
2 Correct 624 ms 16120 KB Output is correct
3 Correct 637 ms 16120 KB Output is correct
4 Correct 469 ms 16120 KB Output is correct
5 Correct 476 ms 16120 KB Output is correct
6 Correct 428 ms 16120 KB Output is correct
7 Correct 594 ms 16120 KB Output is correct
8 Correct 588 ms 16120 KB Output is correct
9 Correct 579 ms 16104 KB Output is correct
10 Correct 501 ms 15992 KB Output is correct
11 Correct 506 ms 15992 KB Output is correct
12 Correct 476 ms 15736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 643 ms 16096 KB Output is correct
2 Correct 624 ms 16120 KB Output is correct
3 Correct 637 ms 16120 KB Output is correct
4 Correct 469 ms 16120 KB Output is correct
5 Correct 476 ms 16120 KB Output is correct
6 Correct 428 ms 16120 KB Output is correct
7 Correct 594 ms 16120 KB Output is correct
8 Correct 588 ms 16120 KB Output is correct
9 Correct 579 ms 16104 KB Output is correct
10 Correct 501 ms 15992 KB Output is correct
11 Correct 506 ms 15992 KB Output is correct
12 Correct 476 ms 15736 KB Output is correct
13 Correct 614 ms 16184 KB Output is correct
14 Correct 611 ms 16120 KB Output is correct
15 Correct 620 ms 16076 KB Output is correct
16 Correct 488 ms 16120 KB Output is correct
17 Correct 492 ms 16120 KB Output is correct
18 Correct 426 ms 16120 KB Output is correct
19 Correct 605 ms 16120 KB Output is correct
20 Correct 637 ms 15992 KB Output is correct
21 Correct 601 ms 16124 KB Output is correct
22 Correct 512 ms 15992 KB Output is correct
23 Correct 498 ms 15992 KB Output is correct
24 Correct 486 ms 15740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Correct 22 ms 760 KB Output is correct
8 Correct 24 ms 764 KB Output is correct
9 Correct 23 ms 760 KB Output is correct
10 Correct 21 ms 760 KB Output is correct
11 Correct 20 ms 760 KB Output is correct
12 Correct 16 ms 760 KB Output is correct
13 Correct 26 ms 760 KB Output is correct
14 Correct 21 ms 760 KB Output is correct
15 Correct 21 ms 760 KB Output is correct
16 Correct 20 ms 760 KB Output is correct
17 Correct 21 ms 760 KB Output is correct
18 Correct 16 ms 760 KB Output is correct
19 Correct 643 ms 16096 KB Output is correct
20 Correct 624 ms 16120 KB Output is correct
21 Correct 637 ms 16120 KB Output is correct
22 Correct 469 ms 16120 KB Output is correct
23 Correct 476 ms 16120 KB Output is correct
24 Correct 428 ms 16120 KB Output is correct
25 Correct 594 ms 16120 KB Output is correct
26 Correct 588 ms 16120 KB Output is correct
27 Correct 579 ms 16104 KB Output is correct
28 Correct 501 ms 15992 KB Output is correct
29 Correct 506 ms 15992 KB Output is correct
30 Correct 476 ms 15736 KB Output is correct
31 Correct 614 ms 16184 KB Output is correct
32 Correct 611 ms 16120 KB Output is correct
33 Correct 620 ms 16076 KB Output is correct
34 Correct 488 ms 16120 KB Output is correct
35 Correct 492 ms 16120 KB Output is correct
36 Correct 426 ms 16120 KB Output is correct
37 Correct 605 ms 16120 KB Output is correct
38 Correct 637 ms 15992 KB Output is correct
39 Correct 601 ms 16124 KB Output is correct
40 Correct 512 ms 15992 KB Output is correct
41 Correct 498 ms 15992 KB Output is correct
42 Correct 486 ms 15740 KB Output is correct
43 Correct 695 ms 16120 KB Output is correct
44 Correct 684 ms 16120 KB Output is correct
45 Correct 730 ms 16120 KB Output is correct
46 Correct 607 ms 16120 KB Output is correct
47 Correct 594 ms 16052 KB Output is correct
48 Correct 426 ms 15864 KB Output is correct
49 Correct 726 ms 16216 KB Output is correct
50 Correct 702 ms 16128 KB Output is correct
51 Correct 697 ms 16228 KB Output is correct
52 Correct 630 ms 15992 KB Output is correct
53 Correct 593 ms 15996 KB Output is correct