Submission #720537

# Submission time Handle Problem Language Result Execution time Memory
720537 2023-04-08T12:22:46 Z thimote75 Examination (JOI19_examination) C++14
100 / 100
533 ms 23568 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define num long long

#define point pair<num, num>
#define inf 1e18

typedef tree<
    pair<num, int>,
    null_type,
    less<pair<num, int>>,
    rb_tree_tag,
    tree_order_statistics_node_update> ordered_set;

struct Query {
    int id;
    int coef;

    num end_pos;
    num query;

    Query (int _id, int _c, num _p, num _q)
    : id(_id), coef(_c), end_pos(_p), query(_q) {}

    bool operator< (const Query &other) const {
        return end_pos < other.end_pos;
    }
};
struct SQQuery {
    int id;

    num a, b;

    SQQuery (int _id, num _a, num _b)
    : id(_id), a(_a), b(_b) {}

    bool operator< (const SQQuery &other) const {
        return a < other.a;
    }
};

void compute (vector<Query> &queries, vector<int> &result, vector<point> points) {
    sort(points.begin(), points.end());
    sort(queries.begin(), queries.end());

    ordered_set y_points;

    int mu = 0;
    for (Query &q : queries) {
        while (mu != points.size() && points[mu].first < q.end_pos) {
            y_points.insert({ points[mu].first + points[mu].second, mu });
            mu ++;
        }
    
        int res = y_points.size() - y_points.order_of_key({ q.query, -1 });
        result[q.id] += q.coef * res;
    }
}

void compute (vector<SQQuery> &queries, vector<int> &result, vector<point> points) {
    sort(queries.rbegin(), queries.rend());
    sort(points.rbegin(), points.rend());

    ordered_set y_points;

    int mu = 0;
    for (SQQuery &q : queries) {
        while (mu != points.size() && points[mu].first >= q.a) {
            y_points.insert({ points[mu].second, mu });
            mu ++;
        }
        
        int res = y_points.size() - y_points.order_of_key({ q.b, -1 });
        result[q.id] = res;
    }
}

int main () {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int N, Q;
    cin >> N >> Q;

    vector<point> hp;
    vector<point> vp;
    for (int i = 0; i < N; i ++) {
        int x, y;
        cin >> x >> y;

        hp.push_back({ x, y });
        vp.push_back({ y, x });
    }

    vector<Query> hq;
    vector<Query> vq;
    vector<SQQuery> sq;

    for (int q = 0; q < Q; q ++) {
        int a, b, c;
        cin >> a >> b >> c;

        if (a + b > c) {
            sq.push_back(SQQuery(q, a, b));
        } else {
            hq.push_back(Query(q, 1, inf, c));
            hq.push_back(Query(q, -1, a, c));
            vq.push_back(Query(q, -1, b, c));
        }
    }

    vector<int> res(Q);

    compute(hq, res, hp);
    compute(vq, res, vp);
    compute(sq, res, hp);

    for (int i = 0; i < Q; i ++)
        cout << res[i] << endl;
}

Compilation message

examination.cpp: In function 'void compute(std::vector<Query>&, std::vector<int>&, std::vector<std::pair<long long int, long long int> >)':
examination.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         while (mu != points.size() && points[mu].first < q.end_pos) {
      |                ~~~^~~~~~~~~~~~~~~~
examination.cpp: In function 'void compute(std::vector<SQQuery>&, std::vector<int>&, std::vector<std::pair<long long int, long long int> >)':
examination.cpp:74:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         while (mu != points.size() && points[mu].first >= q.a) {
      |                ~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 9 ms 952 KB Output is correct
8 Correct 9 ms 972 KB Output is correct
9 Correct 9 ms 980 KB Output is correct
10 Correct 9 ms 844 KB Output is correct
11 Correct 8 ms 840 KB Output is correct
12 Correct 8 ms 852 KB Output is correct
13 Correct 8 ms 908 KB Output is correct
14 Correct 7 ms 888 KB Output is correct
15 Correct 8 ms 852 KB Output is correct
16 Correct 6 ms 724 KB Output is correct
17 Correct 10 ms 840 KB Output is correct
18 Correct 8 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 255 ms 14784 KB Output is correct
2 Correct 273 ms 17096 KB Output is correct
3 Correct 253 ms 17024 KB Output is correct
4 Correct 257 ms 15780 KB Output is correct
5 Correct 221 ms 16348 KB Output is correct
6 Correct 236 ms 15172 KB Output is correct
7 Correct 287 ms 17000 KB Output is correct
8 Correct 257 ms 16988 KB Output is correct
9 Correct 291 ms 16904 KB Output is correct
10 Correct 213 ms 16128 KB Output is correct
11 Correct 302 ms 15720 KB Output is correct
12 Correct 284 ms 15444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 255 ms 14784 KB Output is correct
2 Correct 273 ms 17096 KB Output is correct
3 Correct 253 ms 17024 KB Output is correct
4 Correct 257 ms 15780 KB Output is correct
5 Correct 221 ms 16348 KB Output is correct
6 Correct 236 ms 15172 KB Output is correct
7 Correct 287 ms 17000 KB Output is correct
8 Correct 257 ms 16988 KB Output is correct
9 Correct 291 ms 16904 KB Output is correct
10 Correct 213 ms 16128 KB Output is correct
11 Correct 302 ms 15720 KB Output is correct
12 Correct 284 ms 15444 KB Output is correct
13 Correct 380 ms 20204 KB Output is correct
14 Correct 346 ms 18648 KB Output is correct
15 Correct 253 ms 16972 KB Output is correct
16 Correct 354 ms 18880 KB Output is correct
17 Correct 320 ms 19304 KB Output is correct
18 Correct 294 ms 16008 KB Output is correct
19 Correct 389 ms 20168 KB Output is correct
20 Correct 380 ms 19852 KB Output is correct
21 Correct 409 ms 21204 KB Output is correct
22 Correct 234 ms 16076 KB Output is correct
23 Correct 300 ms 15760 KB Output is correct
24 Correct 286 ms 15420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 9 ms 952 KB Output is correct
8 Correct 9 ms 972 KB Output is correct
9 Correct 9 ms 980 KB Output is correct
10 Correct 9 ms 844 KB Output is correct
11 Correct 8 ms 840 KB Output is correct
12 Correct 8 ms 852 KB Output is correct
13 Correct 8 ms 908 KB Output is correct
14 Correct 7 ms 888 KB Output is correct
15 Correct 8 ms 852 KB Output is correct
16 Correct 6 ms 724 KB Output is correct
17 Correct 10 ms 840 KB Output is correct
18 Correct 8 ms 724 KB Output is correct
19 Correct 255 ms 14784 KB Output is correct
20 Correct 273 ms 17096 KB Output is correct
21 Correct 253 ms 17024 KB Output is correct
22 Correct 257 ms 15780 KB Output is correct
23 Correct 221 ms 16348 KB Output is correct
24 Correct 236 ms 15172 KB Output is correct
25 Correct 287 ms 17000 KB Output is correct
26 Correct 257 ms 16988 KB Output is correct
27 Correct 291 ms 16904 KB Output is correct
28 Correct 213 ms 16128 KB Output is correct
29 Correct 302 ms 15720 KB Output is correct
30 Correct 284 ms 15444 KB Output is correct
31 Correct 380 ms 20204 KB Output is correct
32 Correct 346 ms 18648 KB Output is correct
33 Correct 253 ms 16972 KB Output is correct
34 Correct 354 ms 18880 KB Output is correct
35 Correct 320 ms 19304 KB Output is correct
36 Correct 294 ms 16008 KB Output is correct
37 Correct 389 ms 20168 KB Output is correct
38 Correct 380 ms 19852 KB Output is correct
39 Correct 409 ms 21204 KB Output is correct
40 Correct 234 ms 16076 KB Output is correct
41 Correct 300 ms 15760 KB Output is correct
42 Correct 286 ms 15420 KB Output is correct
43 Correct 482 ms 21724 KB Output is correct
44 Correct 533 ms 22072 KB Output is correct
45 Correct 525 ms 20552 KB Output is correct
46 Correct 408 ms 20032 KB Output is correct
47 Correct 377 ms 20592 KB Output is correct
48 Correct 301 ms 19512 KB Output is correct
49 Correct 424 ms 21936 KB Output is correct
50 Correct 368 ms 22924 KB Output is correct
51 Correct 347 ms 23568 KB Output is correct
52 Correct 412 ms 20504 KB Output is correct
53 Correct 252 ms 16540 KB Output is correct