답안 #187521

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
187521 2020-01-13T02:28:23 Z ToMmyDong Examination (JOI19_examination) C++11
41 / 100
864 ms 1048580 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long 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 tmd
#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) {
    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;

                if (dl > 0) {
                    debug(i, qry[i].id, qry[i].y);
                }
            }
        }

        for (auto id : opr) {
            add(id, -1);
        }
        assert(sum(MAXN-2) == 0);

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


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

    cin >> n >> q;

    REP (i, n) {
        cin >> qry[i].x >> qry[i].y;
        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++) {
        cin >> qry[i].x >> qry[i].y >> qry[i].z;
        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();
    }

    sort(qry,qry+n+q,byZ);
    pary(qry,qry+n+q);
    solve(0, n+q);
    REP (i, q) {
        cout << ans[i] << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Runtime error 864 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 558 ms 8492 KB Output is correct
2 Correct 567 ms 8492 KB Output is correct
3 Correct 546 ms 8488 KB Output is correct
4 Correct 514 ms 7520 KB Output is correct
5 Correct 515 ms 7812 KB Output is correct
6 Correct 176 ms 6796 KB Output is correct
7 Correct 518 ms 8540 KB Output is correct
8 Correct 531 ms 8416 KB Output is correct
9 Correct 506 ms 8432 KB Output is correct
10 Correct 449 ms 7792 KB Output is correct
11 Correct 569 ms 7344 KB Output is correct
12 Correct 92 ms 6512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 558 ms 8492 KB Output is correct
2 Correct 567 ms 8492 KB Output is correct
3 Correct 546 ms 8488 KB Output is correct
4 Correct 514 ms 7520 KB Output is correct
5 Correct 515 ms 7812 KB Output is correct
6 Correct 176 ms 6796 KB Output is correct
7 Correct 518 ms 8540 KB Output is correct
8 Correct 531 ms 8416 KB Output is correct
9 Correct 506 ms 8432 KB Output is correct
10 Correct 449 ms 7792 KB Output is correct
11 Correct 569 ms 7344 KB Output is correct
12 Correct 92 ms 6512 KB Output is correct
13 Correct 737 ms 8948 KB Output is correct
14 Correct 763 ms 8952 KB Output is correct
15 Correct 535 ms 8600 KB Output is correct
16 Correct 645 ms 7904 KB Output is correct
17 Correct 603 ms 8172 KB Output is correct
18 Correct 175 ms 6888 KB Output is correct
19 Correct 717 ms 8980 KB Output is correct
20 Correct 726 ms 9020 KB Output is correct
21 Correct 717 ms 9016 KB Output is correct
22 Correct 433 ms 7792 KB Output is correct
23 Correct 469 ms 7484 KB Output is correct
24 Correct 92 ms 6636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Runtime error 864 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -