답안 #216332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216332 2020-03-27T06:44:52 Z DystoriaX Examination (JOI19_examination) C++14
100 / 100
833 ms 42212 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 200010;

struct BIT{
    vector<int> bit;

    int query(int x){
        int ret = 0;

        for(; x; x -= x & (-x)) ret += bit[x];

        return ret;
    }

    void update(int x, int val){
        for(; x < MAX; x += x & (-x)) bit[x] += val;
    }

    BIT(){
        bit.assign(MAX, 0);
    }

    void init(){
        bit.assign(MAX, 0);
    }
} bitX, bitY;

struct Query{
    int x, y, z, idx;
    bool spec = false;
};

int n, q;
map<int, int> c[3];
vector<int> cp[3];
vector<Query> pt, qr;
int ans[MAX];

void Compress(){
    for(int i = 0; i < 3; i++){
        sort(cp[i].begin(), cp[i].end());
        cp[i].erase(unique(cp[i].begin(), cp[i].end()), cp[i].end());

        int j = 1;
        for(auto k : cp[i]) c[i][k] = j++;
    }

    for(auto &k : pt){
        k.x = c[0][k.x];
        k.y = c[1][k.y];
        k.z = c[2][k.z];
    }

    for(auto &k : qr){
        k.x = c[0][k.x];
        k.y = c[1][k.y];
        k.z = c[2][k.z];
    }
}

bool compQ(Query a, Query b){
    return a.z > b.z;
}

bool compQx(Query a, Query b){
    return a.x > b.x;
}

int main(){
    scanf("%d%d", &n, &q);

    pt.resize(n), qr.resize(q);

    for(int i = 0; i < n; i++){
        scanf("%d%d", &pt[i].x, &pt[i].y);
        pt[i].z = pt[i].x + pt[i].y;

        cp[0].emplace_back(pt[i].x);
        cp[1].emplace_back(pt[i].y);
        cp[2].emplace_back(pt[i].z);
    }

    for(int i = 0; i < q; i++){
        scanf("%d%d%d", &qr[i].x, &qr[i].y, &qr[i].z);
        
        cp[0].emplace_back(qr[i].x);
        cp[1].emplace_back(qr[i].y);
        cp[2].emplace_back(qr[i].z);

        qr[i].idx = i;
        qr[i].spec = (qr[i].x + qr[i].y < qr[i].z);
    }

    Compress();

    sort(pt.begin(), pt.end(), compQ);
    sort(qr.begin(), qr.end(), compQ);

    int id = 0;
    for(auto &k : qr){
        // cout << "Processing " << k.idx << endl;

        while(id < n && pt[id].z >= k.z){
            bitX.update(pt[id].x, 1);
            bitY.update(pt[id].y, 1);
            id++;

            // cout << "Added " << pt[id - 1].x << " " << pt[id - 1].y << endl;
        }

        //Derived from validX + validY - totalValid
        if(k.spec) ans[k.idx] = id - bitX.query(k.x - 1) - bitY.query(k.y - 1);
    }

    sort(pt.begin(), pt.end(), compQx);
    sort(qr.begin(), qr.end(), compQx);

    bitY.init();

    id = 0;
    for(auto &k : qr){
        if(k.spec) continue;

        while(id < n && pt[id].x >= k.x){
            bitY.update(pt[id].y, 1);
            id++;
        }

        ans[k.idx] = id - bitY.query(k.y - 1);
    }

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

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &pt[i].x, &pt[i].y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &qr[i].x, &qr[i].y, &qr[i].z);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1920 KB Output is correct
2 Correct 5 ms 1920 KB Output is correct
3 Correct 6 ms 1920 KB Output is correct
4 Correct 6 ms 1920 KB Output is correct
5 Correct 5 ms 1920 KB Output is correct
6 Correct 6 ms 1920 KB Output is correct
7 Correct 17 ms 3200 KB Output is correct
8 Correct 16 ms 3072 KB Output is correct
9 Correct 16 ms 3072 KB Output is correct
10 Correct 14 ms 2816 KB Output is correct
11 Correct 13 ms 2816 KB Output is correct
12 Correct 11 ms 2176 KB Output is correct
13 Correct 15 ms 2944 KB Output is correct
14 Correct 15 ms 2944 KB Output is correct
15 Correct 14 ms 2944 KB Output is correct
16 Correct 13 ms 2688 KB Output is correct
17 Correct 13 ms 2816 KB Output is correct
18 Correct 9 ms 2176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 477 ms 23300 KB Output is correct
2 Correct 454 ms 23260 KB Output is correct
3 Correct 467 ms 23260 KB Output is correct
4 Correct 300 ms 17900 KB Output is correct
5 Correct 292 ms 17880 KB Output is correct
6 Correct 142 ms 10332 KB Output is correct
7 Correct 419 ms 22284 KB Output is correct
8 Correct 435 ms 22236 KB Output is correct
9 Correct 390 ms 21160 KB Output is correct
10 Correct 284 ms 17756 KB Output is correct
11 Correct 303 ms 17756 KB Output is correct
12 Correct 124 ms 9948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 477 ms 23300 KB Output is correct
2 Correct 454 ms 23260 KB Output is correct
3 Correct 467 ms 23260 KB Output is correct
4 Correct 300 ms 17900 KB Output is correct
5 Correct 292 ms 17880 KB Output is correct
6 Correct 142 ms 10332 KB Output is correct
7 Correct 419 ms 22284 KB Output is correct
8 Correct 435 ms 22236 KB Output is correct
9 Correct 390 ms 21160 KB Output is correct
10 Correct 284 ms 17756 KB Output is correct
11 Correct 303 ms 17756 KB Output is correct
12 Correct 124 ms 9948 KB Output is correct
13 Correct 603 ms 26076 KB Output is correct
14 Correct 563 ms 25460 KB Output is correct
15 Correct 448 ms 23136 KB Output is correct
16 Correct 401 ms 19420 KB Output is correct
17 Correct 377 ms 19516 KB Output is correct
18 Correct 153 ms 10460 KB Output is correct
19 Correct 587 ms 25928 KB Output is correct
20 Correct 587 ms 25692 KB Output is correct
21 Correct 568 ms 25308 KB Output is correct
22 Correct 279 ms 17756 KB Output is correct
23 Correct 288 ms 17880 KB Output is correct
24 Correct 122 ms 9948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1920 KB Output is correct
2 Correct 5 ms 1920 KB Output is correct
3 Correct 6 ms 1920 KB Output is correct
4 Correct 6 ms 1920 KB Output is correct
5 Correct 5 ms 1920 KB Output is correct
6 Correct 6 ms 1920 KB Output is correct
7 Correct 17 ms 3200 KB Output is correct
8 Correct 16 ms 3072 KB Output is correct
9 Correct 16 ms 3072 KB Output is correct
10 Correct 14 ms 2816 KB Output is correct
11 Correct 13 ms 2816 KB Output is correct
12 Correct 11 ms 2176 KB Output is correct
13 Correct 15 ms 2944 KB Output is correct
14 Correct 15 ms 2944 KB Output is correct
15 Correct 14 ms 2944 KB Output is correct
16 Correct 13 ms 2688 KB Output is correct
17 Correct 13 ms 2816 KB Output is correct
18 Correct 9 ms 2176 KB Output is correct
19 Correct 477 ms 23300 KB Output is correct
20 Correct 454 ms 23260 KB Output is correct
21 Correct 467 ms 23260 KB Output is correct
22 Correct 300 ms 17900 KB Output is correct
23 Correct 292 ms 17880 KB Output is correct
24 Correct 142 ms 10332 KB Output is correct
25 Correct 419 ms 22284 KB Output is correct
26 Correct 435 ms 22236 KB Output is correct
27 Correct 390 ms 21160 KB Output is correct
28 Correct 284 ms 17756 KB Output is correct
29 Correct 303 ms 17756 KB Output is correct
30 Correct 124 ms 9948 KB Output is correct
31 Correct 603 ms 26076 KB Output is correct
32 Correct 563 ms 25460 KB Output is correct
33 Correct 448 ms 23136 KB Output is correct
34 Correct 401 ms 19420 KB Output is correct
35 Correct 377 ms 19516 KB Output is correct
36 Correct 153 ms 10460 KB Output is correct
37 Correct 587 ms 25928 KB Output is correct
38 Correct 587 ms 25692 KB Output is correct
39 Correct 568 ms 25308 KB Output is correct
40 Correct 279 ms 17756 KB Output is correct
41 Correct 288 ms 17880 KB Output is correct
42 Correct 122 ms 9948 KB Output is correct
43 Correct 832 ms 42180 KB Output is correct
44 Correct 791 ms 42204 KB Output is correct
45 Correct 833 ms 42200 KB Output is correct
46 Correct 582 ms 31244 KB Output is correct
47 Correct 547 ms 31196 KB Output is correct
48 Correct 156 ms 10076 KB Output is correct
49 Correct 773 ms 42140 KB Output is correct
50 Correct 779 ms 42212 KB Output is correct
51 Correct 738 ms 41944 KB Output is correct
52 Correct 531 ms 31196 KB Output is correct
53 Correct 386 ms 25584 KB Output is correct