답안 #554043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
554043 2022-04-27T15:28:28 Z AA_Surely Examination (JOI19_examination) C++14
100 / 100
1896 ms 12084 KB
#include <bits/stdc++.h>

#define FOR(i,x,n) 	for(int i=x; i<n; i++)
#define F0R(i,n) 	FOR(i,0,n)
#define ROF(i,x,n) 	for(int i=n-1; i>=x; i--)
#define R0F(i,n) 	ROF(i,0,n)

#define IOS 		ios::sync_with_stdio(false); cin.tie(0)
#define F 			first
#define S	 		second
#define pb 			push_back

#define ALL(x) 		x.begin(), x.end()
#define RALL(x) 	x.rbegin(), x.rend()

using namespace std;

typedef pair<int, int> 	PII;
typedef vector<int> 	VI;
typedef vector<PII> 	VPII;

const int N = 1e5 + 7;
const int SQ = 320;
const int TOF = 500;

struct Tutee {
    int a, b, c;

    inline bool operator < (const Tutee &other) {
        return c > other.c;
    }

} ns[N], gooni[N];

struct Query {
    int ma, mb, mc, id;

    inline bool operator < (const Query &other) {
        return mc > other.mc;
    }
} qs[N];

int n, q, sz;
VPII keep[SQ];
VI kp[SQ];
PII whole[N];
int ans[N];

void init() {
    cin >> n >> q;
    VI comp;

    F0R(i, n) {
        cin >> ns[i].a >> ns[i].b;
        ns[i].c = ns[i].a + ns[i].b;
    }

    F0R(i, q) {
        cin >> qs[i].ma >> qs[i].mb >> qs[i].mc;
        qs[i].id = i;
    }

    comp.resize(n);
    F0R(i, n) comp[i] = ns[i].a;
    sort(ALL(comp));
    comp.resize(unique(ALL(comp)) - comp.begin());
    F0R(i, n) ns[i].a = lower_bound(ALL(comp), ns[i].a) - comp.begin();
    F0R(i, q) qs[i].ma = lower_bound(ALL(comp), qs[i].ma) - comp.begin();

    return;
}

inline void rebuild() {
    int pt = 0;
    F0R(i, SQ) {
        for(const PII &on : keep[i]) whole[pt++] = on;
        keep[i].clear();
        kp[i].clear();
    }

    F0R(i, sz) whole[pt++] = PII(gooni[i].a, gooni[i].b);
    sz = 0;

    sort(whole, whole + pt);
    
    F0R(i, pt) {
        keep[i / SQ].pb(whole[i]);
        kp[i / SQ].pb(whole[i].S);
    }

    F0R(i, SQ) sort(ALL(kp[i]));

    return;
}

inline int getKeep(int p) {
    int dasti = SQ - 1;
    F0R(i, SQ) {
        if (!keep[i].empty() && keep[i][0].F >= qs[p].ma) {
            dasti = i - 1;
            break;
        }

        if (keep[i].empty()) {
            dasti = i - 1;
            break;
        }
    }

    int ret = 0; //ret2 = 0;
    if (dasti >= 0) 
        for(const PII &on : keep[dasti]) 
            ret += (on.F >= qs[p].ma && on.S >= qs[p].mb);

    /*F0R(x, SQ)
        for(const PII &on : keep[x]) 
            ret2 += (on.F >= qs[p].ma && on.S >= qs[p].mb);*/

    FOR(i, dasti + 1, SQ) ret += kp[i].size() - (lower_bound(ALL(kp[i]), qs[p].mb) - kp[i].begin());

    return ret;
}

inline int getGooni(int p) {
    int ret = 0;
    F0R(i, sz)
        ret += (gooni[i].a >= qs[p].ma && gooni[i].b >= qs[p].mb);
    return ret;
}

int main() {
    IOS;
    
    init();
    sort(qs, qs + q);
    sort(ns, ns + n);
    
    int ptr = 0;
    F0R(i, q) {
        while(ptr < n && ns[ptr].c >= qs[i].mc) gooni[sz++] = ns[ptr++];
        if (sz >= TOF) rebuild();

        ans[ qs[i].id ] = getKeep(i) + getGooni(i);
    }

    F0R(i, q) cout << ans[i] << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 9 ms 468 KB Output is correct
8 Correct 9 ms 468 KB Output is correct
9 Correct 9 ms 512 KB Output is correct
10 Correct 7 ms 496 KB Output is correct
11 Correct 9 ms 468 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 7 ms 468 KB Output is correct
14 Correct 7 ms 596 KB Output is correct
15 Correct 6 ms 468 KB Output is correct
16 Correct 5 ms 520 KB Output is correct
17 Correct 6 ms 488 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 7744 KB Output is correct
2 Correct 762 ms 7824 KB Output is correct
3 Correct 747 ms 7756 KB Output is correct
4 Correct 601 ms 7840 KB Output is correct
5 Correct 338 ms 7820 KB Output is correct
6 Correct 331 ms 8844 KB Output is correct
7 Correct 1232 ms 10348 KB Output is correct
8 Correct 594 ms 10252 KB Output is correct
9 Correct 959 ms 10344 KB Output is correct
10 Correct 244 ms 9472 KB Output is correct
11 Correct 283 ms 9376 KB Output is correct
12 Correct 152 ms 8500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 7744 KB Output is correct
2 Correct 762 ms 7824 KB Output is correct
3 Correct 747 ms 7756 KB Output is correct
4 Correct 601 ms 7840 KB Output is correct
5 Correct 338 ms 7820 KB Output is correct
6 Correct 331 ms 8844 KB Output is correct
7 Correct 1232 ms 10348 KB Output is correct
8 Correct 594 ms 10252 KB Output is correct
9 Correct 959 ms 10344 KB Output is correct
10 Correct 244 ms 9472 KB Output is correct
11 Correct 283 ms 9376 KB Output is correct
12 Correct 152 ms 8500 KB Output is correct
13 Correct 1664 ms 9716 KB Output is correct
14 Correct 1631 ms 10272 KB Output is correct
15 Correct 757 ms 10392 KB Output is correct
16 Correct 1545 ms 8924 KB Output is correct
17 Correct 1181 ms 8816 KB Output is correct
18 Correct 336 ms 8376 KB Output is correct
19 Correct 1704 ms 9716 KB Output is correct
20 Correct 1776 ms 9660 KB Output is correct
21 Correct 1708 ms 9948 KB Output is correct
22 Correct 251 ms 9428 KB Output is correct
23 Correct 269 ms 9416 KB Output is correct
24 Correct 163 ms 8504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 9 ms 468 KB Output is correct
8 Correct 9 ms 468 KB Output is correct
9 Correct 9 ms 512 KB Output is correct
10 Correct 7 ms 496 KB Output is correct
11 Correct 9 ms 468 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 7 ms 468 KB Output is correct
14 Correct 7 ms 596 KB Output is correct
15 Correct 6 ms 468 KB Output is correct
16 Correct 5 ms 520 KB Output is correct
17 Correct 6 ms 488 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 752 ms 7744 KB Output is correct
20 Correct 762 ms 7824 KB Output is correct
21 Correct 747 ms 7756 KB Output is correct
22 Correct 601 ms 7840 KB Output is correct
23 Correct 338 ms 7820 KB Output is correct
24 Correct 331 ms 8844 KB Output is correct
25 Correct 1232 ms 10348 KB Output is correct
26 Correct 594 ms 10252 KB Output is correct
27 Correct 959 ms 10344 KB Output is correct
28 Correct 244 ms 9472 KB Output is correct
29 Correct 283 ms 9376 KB Output is correct
30 Correct 152 ms 8500 KB Output is correct
31 Correct 1664 ms 9716 KB Output is correct
32 Correct 1631 ms 10272 KB Output is correct
33 Correct 757 ms 10392 KB Output is correct
34 Correct 1545 ms 8924 KB Output is correct
35 Correct 1181 ms 8816 KB Output is correct
36 Correct 336 ms 8376 KB Output is correct
37 Correct 1704 ms 9716 KB Output is correct
38 Correct 1776 ms 9660 KB Output is correct
39 Correct 1708 ms 9948 KB Output is correct
40 Correct 251 ms 9428 KB Output is correct
41 Correct 269 ms 9416 KB Output is correct
42 Correct 163 ms 8504 KB Output is correct
43 Correct 1630 ms 11456 KB Output is correct
44 Correct 1588 ms 11472 KB Output is correct
45 Correct 1535 ms 12052 KB Output is correct
46 Correct 1465 ms 9912 KB Output is correct
47 Correct 1162 ms 9976 KB Output is correct
48 Correct 233 ms 7632 KB Output is correct
49 Correct 1896 ms 11964 KB Output is correct
50 Correct 1461 ms 11560 KB Output is correct
51 Correct 1572 ms 12084 KB Output is correct
52 Correct 1189 ms 9780 KB Output is correct
53 Correct 295 ms 10180 KB Output is correct