답안 #201255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201255 2020-02-10T04:02:17 Z BThero Examination (JOI19_examination) C++17
100 / 100
377 ms 16532 KB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
                                                  
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;   
typedef pair<int, int> pii;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = (int)1e5 + 5;

vector<pair<pii, int> > V[5];

pii arr[5][MAXN];

vector<pii> V2;

int arr2[MAXN];

int fenw[MAXN];

int ans[MAXN];

int n, q;

void fenwUpd(int p, int x) {
    for (; p <= n; p |= (p + 1)) {
        fenw[p] += x;
    }
}

int prefSum(int p) {
    int ret = 0;

    for (; p >= 0; --p) {
        ret += fenw[p];
        p &= (p + 1);
    }

    return ret;
}

void solve() {
    scanf("%d %d", &n, &q);

    for (int i = 1; i <= n; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        arr[0][i] = mp(-x, -y);
        arr[1][i] = mp(x, x + y);
        arr[2][i] = mp(y, x + y);
        arr[3][i] = mp(x, y);
        arr[4][i] = mp(x + y, x + y);
    }     

    for (int i = 1; i <= q; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        V[0].pb(mp(mp(-a, -b), i));

        if (c > a + b) {
            V[1].pb(mp(mp(a - 1, c - 1), i));
            V[2].pb(mp(mp(b - 1, c - 1), i));
            V[3].pb(mp(mp(a - 1, b - 1), -i));
            V[4].pb(mp(mp(c - 1, c - 1), -i));
        }          
    }

    for (int i = 0; i < 5; ++i) {
        vector<int> vv;        

        for (int j = 1; j <= n; ++j) {
            vv.pb(arr[i][j].se);
        }

        sort(all(vv));
        vv.resize(unique(all(vv)) - vv.begin());

        for (int j = 1; j <= n; ++j) {
            arr[i][j].se = lower_bound(all(vv), arr[i][j].se) - vv.begin();
        }

        for (auto &it : V[i]) {
            it.fi.se = upper_bound(all(vv), it.fi.se) - vv.begin();
            --it.fi.se;
        }        
        
        sort(all(V[i]));
        sort(arr[i] + 1, arr[i] + n + 1);
        fill(fenw, fenw + n + 1, 0);
        int ptr = 1;

        for (auto it : V[i]) {
            int x, y, id = it.se;
            tie(x, y) = it.fi;

            while (ptr <= n && arr[i][ptr].fi <= x) {
                fenwUpd(arr[i][ptr].se, 1);
                ++ptr;
            }

            if (id < 0) {
                ans[-id] -= prefSum(y);             
            }
            else {
                ans[id] += prefSum(y);            
            }
        }                                                                                                                                                                                         
    }

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

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

examination.cpp: In function 'void solve()':
examination.cpp:57: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:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &a, &b, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 14 ms 760 KB Output is correct
8 Correct 13 ms 892 KB Output is correct
9 Correct 14 ms 892 KB Output is correct
10 Correct 12 ms 760 KB Output is correct
11 Correct 13 ms 760 KB Output is correct
12 Correct 10 ms 760 KB Output is correct
13 Correct 12 ms 760 KB Output is correct
14 Correct 13 ms 760 KB Output is correct
15 Correct 11 ms 760 KB Output is correct
16 Correct 11 ms 636 KB Output is correct
17 Correct 11 ms 756 KB Output is correct
18 Correct 8 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 8552 KB Output is correct
2 Correct 262 ms 10224 KB Output is correct
3 Correct 261 ms 10344 KB Output is correct
4 Correct 221 ms 9412 KB Output is correct
5 Correct 256 ms 9576 KB Output is correct
6 Correct 147 ms 8680 KB Output is correct
7 Correct 276 ms 10248 KB Output is correct
8 Correct 273 ms 10092 KB Output is correct
9 Correct 258 ms 10088 KB Output is correct
10 Correct 263 ms 9196 KB Output is correct
11 Correct 205 ms 9324 KB Output is correct
12 Correct 92 ms 8296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 8552 KB Output is correct
2 Correct 262 ms 10224 KB Output is correct
3 Correct 261 ms 10344 KB Output is correct
4 Correct 221 ms 9412 KB Output is correct
5 Correct 256 ms 9576 KB Output is correct
6 Correct 147 ms 8680 KB Output is correct
7 Correct 276 ms 10248 KB Output is correct
8 Correct 273 ms 10092 KB Output is correct
9 Correct 258 ms 10088 KB Output is correct
10 Correct 263 ms 9196 KB Output is correct
11 Correct 205 ms 9324 KB Output is correct
12 Correct 92 ms 8296 KB Output is correct
13 Correct 336 ms 13612 KB Output is correct
14 Correct 297 ms 11820 KB Output is correct
15 Correct 268 ms 10216 KB Output is correct
16 Correct 275 ms 12272 KB Output is correct
17 Correct 321 ms 12584 KB Output is correct
18 Correct 160 ms 10028 KB Output is correct
19 Correct 333 ms 13360 KB Output is correct
20 Correct 315 ms 13224 KB Output is correct
21 Correct 355 ms 14168 KB Output is correct
22 Correct 249 ms 9196 KB Output is correct
23 Correct 202 ms 9320 KB Output is correct
24 Correct 93 ms 8296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 14 ms 760 KB Output is correct
8 Correct 13 ms 892 KB Output is correct
9 Correct 14 ms 892 KB Output is correct
10 Correct 12 ms 760 KB Output is correct
11 Correct 13 ms 760 KB Output is correct
12 Correct 10 ms 760 KB Output is correct
13 Correct 12 ms 760 KB Output is correct
14 Correct 13 ms 760 KB Output is correct
15 Correct 11 ms 760 KB Output is correct
16 Correct 11 ms 636 KB Output is correct
17 Correct 11 ms 756 KB Output is correct
18 Correct 8 ms 636 KB Output is correct
19 Correct 265 ms 8552 KB Output is correct
20 Correct 262 ms 10224 KB Output is correct
21 Correct 261 ms 10344 KB Output is correct
22 Correct 221 ms 9412 KB Output is correct
23 Correct 256 ms 9576 KB Output is correct
24 Correct 147 ms 8680 KB Output is correct
25 Correct 276 ms 10248 KB Output is correct
26 Correct 273 ms 10092 KB Output is correct
27 Correct 258 ms 10088 KB Output is correct
28 Correct 263 ms 9196 KB Output is correct
29 Correct 205 ms 9324 KB Output is correct
30 Correct 92 ms 8296 KB Output is correct
31 Correct 336 ms 13612 KB Output is correct
32 Correct 297 ms 11820 KB Output is correct
33 Correct 268 ms 10216 KB Output is correct
34 Correct 275 ms 12272 KB Output is correct
35 Correct 321 ms 12584 KB Output is correct
36 Correct 160 ms 10028 KB Output is correct
37 Correct 333 ms 13360 KB Output is correct
38 Correct 315 ms 13224 KB Output is correct
39 Correct 355 ms 14168 KB Output is correct
40 Correct 249 ms 9196 KB Output is correct
41 Correct 202 ms 9320 KB Output is correct
42 Correct 93 ms 8296 KB Output is correct
43 Correct 377 ms 14936 KB Output is correct
44 Correct 351 ms 15656 KB Output is correct
45 Correct 310 ms 13864 KB Output is correct
46 Correct 286 ms 13372 KB Output is correct
47 Correct 337 ms 13424 KB Output is correct
48 Correct 202 ms 12252 KB Output is correct
49 Correct 338 ms 15540 KB Output is correct
50 Correct 368 ms 15968 KB Output is correct
51 Correct 374 ms 16532 KB Output is correct
52 Correct 333 ms 13736 KB Output is correct
53 Correct 203 ms 9960 KB Output is correct