답안 #709343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709343 2023-03-13T12:29:52 Z Johann Examination (JOI19_examination) C++14
2 / 100
3000 ms 13076 KB
// TODO: Still to solve...
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

struct Req
{
    ll a, b, c;
    int idx;
};

struct SqrtDecom
{
    vpii newStuff;
    vvpii buckets;
    vi minele;
    int sq;
    void init(int N)
    {
        sq = ceil(sqrt(N));
    }
    void insert(pii &item)
    {
        newStuff.push_back(item);
        if (sz(newStuff) == sq)
        {
            for (int i = 0; i < sz(buckets); ++i)
            {
                for (pii tmp : buckets[i])
                    newStuff.push_back(tmp);
                buckets[i].clear();
            }
            buckets.push_back(vpii());
            minele.push_back(0);
            sort(all(newStuff));

            for (int i = 0; i < sz(newStuff); ++i)
                buckets[i / sq].push_back(newStuff[i]);
            newStuff.clear();

            for (int i = 0; i < sz(buckets); ++i)
            {
                minele[i] = buckets[i].front().first;
                sort(all(buckets[i]), [&](pii &a, pii &b)
                     { return a.second < b.second; });
            }
        }
    }

    int answer(Req &q)
    {
        int ans = 0;
        for (pii r : newStuff)
            if (r.first >= q.a && r.second >= q.b)
                ++ans;
        int idx = sz(buckets) - 1;
        while (idx >= 0 && minele[idx] >= q.a)
        {
            ans += buckets[idx].end() - lower_bound(all(buckets[idx]), make_pair(0LL, q.b), [&](const pii a, const pii b)
                                                    { return a.second < b.second; });
            idx--;
        }
        if (idx != -1)
            for (pii r : buckets[idx])
                if (r.first >= q.a && r.second >= q.b)
                    ++ans;
        return ans;
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, Q;
    cin >> N >> Q;

    vpii ST(N); // A <= S[i] , B <= T[i], C <= S[i] + T[i]
    for (int i = 0; i < N; ++i)
        cin >> ST[i].first >> ST[i].second;

    vector<Req> Queries(Q);
    for (int i = 0, a, b, c; i < Q; ++i)
    {
        cin >> a >> b >> c;
        Queries[i] = {a, b, c, i};
    }
    vi ans(Q);

    sort(all(Queries), [&](Req &a, Req &b)
         { return a.c > b.c; });
    sort(all(ST), [&](pii &a, pii &b)
         { return a.first + a.second > b.first + b.second; });

    SqrtDecom sqd;
    sqd.init(N);

    int idx = 0;
    for (int i = 0; i < sz(Queries); ++i)
    {
        while (idx < sz(ST) && ST[idx].first + ST[idx].second >= Queries[i].c)
        {
            sqd.insert(ST[idx]);
            ++idx;
        }
        ans[Queries[i].idx] = sqd.answer(Queries[i]);
    }

    for (int x : ans)
        cout << x << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 10 ms 716 KB Output is correct
8 Correct 12 ms 748 KB Output is correct
9 Correct 11 ms 740 KB Output is correct
10 Correct 9 ms 712 KB Output is correct
11 Correct 9 ms 724 KB Output is correct
12 Correct 8 ms 592 KB Output is correct
13 Correct 12 ms 728 KB Output is correct
14 Correct 11 ms 736 KB Output is correct
15 Correct 11 ms 724 KB Output is correct
16 Correct 6 ms 588 KB Output is correct
17 Correct 6 ms 716 KB Output is correct
18 Correct 5 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2503 ms 12948 KB Output is correct
2 Correct 2501 ms 13076 KB Output is correct
3 Correct 2423 ms 12588 KB Output is correct
4 Correct 1976 ms 12304 KB Output is correct
5 Correct 1643 ms 11968 KB Output is correct
6 Correct 936 ms 11580 KB Output is correct
7 Execution timed out 3005 ms 12904 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2503 ms 12948 KB Output is correct
2 Correct 2501 ms 13076 KB Output is correct
3 Correct 2423 ms 12588 KB Output is correct
4 Correct 1976 ms 12304 KB Output is correct
5 Correct 1643 ms 11968 KB Output is correct
6 Correct 936 ms 11580 KB Output is correct
7 Execution timed out 3005 ms 12904 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 10 ms 716 KB Output is correct
8 Correct 12 ms 748 KB Output is correct
9 Correct 11 ms 740 KB Output is correct
10 Correct 9 ms 712 KB Output is correct
11 Correct 9 ms 724 KB Output is correct
12 Correct 8 ms 592 KB Output is correct
13 Correct 12 ms 728 KB Output is correct
14 Correct 11 ms 736 KB Output is correct
15 Correct 11 ms 724 KB Output is correct
16 Correct 6 ms 588 KB Output is correct
17 Correct 6 ms 716 KB Output is correct
18 Correct 5 ms 588 KB Output is correct
19 Correct 2503 ms 12948 KB Output is correct
20 Correct 2501 ms 13076 KB Output is correct
21 Correct 2423 ms 12588 KB Output is correct
22 Correct 1976 ms 12304 KB Output is correct
23 Correct 1643 ms 11968 KB Output is correct
24 Correct 936 ms 11580 KB Output is correct
25 Execution timed out 3005 ms 12904 KB Time limit exceeded
26 Halted 0 ms 0 KB -