Submission #187535

# Submission time Handle Problem Language Result Execution time Memory
187535 2020-01-13T02:49:15 Z ToMmyDong Examination (JOI19_examination) C++11
100 / 100
828 ms 16988 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#ifdef tmdd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
    os<<"{";
    for(It it=bg;it!=ed;it++) {
        os<<(it==bg?"":",")<<*it;
    }
    os<<"}";
    return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif


const int MAXN = 200005;
const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int n, q;

struct Query {
    int id;
    int x, y, z;
};

ostream &operator << (ostream &os, Query &q) {
    return os << "{" << q.id << ":" << q.x << "," << q.y << "," << q.z << "}";
}

bool byZ (const Query &q1, const Query &q2) {
    return q1.z < q2.z;
}

bool byX (const Query &q1, const Query &q2) {
    return q1.x < q2.x;
}
Query qry[MAXN];
int ans[MAXN];

int bit[MAXN];

void add (int x, int val) {
    for (x++;x<MAXN;x+=-x&x) {
        bit[x] += val;
    }
}

int sum (int x) {
    int ret = 0;
    for (x++;x>0;x-=-x&x) {
        ret += bit[x];
    }
    return ret;
}

void solve (int l, int r) {
//    cerr << l << " " << r << " " << qry[l].z << " " << qry[r-1].z << endl;
//    if (l == r) {
//        for (int i=l-10;i<r+10;i++) {
//            cerr<<qry[i] << endl;
//        }
//    }
    assert(l != r);
    if (qry[l].z == qry[r-1].z) {
        return;
    } else {
        int mid = (qry[l].z + qry[r-1].z) >> 1;
        int m;
        for (m=l;m<r;m++) {
            if (qry[m].z > mid) {
                break;
            }
        }

        solve(l,m);
        solve(m,r);

        sort(qry+l,qry+m,byX);
        sort(qry+m,qry+r,byX);

        debug(l, m, r);
        pary(qry+l, qry+m);
        pary(qry+m, qry+r);


        vector<int> opr;

        int rid = r-1;
        for (int i=m-1;i>=l;i--) {
            while (rid>=m&&qry[rid].x>=qry[i].x) {
                if (qry[rid].id == -1) {
                    add(qry[rid].y, 1);
                    opr.emplace_back(qry[rid].y);
                }
                rid--;
            }
            if (qry[i].id != -1) {
                int dl = sum(MAXN-2) - sum(qry[i].y-1);
                ans[qry[i].id] += dl;
            }
        }

        for (auto id : opr) {
            add(id, -1);
        }

        sort(qry+l,qry+r,byZ);
    }
}


vector<int> yval;
/*********************GoodLuck***********************/
signed main () {
    IOS();

    cin >> n >> q;

    REP (i, n) {
        #ifdef tmd
        qry[i].x = rand()%MOD;
        qry[i].y = rand()%MOD;
        #else
        cin >> qry[i].x >> qry[i].y;
        #endif
        qry[i].z = qry[i].x+qry[i].y+1;
        qry[i].id = -1;
        yval.emplace_back(qry[i].y);
    }

    for (int i=n;i<n+q;i++) {
        #ifdef tmd
        qry[i].x = rand()%MOD;
        qry[i].y = rand()%MOD;
        qry[i].z = rand();
        #else
        cin >> qry[i].x >> qry[i].y >> qry[i].z;
        #endif
        qry[i].id = i-n;
        yval.emplace_back(qry[i].y);
    }

    sort(yval.begin(),yval.end());
    yval.resize(unique(yval.begin(),yval.end())-yval.begin());
    for (int i=0;i<n+q;i++) {
        qry[i].y = lower_bound(yval.begin(),yval.end(),qry[i].y)-yval.begin();
    }
    debug("en d");


    sort(qry,qry+n+q,byZ);
    pary(qry,qry+n+q);
    solve(0, n+q);
    REP (i, q) {
        cout << ans[i] << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 348 KB Output is correct
2 Correct 1 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 8 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 18 ms 860 KB Output is correct
8 Correct 17 ms 888 KB Output is correct
9 Correct 17 ms 888 KB Output is correct
10 Correct 15 ms 888 KB Output is correct
11 Correct 13 ms 888 KB Output is correct
12 Correct 7 ms 760 KB Output is correct
13 Correct 14 ms 1016 KB Output is correct
14 Correct 14 ms 940 KB Output is correct
15 Correct 12 ms 888 KB Output is correct
16 Correct 13 ms 888 KB Output is correct
17 Correct 16 ms 888 KB Output is correct
18 Correct 5 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 594 ms 11348 KB Output is correct
2 Correct 571 ms 13720 KB Output is correct
3 Correct 582 ms 13672 KB Output is correct
4 Correct 555 ms 12432 KB Output is correct
5 Correct 555 ms 12928 KB Output is correct
6 Correct 193 ms 11624 KB Output is correct
7 Correct 553 ms 13772 KB Output is correct
8 Correct 558 ms 13416 KB Output is correct
9 Correct 551 ms 13408 KB Output is correct
10 Correct 483 ms 12904 KB Output is correct
11 Correct 539 ms 12076 KB Output is correct
12 Correct 98 ms 11976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 594 ms 11348 KB Output is correct
2 Correct 571 ms 13720 KB Output is correct
3 Correct 582 ms 13672 KB Output is correct
4 Correct 555 ms 12432 KB Output is correct
5 Correct 555 ms 12928 KB Output is correct
6 Correct 193 ms 11624 KB Output is correct
7 Correct 553 ms 13772 KB Output is correct
8 Correct 558 ms 13416 KB Output is correct
9 Correct 551 ms 13408 KB Output is correct
10 Correct 483 ms 12904 KB Output is correct
11 Correct 539 ms 12076 KB Output is correct
12 Correct 98 ms 11976 KB Output is correct
13 Correct 768 ms 14072 KB Output is correct
14 Correct 761 ms 14212 KB Output is correct
15 Correct 592 ms 13700 KB Output is correct
16 Correct 672 ms 12820 KB Output is correct
17 Correct 638 ms 13304 KB Output is correct
18 Correct 190 ms 11608 KB Output is correct
19 Correct 770 ms 14268 KB Output is correct
20 Correct 770 ms 14188 KB Output is correct
21 Correct 758 ms 14184 KB Output is correct
22 Correct 497 ms 12904 KB Output is correct
23 Correct 510 ms 12140 KB Output is correct
24 Correct 111 ms 11804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 348 KB Output is correct
2 Correct 1 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 8 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 18 ms 860 KB Output is correct
8 Correct 17 ms 888 KB Output is correct
9 Correct 17 ms 888 KB Output is correct
10 Correct 15 ms 888 KB Output is correct
11 Correct 13 ms 888 KB Output is correct
12 Correct 7 ms 760 KB Output is correct
13 Correct 14 ms 1016 KB Output is correct
14 Correct 14 ms 940 KB Output is correct
15 Correct 12 ms 888 KB Output is correct
16 Correct 13 ms 888 KB Output is correct
17 Correct 16 ms 888 KB Output is correct
18 Correct 5 ms 760 KB Output is correct
19 Correct 594 ms 11348 KB Output is correct
20 Correct 571 ms 13720 KB Output is correct
21 Correct 582 ms 13672 KB Output is correct
22 Correct 555 ms 12432 KB Output is correct
23 Correct 555 ms 12928 KB Output is correct
24 Correct 193 ms 11624 KB Output is correct
25 Correct 553 ms 13772 KB Output is correct
26 Correct 558 ms 13416 KB Output is correct
27 Correct 551 ms 13408 KB Output is correct
28 Correct 483 ms 12904 KB Output is correct
29 Correct 539 ms 12076 KB Output is correct
30 Correct 98 ms 11976 KB Output is correct
31 Correct 768 ms 14072 KB Output is correct
32 Correct 761 ms 14212 KB Output is correct
33 Correct 592 ms 13700 KB Output is correct
34 Correct 672 ms 12820 KB Output is correct
35 Correct 638 ms 13304 KB Output is correct
36 Correct 190 ms 11608 KB Output is correct
37 Correct 770 ms 14268 KB Output is correct
38 Correct 770 ms 14188 KB Output is correct
39 Correct 758 ms 14184 KB Output is correct
40 Correct 497 ms 12904 KB Output is correct
41 Correct 510 ms 12140 KB Output is correct
42 Correct 111 ms 11804 KB Output is correct
43 Correct 793 ms 16988 KB Output is correct
44 Correct 816 ms 16900 KB Output is correct
45 Correct 828 ms 16936 KB Output is correct
46 Correct 709 ms 13940 KB Output is correct
47 Correct 731 ms 15436 KB Output is correct
48 Correct 220 ms 11344 KB Output is correct
49 Correct 825 ms 16868 KB Output is correct
50 Correct 796 ms 16844 KB Output is correct
51 Correct 802 ms 16828 KB Output is correct
52 Correct 605 ms 15336 KB Output is correct
53 Correct 562 ms 13004 KB Output is correct