Submission #201255

#TimeUsernameProblemLanguageResultExecution timeMemory
201255BTheroExamination (JOI19_examination)C++17
100 / 100
377 ms16532 KiB
// 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 (stderr)

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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...