제출 #1338783

#제출 시각아이디문제언어결과실행 시간메모리
1338783niehExamination (JOI19_examination)C++20
2 / 100
3091 ms4372 KiB
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FOD(i, a, b) for(int i = (a); i >= (b); i--)
#define file(name) if(fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define fi first
#define se second
#define el cout << '\n'
#define maxn int(1e5 + 5)

using namespace std;

typedef pair<int, int> pii;

struct Query {
    int x, y, z;
} Q[maxn];

int n, q;

pii a[maxn];

namespace subtask1 {
    bool check() {
        return n <= 3000 && q <= 3000;
    }

    void solve() {
        FOR(i, 1, q) {
            int x = Q[i].x, y = Q[i].y, z = Q[i].z;
            int cnt = 0;
            FOR(j, 1, n)  
                if(a[j].fi >= x && a[j].se >= y && a[j].fi + a[j].se >= z) cnt++;
            cout << cnt, el;
        }
    }
}

namespace subtask2 {
    bool check() {
        FOR(i, 1, q) if(Q[i].z) return 0;
        return 1;
    }

    const int N = (int)1e5;

    int b[maxn], res[maxn];

    int t[maxn];

    vector<pii> queries;

    bool cmp(pii &A, pii &B) {
        return A.fi > B.fi;
    }

    void update(int x, int v) {
        for(; x; x -= x & -x) t[x] += v;
    }

    int get(int x) {
        int res = 0;
        for(; x <= N; x += x & -x) res += t[x];
        return res;
    }

    void solve() {
        sort(a + 1, a + n + 1);
        FOR(i, 1, n) b[i] = a[i].fi;
        FOR(i, 1, q) {
            int x = Q[i].x, y = Q[i].y, z = Q[i].z;
            int pos = lower_bound(b + 1, b + n + 1, x) - b;
            if(pos > 0)
                queries.push_back({ pos, i });
        }
        sort(queries.begin(), queries.end(), cmp);
        int j = n + 1;
        for(pii x : queries) {
            while(j - 1 >= x.fi) update(a[--j].se, 1);
            res[x.se] = get(Q[x.se].y);
        }
        FOR(i, 1, q) cout << res[i], el;
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    FOR(i, 1, n) cin >> a[i].fi >> a[i].se;
    FOR(i, 1, q) cin >> Q[i].x >> Q[i].y >> Q[i].z;
    if(subtask1::check()) return subtask1::solve(), 0;
    if(subtask2::check()) return subtask2::solve(), 0;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...