Submission #166034

# Submission time Handle Problem Language Result Execution time Memory
166034 2019-11-30T09:44:26 Z Akashi Examination (JOI19_examination) C++14
100 / 100
2619 ms 372020 KB
#include <bits/stdc++.h>
using namespace std;

struct grades{
    int x, y, z;
    bool operator < (const grades &aux)const{
        if(z != aux.z) return z > aux.z;
        if(x != aux.x) return x > aux.x;
        return y > aux.y;
    }
};
struct teacher{
    int x, y, z, p;
    bool operator < (const teacher &aux)const{
        if(z != aux.z) return z > aux.z;
        if(x != aux.x) return x > aux.x;
        return y > aux.y;
    }
};

grades a[100005];
teacher b[100005];
int ans[100005];

int n, q;

struct node{
    int tip, val;
    int left, right;
};

node Tree[32000005];

int y, nx, ny, NR;
void update(int x, int nod, int st, int dr){
    if(st == dr){
        if(Tree[nod].tip == 1){
            if(Tree[nod].val == 0){
                Tree[nod].val = ++NR;
                Tree[NR].tip = 0;
            }
            update(y, Tree[nod].val, 1, ny);
        }
        else ++Tree[nod].val;
        return ;
    }

    int mij = (st + dr) / 2;
    if(x <= mij){
        if(Tree[nod].left == 0){
            Tree[nod].left = ++NR;
            Tree[NR].tip = Tree[nod].tip;
        }
        update(x, Tree[nod].left, st, mij);
    }
    else{
        if(Tree[nod].right == 0){
            Tree[nod].right = ++NR;
            Tree[NR].tip = Tree[nod].tip;
        }
        update(x, Tree[nod].right, mij + 1, dr);
    }

    if(Tree[nod].tip == 1){
        if(Tree[nod].val == 0){
            Tree[nod].val = ++NR;
            Tree[NR].tip = 0;
        }
        update(y, Tree[nod].val, 1, ny);
    }
    else Tree[nod].val = Tree[Tree[nod].left].val + Tree[Tree[nod].right].val;

}

int yr, yl;
int query(int x, int y, int nod, int st, int dr){
    if(x <= st && dr <= y){
        if(Tree[nod].tip == 1){
            if(Tree[nod].val == 0) return 0;
            return query(yl, yr, Tree[nod].val, 1, ny);
        }
        else return Tree[nod].val;
    }

    int mij = (st + dr) / 2;

    int val = 0;
    if(x <= mij){
        if(Tree[nod].left) val += query(x, y, Tree[nod].left, st, mij);
    }
    if(mij + 1 <= y){
        if(Tree[nod].right) val += query(x, y, Tree[nod].right, mij + 1, dr);
    }

    return val;
}

set <int> sx, sy;
map <int, int> fx, fy;

int main()
{
    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;
        sx.insert(a[i].x); sy.insert(a[i].y);
    }

    for(int i = 1; i <= q ; ++i){
        scanf("%d%d%d", &b[i].x, &b[i].y, &b[i].z), b[i].p = i;
        sx.insert(b[i].x); sy.insert(b[i].y);
    }

    for(auto it : sx) fx[it] = ++nx;
    for(auto it : sy) fy[it] = ++ny;

    for(int i = 1; i <= n ; ++i) a[i].x = fx[a[i].x], a[i].y = fy[a[i].y];
    for(int i = 1; i <= q ; ++i) b[i].x = fx[b[i].x], b[i].y = fy[b[i].y];

    sort(a + 1, a + n + 1);
    sort(b + 1, b + q + 1);

    int j = 1;
    Tree[++NR].tip = 1;
    for(int i = 1; i <= q ; ++i){
        while(j <= n && a[j].z >= b[i].z){
            y = a[j].y;
            update(a[j].x, 1, 1, nx);
            ++j;
        }

        yl = b[i].y; yr = ny;
        ans[b[i].p] = query(b[i].x, nx, 1, 1, nx);
    }

//    nx = 200000; ny = 200000;
//    srand(time(NULL));
//    for(int i = 1; i <= 100000 ; ++i){
//        y = rand() % (200000) + 1;
//        int x = rand() % (200000) + 1;
//        update(x, 1, 1, nx);
//        if(i % 1000 == 0) cerr << NR << endl;
//    }
//

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

    return 0;
}

















Compilation message

examination.cpp: In function 'int main()':
examination.cpp:103: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:105: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:111:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &b[i].x, &b[i].y, &b[i].z), b[i].p = i;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 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 28 ms 7160 KB Output is correct
8 Correct 27 ms 7160 KB Output is correct
9 Correct 62 ms 7288 KB Output is correct
10 Correct 12 ms 2040 KB Output is correct
11 Correct 12 ms 1948 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 29 ms 7032 KB Output is correct
14 Correct 54 ms 7288 KB Output is correct
15 Correct 27 ms 7160 KB Output is correct
16 Correct 16 ms 1400 KB Output is correct
17 Correct 10 ms 1400 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1687 ms 274104 KB Output is correct
2 Correct 1713 ms 276532 KB Output is correct
3 Correct 1623 ms 276540 KB Output is correct
4 Correct 443 ms 37112 KB Output is correct
5 Correct 447 ms 34636 KB Output is correct
6 Correct 115 ms 5112 KB Output is correct
7 Correct 1626 ms 262964 KB Output is correct
8 Correct 1482 ms 263588 KB Output is correct
9 Correct 1409 ms 250452 KB Output is correct
10 Correct 394 ms 18552 KB Output is correct
11 Correct 364 ms 20836 KB Output is correct
12 Correct 76 ms 4768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1687 ms 274104 KB Output is correct
2 Correct 1713 ms 276532 KB Output is correct
3 Correct 1623 ms 276540 KB Output is correct
4 Correct 443 ms 37112 KB Output is correct
5 Correct 447 ms 34636 KB Output is correct
6 Correct 115 ms 5112 KB Output is correct
7 Correct 1626 ms 262964 KB Output is correct
8 Correct 1482 ms 263588 KB Output is correct
9 Correct 1409 ms 250452 KB Output is correct
10 Correct 394 ms 18552 KB Output is correct
11 Correct 364 ms 20836 KB Output is correct
12 Correct 76 ms 4768 KB Output is correct
13 Correct 1798 ms 277068 KB Output is correct
14 Correct 2127 ms 277020 KB Output is correct
15 Correct 1761 ms 276376 KB Output is correct
16 Correct 462 ms 37240 KB Output is correct
17 Correct 497 ms 35156 KB Output is correct
18 Correct 118 ms 5068 KB Output is correct
19 Correct 1942 ms 277252 KB Output is correct
20 Correct 1943 ms 276924 KB Output is correct
21 Correct 1633 ms 267444 KB Output is correct
22 Correct 340 ms 18416 KB Output is correct
23 Correct 353 ms 20756 KB Output is correct
24 Correct 75 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 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 28 ms 7160 KB Output is correct
8 Correct 27 ms 7160 KB Output is correct
9 Correct 62 ms 7288 KB Output is correct
10 Correct 12 ms 2040 KB Output is correct
11 Correct 12 ms 1948 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 29 ms 7032 KB Output is correct
14 Correct 54 ms 7288 KB Output is correct
15 Correct 27 ms 7160 KB Output is correct
16 Correct 16 ms 1400 KB Output is correct
17 Correct 10 ms 1400 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
19 Correct 1687 ms 274104 KB Output is correct
20 Correct 1713 ms 276532 KB Output is correct
21 Correct 1623 ms 276540 KB Output is correct
22 Correct 443 ms 37112 KB Output is correct
23 Correct 447 ms 34636 KB Output is correct
24 Correct 115 ms 5112 KB Output is correct
25 Correct 1626 ms 262964 KB Output is correct
26 Correct 1482 ms 263588 KB Output is correct
27 Correct 1409 ms 250452 KB Output is correct
28 Correct 394 ms 18552 KB Output is correct
29 Correct 364 ms 20836 KB Output is correct
30 Correct 76 ms 4768 KB Output is correct
31 Correct 1798 ms 277068 KB Output is correct
32 Correct 2127 ms 277020 KB Output is correct
33 Correct 1761 ms 276376 KB Output is correct
34 Correct 462 ms 37240 KB Output is correct
35 Correct 497 ms 35156 KB Output is correct
36 Correct 118 ms 5068 KB Output is correct
37 Correct 1942 ms 277252 KB Output is correct
38 Correct 1943 ms 276924 KB Output is correct
39 Correct 1633 ms 267444 KB Output is correct
40 Correct 340 ms 18416 KB Output is correct
41 Correct 353 ms 20756 KB Output is correct
42 Correct 75 ms 4728 KB Output is correct
43 Correct 2400 ms 371992 KB Output is correct
44 Correct 2435 ms 372020 KB Output is correct
45 Correct 2619 ms 371800 KB Output is correct
46 Correct 658 ms 60436 KB Output is correct
47 Correct 672 ms 56032 KB Output is correct
48 Correct 117 ms 4896 KB Output is correct
49 Correct 2293 ms 355780 KB Output is correct
50 Correct 2134 ms 356600 KB Output is correct
51 Correct 2093 ms 339776 KB Output is correct
52 Correct 551 ms 34700 KB Output is correct
53 Correct 531 ms 38108 KB Output is correct