답안 #709435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709435 2023-03-13T14:48:11 Z Johann Examination (JOI19_examination) C++14
100 / 100
2062 ms 14384 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;
    vpii stuff;
    vvpii buckets;
    vi minele;
    int sq;
    void init(int N)
    {
        sq = 2 * ceil(sqrt(N));
    }
    void insert(pii &item)
    {
        newStuff.push_back(item);
        if (sz(newStuff) == sq)
        {
            for (pii tmp : newStuff)
                stuff.push_back(tmp);
            newStuff.clear();
            sort(all(stuff));
            buckets.push_back(vpii(sq));
            minele.push_back(0);

            for (int i = 0; i < sz(buckets); ++i)
            {
                minele[i] = stuff[i * sq].first;
                sort(stuff.begin() + i * sq, stuff.begin() + (i + 1) * sq, [&](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(stuff) / sq - 1;
        while (idx >= 0 && minele[idx] >= q.a)
        {
            ans += (stuff.begin() + (idx + 1) * sq) - lower_bound(stuff.begin() + idx * sq, stuff.begin() + (idx + 1) * sq, make_pair(0LL, q.b), [&](const pii a, const pii b)
                                                                  { return a.second < b.second; });
            --idx;
        }
        if (idx != -1)
            for (int i = idx * sq; i < (idx + 1) * sq; ++i)
                if (stuff[i].first >= q.a && stuff[i].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 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 8 ms 592 KB Output is correct
8 Correct 7 ms 596 KB Output is correct
9 Correct 7 ms 596 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 6 ms 596 KB Output is correct
12 Correct 5 ms 596 KB Output is correct
13 Correct 8 ms 596 KB Output is correct
14 Correct 8 ms 552 KB Output is correct
15 Correct 7 ms 596 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1645 ms 9552 KB Output is correct
2 Correct 1679 ms 11308 KB Output is correct
3 Correct 1657 ms 11184 KB Output is correct
4 Correct 1470 ms 11100 KB Output is correct
5 Correct 941 ms 11008 KB Output is correct
6 Correct 734 ms 10576 KB Output is correct
7 Correct 2053 ms 11008 KB Output is correct
8 Correct 1538 ms 11952 KB Output is correct
9 Correct 1837 ms 11912 KB Output is correct
10 Correct 962 ms 11084 KB Output is correct
11 Correct 874 ms 11028 KB Output is correct
12 Correct 350 ms 10184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1645 ms 9552 KB Output is correct
2 Correct 1679 ms 11308 KB Output is correct
3 Correct 1657 ms 11184 KB Output is correct
4 Correct 1470 ms 11100 KB Output is correct
5 Correct 941 ms 11008 KB Output is correct
6 Correct 734 ms 10576 KB Output is correct
7 Correct 2053 ms 11008 KB Output is correct
8 Correct 1538 ms 11952 KB Output is correct
9 Correct 1837 ms 11912 KB Output is correct
10 Correct 962 ms 11084 KB Output is correct
11 Correct 874 ms 11028 KB Output is correct
12 Correct 350 ms 10184 KB Output is correct
13 Correct 1525 ms 12444 KB Output is correct
14 Correct 1640 ms 12392 KB Output is correct
15 Correct 1738 ms 12120 KB Output is correct
16 Correct 1375 ms 11612 KB Output is correct
17 Correct 991 ms 11640 KB Output is correct
18 Correct 866 ms 10544 KB Output is correct
19 Correct 1746 ms 12408 KB Output is correct
20 Correct 1779 ms 12384 KB Output is correct
21 Correct 1609 ms 12384 KB Output is correct
22 Correct 963 ms 11116 KB Output is correct
23 Correct 909 ms 11056 KB Output is correct
24 Correct 380 ms 10144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 8 ms 592 KB Output is correct
8 Correct 7 ms 596 KB Output is correct
9 Correct 7 ms 596 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 6 ms 596 KB Output is correct
12 Correct 5 ms 596 KB Output is correct
13 Correct 8 ms 596 KB Output is correct
14 Correct 8 ms 552 KB Output is correct
15 Correct 7 ms 596 KB Output is correct
16 Correct 4 ms 604 KB Output is correct
17 Correct 4 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 1645 ms 9552 KB Output is correct
20 Correct 1679 ms 11308 KB Output is correct
21 Correct 1657 ms 11184 KB Output is correct
22 Correct 1470 ms 11100 KB Output is correct
23 Correct 941 ms 11008 KB Output is correct
24 Correct 734 ms 10576 KB Output is correct
25 Correct 2053 ms 11008 KB Output is correct
26 Correct 1538 ms 11952 KB Output is correct
27 Correct 1837 ms 11912 KB Output is correct
28 Correct 962 ms 11084 KB Output is correct
29 Correct 874 ms 11028 KB Output is correct
30 Correct 350 ms 10184 KB Output is correct
31 Correct 1525 ms 12444 KB Output is correct
32 Correct 1640 ms 12392 KB Output is correct
33 Correct 1738 ms 12120 KB Output is correct
34 Correct 1375 ms 11612 KB Output is correct
35 Correct 991 ms 11640 KB Output is correct
36 Correct 866 ms 10544 KB Output is correct
37 Correct 1746 ms 12408 KB Output is correct
38 Correct 1779 ms 12384 KB Output is correct
39 Correct 1609 ms 12384 KB Output is correct
40 Correct 963 ms 11116 KB Output is correct
41 Correct 909 ms 11056 KB Output is correct
42 Correct 380 ms 10144 KB Output is correct
43 Correct 1525 ms 14384 KB Output is correct
44 Correct 1520 ms 14308 KB Output is correct
45 Correct 1776 ms 14340 KB Output is correct
46 Correct 1334 ms 12716 KB Output is correct
47 Correct 883 ms 12932 KB Output is correct
48 Correct 657 ms 10340 KB Output is correct
49 Correct 2062 ms 14204 KB Output is correct
50 Correct 1375 ms 14244 KB Output is correct
51 Correct 1699 ms 14120 KB Output is correct
52 Correct 989 ms 12564 KB Output is correct
53 Correct 1037 ms 11844 KB Output is correct