Submission #233175

# Submission time Handle Problem Language Result Execution time Memory
233175 2020-05-19T19:35:16 Z Shafin666 Examination (JOI19_examination) C++14
100 / 100
629 ms 16352 KB
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define nyan "(=^・ω・^=)"
#define read_input         freopen("in.txt","r", stdin)
#define print_output       freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 2e5+10;

int n, q;
vector<int> X, Y;
int ans[maxn];

struct event {
    int x, y, z, idx;
}; vector<event> events;

struct tree {
    vector<int> a;
    tree() : a(maxn+1) {}

    void add(int x, int v) {
        for(; x; x -= x & -x)
            a[x] += v;
    }
    int query(int x) {
        int ret = 0;
        for(; x < a.size(); x += x & -x)
            ret += a[x];
        return ret;
    }
} bit;

void trim(vector<int> &v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
}

void solve(int l, int r) {
    if(l == r) return;

    int mid = l + r >> 1;
    solve(l, mid);

    vector<event> qry, upd;

    for(int i = l; i <= mid; i++) {
        if(events[i].idx == 0)
            upd.pb(events[i]);
    }
    for(int i = mid+1; i <= r; i++) {
        if(events[i].idx)
            qry.pb(events[i]);
    }

    sort(qry.begin(), qry.end(), [] (event a, event b) {return a.x > b.x;});
    sort(upd.begin(), upd.end(), [] (event a, event b) {return a.x > b.x;});

    for(int i = 0, j = 0; i < qry.size(); i++) {
        while(j < upd.size() && upd[j].x >= qry[i].x) {
            bit.add(upd[j].y, 1);
            j++;
        }
        ans[qry[i].idx] += bit.query(qry[i].y);
    }
    
    for(auto e : upd) {
        int last = qry.empty()? 1e9+7 : qry[qry.size()-1].x;
        if(e.x < last) break;
        bit.add(e.y, -1);
    }

    solve(mid+1, r);
}

int main() 
{
    cin >> n >> q;

    for(int i = 1; i <= n; i++) {
        int x, y; cin >> x >> y;
        X.pb(x); Y.pb(y);
        event e = {x, y, x+y, 0};
        events.pb(e);
    }
    
    for(int i = 1; i <= q; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        X.pb(x); Y.pb(y);
        event e = {x, y, z, i};
        events.pb(e);
    }

    trim(X); trim(Y);

    for(int i = 0; i < events.size(); i++) {
        event e = events[i];
        e.x = lower_bound(X.begin(), X.end(), e.x) - X.begin() + 1;
        e.y = lower_bound(Y.begin(), Y.end(), e.y) - Y.begin() + 1;
        events[i] = e;
    }

    sort(events.begin(), events.end(), [] (event a, event b) {
        if(a.z == b.z) return a.idx < b.idx;
        return a.z > b.z;
    });

    solve(0, events.size()-1);

    for(int i = 1; i <= q; i++)
        printf("%d\n", ans[i]);

    return 0;  
}

Compilation message

examination.cpp: In member function 'int tree::query(int)':
examination.cpp:31:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(; x < a.size(); x += x & -x)
               ~~^~~~~~~~~~
examination.cpp: In function 'void solve(int, int)':
examination.cpp:45:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid = l + r >> 1;
               ~~^~~
examination.cpp:62:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0, j = 0; i < qry.size(); i++) {
                           ~~^~~~~~~~~~~~
examination.cpp:63:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(j < upd.size() && upd[j].x >= qry[i].x) {
               ~~^~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:100:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < events.size(); i++) {
                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1152 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1152 KB Output is correct
7 Correct 21 ms 1652 KB Output is correct
8 Correct 21 ms 1536 KB Output is correct
9 Correct 21 ms 1536 KB Output is correct
10 Correct 17 ms 1508 KB Output is correct
11 Correct 17 ms 1536 KB Output is correct
12 Correct 12 ms 1396 KB Output is correct
13 Correct 19 ms 1536 KB Output is correct
14 Correct 19 ms 1792 KB Output is correct
15 Correct 18 ms 1664 KB Output is correct
16 Correct 14 ms 1584 KB Output is correct
17 Correct 17 ms 1536 KB Output is correct
18 Correct 11 ms 1408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 14312 KB Output is correct
2 Correct 453 ms 14176 KB Output is correct
3 Correct 466 ms 14304 KB Output is correct
4 Correct 373 ms 13408 KB Output is correct
5 Correct 350 ms 13548 KB Output is correct
6 Correct 267 ms 12756 KB Output is correct
7 Correct 440 ms 14176 KB Output is correct
8 Correct 451 ms 14176 KB Output is correct
9 Correct 435 ms 14048 KB Output is correct
10 Correct 312 ms 13408 KB Output is correct
11 Correct 356 ms 13512 KB Output is correct
12 Correct 230 ms 12640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 14312 KB Output is correct
2 Correct 453 ms 14176 KB Output is correct
3 Correct 466 ms 14304 KB Output is correct
4 Correct 373 ms 13408 KB Output is correct
5 Correct 350 ms 13548 KB Output is correct
6 Correct 267 ms 12756 KB Output is correct
7 Correct 440 ms 14176 KB Output is correct
8 Correct 451 ms 14176 KB Output is correct
9 Correct 435 ms 14048 KB Output is correct
10 Correct 312 ms 13408 KB Output is correct
11 Correct 356 ms 13512 KB Output is correct
12 Correct 230 ms 12640 KB Output is correct
13 Correct 536 ms 13664 KB Output is correct
14 Correct 521 ms 14560 KB Output is correct
15 Correct 463 ms 14176 KB Output is correct
16 Correct 423 ms 12316 KB Output is correct
17 Correct 428 ms 12384 KB Output is correct
18 Correct 279 ms 12512 KB Output is correct
19 Correct 526 ms 13664 KB Output is correct
20 Correct 521 ms 13792 KB Output is correct
21 Correct 524 ms 13612 KB Output is correct
22 Correct 312 ms 13536 KB Output is correct
23 Correct 351 ms 13628 KB Output is correct
24 Correct 231 ms 12768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
3 Correct 5 ms 1152 KB Output is correct
4 Correct 5 ms 1152 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1152 KB Output is correct
7 Correct 21 ms 1652 KB Output is correct
8 Correct 21 ms 1536 KB Output is correct
9 Correct 21 ms 1536 KB Output is correct
10 Correct 17 ms 1508 KB Output is correct
11 Correct 17 ms 1536 KB Output is correct
12 Correct 12 ms 1396 KB Output is correct
13 Correct 19 ms 1536 KB Output is correct
14 Correct 19 ms 1792 KB Output is correct
15 Correct 18 ms 1664 KB Output is correct
16 Correct 14 ms 1584 KB Output is correct
17 Correct 17 ms 1536 KB Output is correct
18 Correct 11 ms 1408 KB Output is correct
19 Correct 450 ms 14312 KB Output is correct
20 Correct 453 ms 14176 KB Output is correct
21 Correct 466 ms 14304 KB Output is correct
22 Correct 373 ms 13408 KB Output is correct
23 Correct 350 ms 13548 KB Output is correct
24 Correct 267 ms 12756 KB Output is correct
25 Correct 440 ms 14176 KB Output is correct
26 Correct 451 ms 14176 KB Output is correct
27 Correct 435 ms 14048 KB Output is correct
28 Correct 312 ms 13408 KB Output is correct
29 Correct 356 ms 13512 KB Output is correct
30 Correct 230 ms 12640 KB Output is correct
31 Correct 536 ms 13664 KB Output is correct
32 Correct 521 ms 14560 KB Output is correct
33 Correct 463 ms 14176 KB Output is correct
34 Correct 423 ms 12316 KB Output is correct
35 Correct 428 ms 12384 KB Output is correct
36 Correct 279 ms 12512 KB Output is correct
37 Correct 526 ms 13664 KB Output is correct
38 Correct 521 ms 13792 KB Output is correct
39 Correct 524 ms 13612 KB Output is correct
40 Correct 312 ms 13536 KB Output is correct
41 Correct 351 ms 13628 KB Output is correct
42 Correct 231 ms 12768 KB Output is correct
43 Correct 629 ms 15584 KB Output is correct
44 Correct 629 ms 15456 KB Output is correct
45 Correct 611 ms 16352 KB Output is correct
46 Correct 475 ms 13576 KB Output is correct
47 Correct 484 ms 13664 KB Output is correct
48 Correct 266 ms 10976 KB Output is correct
49 Correct 607 ms 16352 KB Output is correct
50 Correct 619 ms 15456 KB Output is correct
51 Correct 595 ms 16100 KB Output is correct
52 Correct 443 ms 13384 KB Output is correct
53 Correct 382 ms 14176 KB Output is correct