답안 #123699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123699 2019-07-02T04:48:52 Z 송준혁(#3032) Examination (JOI19_examination) C++14
100 / 100
1635 ms 272172 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int N, Q;
int ans[101010];
vector<int> xcomp, ycomp;

struct Data{
    int x, y, z, id;
    bool operator<(const Data &r)const{
        if (z == r.z) return id < r.id;
        return z > r.z;
    }
} A[202020];

struct Node{
    int val;
    Node *lc, *rc;

    Node();
} *NIL, *T[101010];

Node :: Node(){
    val = 0;
    lc = rc = NIL;
}

void yupdate(Node *now, int s, int e, int t){
    now->val++;
    if (s == e) return;
    int mid = (s+e)/2;
    if (t <= mid){
        if (now->lc == NIL) now->lc = new Node;
        yupdate(now->lc, s, mid, t);
    }
    else{
        if (now->rc == NIL) now->rc = new Node;
        yupdate(now->rc, mid+1, e, t);
    }
}

int yquery(Node *now, int s, int e, int ts, int te){
    if (e < ts || te < s || now->val == 0) return 0;
    if (ts <= s && e <= te) return now->val;
    int mid = (s+e)/2;
    return yquery(now->lc, s, mid, ts, te) + yquery(now->rc, mid+1, e, ts, te);
}

void xupdate(int tx, int ty){
    while (tx <= N+1){
        yupdate(T[tx], 1, N+1, ty);
        tx += tx & -tx;
    }
}

int xquery(int tx, int ty){
    int ret = 0;
    while (tx){
        ret += yquery(T[tx], 1, N+1, 1, ty);
        tx -= tx & -tx;
    }
    return ret;
}

int main(){
    NIL = new Node;
    NIL->val = 0, NIL->lc = NIL->rc = NIL;

    scanf("%d %d", &N, &Q);
    for (int i=1; i<=N; i++){
        scanf("%d %d", &A[i].x, &A[i].y);
        A[i].z = A[i].x + A[i].y, A[i].id = 0;
        xcomp.push_back(A[i].x);
        ycomp.push_back(A[i].y);
    }
    for (int i=N+1; i<=N+Q; i++){
        scanf("%d %d %d", &A[i].x, &A[i].y, &A[i].z);
        A[i].id = i-N;
    }
    xcomp.push_back(1234567890); ycomp.push_back(1234567890);
    sort(xcomp.begin(), xcomp.end());
    xcomp.erase(unique(xcomp.begin(), xcomp.end()), xcomp.end());
    sort(ycomp.begin(), ycomp.end());
    ycomp.erase(unique(ycomp.begin(), ycomp.end()), ycomp.end());
    for (int i=1; i<=N+1; i++) T[i] = new Node;
    sort(A+1, A+N+Q+1);
    for (int i=1; i<=N+Q; i++){
        A[i].x  = N+1 - (lower_bound(xcomp.begin(), xcomp.end(), A[i].x) - xcomp.begin());
        A[i].y  = N+1 - (lower_bound(ycomp.begin(), ycomp.end(), A[i].y) - ycomp.begin());
        if (!A[i].id) xupdate(A[i].x, A[i].y);
        else ans[A[i].id] = xquery(A[i].x, A[i].y);
    }
    for (int i=1; i<=Q; i++) printf("%d\n", ans[i]);
    return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:70: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:72:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &A[i].x, &A[i].y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:78:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &A[i].x, &A[i].y, &A[i].z);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 17 ms 4600 KB Output is correct
8 Correct 17 ms 4600 KB Output is correct
9 Correct 17 ms 4728 KB Output is correct
10 Correct 10 ms 1912 KB Output is correct
11 Correct 8 ms 1272 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 17 ms 4604 KB Output is correct
14 Correct 18 ms 4600 KB Output is correct
15 Correct 18 ms 4728 KB Output is correct
16 Correct 6 ms 808 KB Output is correct
17 Correct 9 ms 1656 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1469 ms 236920 KB Output is correct
2 Correct 1359 ms 237460 KB Output is correct
3 Correct 1322 ms 237436 KB Output is correct
4 Correct 465 ms 52344 KB Output is correct
5 Correct 262 ms 28656 KB Output is correct
6 Correct 122 ms 9708 KB Output is correct
7 Correct 1341 ms 237452 KB Output is correct
8 Correct 1261 ms 237224 KB Output is correct
9 Correct 1113 ms 237500 KB Output is correct
10 Correct 150 ms 13512 KB Output is correct
11 Correct 316 ms 41320 KB Output is correct
12 Correct 79 ms 9452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1469 ms 236920 KB Output is correct
2 Correct 1359 ms 237460 KB Output is correct
3 Correct 1322 ms 237436 KB Output is correct
4 Correct 465 ms 52344 KB Output is correct
5 Correct 262 ms 28656 KB Output is correct
6 Correct 122 ms 9708 KB Output is correct
7 Correct 1341 ms 237452 KB Output is correct
8 Correct 1261 ms 237224 KB Output is correct
9 Correct 1113 ms 237500 KB Output is correct
10 Correct 150 ms 13512 KB Output is correct
11 Correct 316 ms 41320 KB Output is correct
12 Correct 79 ms 9452 KB Output is correct
13 Correct 1223 ms 237312 KB Output is correct
14 Correct 1369 ms 237356 KB Output is correct
15 Correct 1635 ms 237544 KB Output is correct
16 Correct 395 ms 52560 KB Output is correct
17 Correct 239 ms 28652 KB Output is correct
18 Correct 132 ms 9708 KB Output is correct
19 Correct 1187 ms 237384 KB Output is correct
20 Correct 1364 ms 237288 KB Output is correct
21 Correct 1061 ms 237608 KB Output is correct
22 Correct 145 ms 13548 KB Output is correct
23 Correct 313 ms 41196 KB Output is correct
24 Correct 79 ms 9324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 17 ms 4600 KB Output is correct
8 Correct 17 ms 4600 KB Output is correct
9 Correct 17 ms 4728 KB Output is correct
10 Correct 10 ms 1912 KB Output is correct
11 Correct 8 ms 1272 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 17 ms 4604 KB Output is correct
14 Correct 18 ms 4600 KB Output is correct
15 Correct 18 ms 4728 KB Output is correct
16 Correct 6 ms 808 KB Output is correct
17 Correct 9 ms 1656 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 1469 ms 236920 KB Output is correct
20 Correct 1359 ms 237460 KB Output is correct
21 Correct 1322 ms 237436 KB Output is correct
22 Correct 465 ms 52344 KB Output is correct
23 Correct 262 ms 28656 KB Output is correct
24 Correct 122 ms 9708 KB Output is correct
25 Correct 1341 ms 237452 KB Output is correct
26 Correct 1261 ms 237224 KB Output is correct
27 Correct 1113 ms 237500 KB Output is correct
28 Correct 150 ms 13512 KB Output is correct
29 Correct 316 ms 41320 KB Output is correct
30 Correct 79 ms 9452 KB Output is correct
31 Correct 1223 ms 237312 KB Output is correct
32 Correct 1369 ms 237356 KB Output is correct
33 Correct 1635 ms 237544 KB Output is correct
34 Correct 395 ms 52560 KB Output is correct
35 Correct 239 ms 28652 KB Output is correct
36 Correct 132 ms 9708 KB Output is correct
37 Correct 1187 ms 237384 KB Output is correct
38 Correct 1364 ms 237288 KB Output is correct
39 Correct 1061 ms 237608 KB Output is correct
40 Correct 145 ms 13548 KB Output is correct
41 Correct 313 ms 41196 KB Output is correct
42 Correct 79 ms 9324 KB Output is correct
43 Correct 1367 ms 271728 KB Output is correct
44 Correct 1264 ms 271972 KB Output is correct
45 Correct 1511 ms 271924 KB Output is correct
46 Correct 457 ms 72188 KB Output is correct
47 Correct 265 ms 34664 KB Output is correct
48 Correct 121 ms 10016 KB Output is correct
49 Correct 1288 ms 272076 KB Output is correct
50 Correct 1123 ms 272172 KB Output is correct
51 Correct 1050 ms 272160 KB Output is correct
52 Correct 175 ms 16260 KB Output is correct
53 Correct 364 ms 60392 KB Output is correct