답안 #733375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733375 2023-04-30T15:22:05 Z benjaminkleyn Examination (JOI19_examination) C++17
100 / 100
653 ms 50376 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct Query
{
    int a, b, A, B, C, idx;
    Query() : a(0), b(0), A(0), B(0), C(0), idx(0) {}
    Query(int _a, int _b, int _c, int _idx) : a(0), b(0), A(_a), B(_b), C(_c), idx(_idx) {}
};

struct Student
{
    int s, t, S, T, idx;
    Student() : s(0), t(0), S(0), T(0), idx(0) {}
};

int n, q;

struct SegTree
{
    int t[1000000] = {0};
    SegTree() {}
    void update(int idx, int v = 1, int tl = 0, int tr = 200000)
    {
        if (tl == tr)
        {
            t[v]++;
            return;
        }
        int tm = (tl + tr) / 2;
        if (idx <= tm)
            update(idx, 2 * v, tl, tm);
        else
            update(idx, 2 * v + 1, tm + 1, tr);
        t[v] = t[2 * v] + t[2 * v + 1];
    }
    int query(int l, int r, int v = 1, int tl = 0, int tr = 200000)
    {
        if (l > r || r < tl || tr < l)
            return 0;
        if (l <= tl && tr <= r)
            return t[v];
        int tm = (tl + tr) / 2;
        return query(l, r, 2 * v, tl, tm) + query(l, r, 2 * v + 1, tm + 1, tr);
    }
};

int main()
{
    cin.tie(0)->sync_with_stdio(0);

    cin >> n >> q;

    set<int> a_vals, b_vals;

    vector<Student> students(n);
    for (Student &x : students)
    {
        cin >> x.S >> x.T;
        a_vals.insert(x.S);
        b_vals.insert(x.T);
    }

    vector<Query> type1, type2;
    for (int i = 0, a, b, c; i < q; i++)
    {
        cin >> a >> b >> c;
        if (a + b >= c)
            type1.push_back(Query(a, b, c, i));
        else
            type2.push_back(Query(a, b, c, i));

        a_vals.insert(a);
        b_vals.insert(b);
    }

    unordered_map<int, int> smolA, smolB;
    int mxA = 0;
    for (int a : a_vals)
        smolA[a] = mxA++;
    int mxB = 0;
    for (int b : b_vals)
        smolB[b] = mxB++;

    for (Student &x : students)
    {
        x.s = smolA[x.S];
        x.t = smolB[x.T];
    }
    for (Query &Q : type1)
    {
        Q.a = smolA[Q.A];
        Q.b = smolB[Q.B];
    }
    for (Query &Q : type2)
    {
        Q.a = smolA[Q.A];
        Q.b = smolB[Q.B];
    }

    vector<int> res(q);

    SegTree seg1;
    sort(type1.begin(), type1.end(), [] (const Query &X, const Query &Y) {return X.A > Y.A;});
    sort(students.begin(), students.end(), [] (const Student &X, const Student &Y) {return X.S > Y.S;});
    int i = 0;
    for (const Query &Q : type1)
    {
        while (i < n && students[i].S >= Q.A)
            seg1.update(students[i++].t);
        res[Q.idx] = seg1.query(Q.b, 200000);
    }

    seg1 = SegTree();
    SegTree seg2;
    sort(type2.begin(), type2.end(), [] (const Query &X, const Query &Y) {return X.C > Y.C;});
    sort(students.begin(), students.end(), [] (const Student &X, const Student &Y) {return X.S + X.T > Y.S + Y.T;});
    i = 0;
    for (const Query &Q : type2)
    {
        while (i < n && students[i].S + students[i].T >= Q.C)
        {
            seg1.update(students[i].s);
            seg2.update(students[i].t);
            i++;
        }
        res[Q.idx] = seg1.query(Q.a, 200000) - seg2.query(0, Q.b - 1);
    }

    for (int j = 0; j < q; j++)
        cout << res[j] << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8020 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8020 KB Output is correct
4 Correct 5 ms 8020 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 4 ms 8020 KB Output is correct
7 Correct 12 ms 9300 KB Output is correct
8 Correct 12 ms 9352 KB Output is correct
9 Correct 12 ms 9328 KB Output is correct
10 Correct 11 ms 8864 KB Output is correct
11 Correct 13 ms 8788 KB Output is correct
12 Correct 10 ms 8276 KB Output is correct
13 Correct 15 ms 9416 KB Output is correct
14 Correct 12 ms 9408 KB Output is correct
15 Correct 14 ms 9416 KB Output is correct
16 Correct 8 ms 8832 KB Output is correct
17 Correct 9 ms 8848 KB Output is correct
18 Correct 6 ms 8256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 301 ms 29832 KB Output is correct
2 Correct 267 ms 29872 KB Output is correct
3 Correct 299 ms 29796 KB Output is correct
4 Correct 149 ms 21724 KB Output is correct
5 Correct 159 ms 21716 KB Output is correct
6 Correct 96 ms 13364 KB Output is correct
7 Correct 237 ms 27604 KB Output is correct
8 Correct 246 ms 27476 KB Output is correct
9 Correct 217 ms 25152 KB Output is correct
10 Correct 153 ms 21604 KB Output is correct
11 Correct 139 ms 21492 KB Output is correct
12 Correct 85 ms 13216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 301 ms 29832 KB Output is correct
2 Correct 267 ms 29872 KB Output is correct
3 Correct 299 ms 29796 KB Output is correct
4 Correct 149 ms 21724 KB Output is correct
5 Correct 159 ms 21716 KB Output is correct
6 Correct 96 ms 13364 KB Output is correct
7 Correct 237 ms 27604 KB Output is correct
8 Correct 246 ms 27476 KB Output is correct
9 Correct 217 ms 25152 KB Output is correct
10 Correct 153 ms 21604 KB Output is correct
11 Correct 139 ms 21492 KB Output is correct
12 Correct 85 ms 13216 KB Output is correct
13 Correct 291 ms 29828 KB Output is correct
14 Correct 310 ms 29808 KB Output is correct
15 Correct 252 ms 29832 KB Output is correct
16 Correct 203 ms 21752 KB Output is correct
17 Correct 174 ms 21648 KB Output is correct
18 Correct 88 ms 13816 KB Output is correct
19 Correct 337 ms 29848 KB Output is correct
20 Correct 317 ms 29852 KB Output is correct
21 Correct 287 ms 27172 KB Output is correct
22 Correct 172 ms 21584 KB Output is correct
23 Correct 160 ms 21480 KB Output is correct
24 Correct 64 ms 13264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8020 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 4 ms 8020 KB Output is correct
4 Correct 5 ms 8020 KB Output is correct
5 Correct 5 ms 8148 KB Output is correct
6 Correct 4 ms 8020 KB Output is correct
7 Correct 12 ms 9300 KB Output is correct
8 Correct 12 ms 9352 KB Output is correct
9 Correct 12 ms 9328 KB Output is correct
10 Correct 11 ms 8864 KB Output is correct
11 Correct 13 ms 8788 KB Output is correct
12 Correct 10 ms 8276 KB Output is correct
13 Correct 15 ms 9416 KB Output is correct
14 Correct 12 ms 9408 KB Output is correct
15 Correct 14 ms 9416 KB Output is correct
16 Correct 8 ms 8832 KB Output is correct
17 Correct 9 ms 8848 KB Output is correct
18 Correct 6 ms 8256 KB Output is correct
19 Correct 301 ms 29832 KB Output is correct
20 Correct 267 ms 29872 KB Output is correct
21 Correct 299 ms 29796 KB Output is correct
22 Correct 149 ms 21724 KB Output is correct
23 Correct 159 ms 21716 KB Output is correct
24 Correct 96 ms 13364 KB Output is correct
25 Correct 237 ms 27604 KB Output is correct
26 Correct 246 ms 27476 KB Output is correct
27 Correct 217 ms 25152 KB Output is correct
28 Correct 153 ms 21604 KB Output is correct
29 Correct 139 ms 21492 KB Output is correct
30 Correct 85 ms 13216 KB Output is correct
31 Correct 291 ms 29828 KB Output is correct
32 Correct 310 ms 29808 KB Output is correct
33 Correct 252 ms 29832 KB Output is correct
34 Correct 203 ms 21752 KB Output is correct
35 Correct 174 ms 21648 KB Output is correct
36 Correct 88 ms 13816 KB Output is correct
37 Correct 337 ms 29848 KB Output is correct
38 Correct 317 ms 29852 KB Output is correct
39 Correct 287 ms 27172 KB Output is correct
40 Correct 172 ms 21584 KB Output is correct
41 Correct 160 ms 21480 KB Output is correct
42 Correct 64 ms 13264 KB Output is correct
43 Correct 540 ms 50284 KB Output is correct
44 Correct 570 ms 50352 KB Output is correct
45 Correct 580 ms 50284 KB Output is correct
46 Correct 308 ms 31764 KB Output is correct
47 Correct 313 ms 31760 KB Output is correct
48 Correct 105 ms 14340 KB Output is correct
49 Correct 653 ms 50280 KB Output is correct
50 Correct 607 ms 50248 KB Output is correct
51 Correct 604 ms 50376 KB Output is correct
52 Correct 326 ms 31644 KB Output is correct
53 Correct 253 ms 31872 KB Output is correct