Submission #1074869

# Submission time Handle Problem Language Result Execution time Memory
1074869 2024-08-25T15:45:45 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
428 ms 31188 KB
#include <bits/stdc++.h>
#define all(s) s.begin(), s.end()
#define lb(s, a) lower_bound(all(s), (a)) - s.begin()

using namespace std;

typedef long long ll;

const int ar = 2e5 + 2;
const ll mod = 1e9 + 7;
const int oo = 2e9;

struct BIT {
    vector<vector<int>> c, t;
    bool b;

    BIT(int n) {
        b = 0;
        c = vector<vector<int>>(n);
        t = vector<vector<int>>(n);
    }

    void init() {
        b = 1;
        for (int i = 0; i < c.size(); i++) {
            sort(c[i].begin(), c[i].end());
            c[i].resize(unique(c[i].begin(), c[i].end()) - c[i].begin());
            t[i] = vector<int>(c[i].size(), 0);
        }
    }

    void update(int i, int j) {
        i++, j++;
        while (i <= t.size()) {
            if (!b)
                c[i - 1].push_back(j);
            else {
                int k = upper_bound(c[i - 1].begin(), c[i - 1].end(), j) -
                        c[i - 1].begin();
                while (k <= c[i - 1].size()) {
                    t[i - 1][k - 1]++;
                    k += k & -k;
                }
            }
            i += i & -i;
        }
    }

    int pre(int i, int j) {
        int x = 0;
        i++, j++;

        while (i) {
            int k = upper_bound(c[i - 1].begin(), c[i - 1].end(), j) - c[i - 1].begin();
            while (k) {
                x += t[i - 1][k - 1];
                k -= k & -k;
            }
            i -= i & -i;
        }
        return x;
    }

    int get(int i1, int i2, int j1, int j2) {
        int x = pre(i2, j2);
        if (i1)
            x -= pre(i1 - 1, j2);
        if (j1)
            x -= pre(i2, j1 - 1);
        if (i1 && j1)
            x += pre(i1 - 1, j1 - 1);
        return x;
    }
};

struct Event {
    int t, x, y;
    int i;
    bool a;

    bool operator<(Event const &e) const {
        if (t == e.t)
            return a && !e.a;
        return t > e.t;
    }
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
#define task "code"
    if(fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int n, q;
    cin >> n >> q;

    vector<Event> tap;
    vector<int> td;

    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        td.push_back(x);
        tap.push_back({x + y, x, y, n, 1});
    }

    for (int i = 0; i < q; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        td.push_back(x);
        tap.push_back({z, x, y, i, 0});
    }

    sort(all(tap));
    sort(all(td));
    td.resize(unique(all(td)) - td.begin());
    BIT bit(td.size());

    vector<int> ans(q, 0);

    for (auto const &[t, x, y, i, a] : tap)
        if (a)
            bit.update(lb(td, x), y);
    bit.init();
    for (auto const &[t, x, y, i, a] : tap) {
        if (a)
            bit.update(lb(td, x), y);
        else
            ans[i] = bit.get(lb(td, x), td.size() - 1, y, oo);
    }

    for (auto const &a : ans)
        cout << a << '\n';
}

Compilation message

examination.cpp: In member function 'void BIT::init()':
examination.cpp:25:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (int i = 0; i < c.size(); i++) {
      |                         ~~^~~~~~~~~~
examination.cpp: In member function 'void BIT::update(int, int)':
examination.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         while (i <= t.size()) {
      |                ~~^~~~~~~~~~~
examination.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |                 while (k <= c[i - 1].size()) {
      |                        ~~^~~~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 1116 KB Output is correct
8 Correct 7 ms 1116 KB Output is correct
9 Correct 7 ms 1116 KB Output is correct
10 Correct 4 ms 1112 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 7 ms 1288 KB Output is correct
14 Correct 7 ms 1116 KB Output is correct
15 Correct 7 ms 1112 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 20944 KB Output is correct
2 Correct 355 ms 21460 KB Output is correct
3 Correct 376 ms 21460 KB Output is correct
4 Correct 170 ms 18648 KB Output is correct
5 Correct 129 ms 8172 KB Output is correct
6 Correct 56 ms 7912 KB Output is correct
7 Correct 296 ms 19236 KB Output is correct
8 Correct 323 ms 22276 KB Output is correct
9 Correct 275 ms 19516 KB Output is correct
10 Correct 77 ms 7916 KB Output is correct
11 Correct 112 ms 18392 KB Output is correct
12 Correct 41 ms 8676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 20944 KB Output is correct
2 Correct 355 ms 21460 KB Output is correct
3 Correct 376 ms 21460 KB Output is correct
4 Correct 170 ms 18648 KB Output is correct
5 Correct 129 ms 8172 KB Output is correct
6 Correct 56 ms 7912 KB Output is correct
7 Correct 296 ms 19236 KB Output is correct
8 Correct 323 ms 22276 KB Output is correct
9 Correct 275 ms 19516 KB Output is correct
10 Correct 77 ms 7916 KB Output is correct
11 Correct 112 ms 18392 KB Output is correct
12 Correct 41 ms 8676 KB Output is correct
13 Correct 380 ms 21168 KB Output is correct
14 Correct 365 ms 21208 KB Output is correct
15 Correct 351 ms 21624 KB Output is correct
16 Correct 169 ms 19416 KB Output is correct
17 Correct 134 ms 8092 KB Output is correct
18 Correct 57 ms 8936 KB Output is correct
19 Correct 369 ms 22508 KB Output is correct
20 Correct 367 ms 21020 KB Output is correct
21 Correct 360 ms 20332 KB Output is correct
22 Correct 77 ms 7656 KB Output is correct
23 Correct 108 ms 19028 KB Output is correct
24 Correct 42 ms 8412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 6 ms 1116 KB Output is correct
8 Correct 7 ms 1116 KB Output is correct
9 Correct 7 ms 1116 KB Output is correct
10 Correct 4 ms 1112 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 7 ms 1288 KB Output is correct
14 Correct 7 ms 1116 KB Output is correct
15 Correct 7 ms 1112 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 362 ms 20944 KB Output is correct
20 Correct 355 ms 21460 KB Output is correct
21 Correct 376 ms 21460 KB Output is correct
22 Correct 170 ms 18648 KB Output is correct
23 Correct 129 ms 8172 KB Output is correct
24 Correct 56 ms 7912 KB Output is correct
25 Correct 296 ms 19236 KB Output is correct
26 Correct 323 ms 22276 KB Output is correct
27 Correct 275 ms 19516 KB Output is correct
28 Correct 77 ms 7916 KB Output is correct
29 Correct 112 ms 18392 KB Output is correct
30 Correct 41 ms 8676 KB Output is correct
31 Correct 380 ms 21168 KB Output is correct
32 Correct 365 ms 21208 KB Output is correct
33 Correct 351 ms 21624 KB Output is correct
34 Correct 169 ms 19416 KB Output is correct
35 Correct 134 ms 8092 KB Output is correct
36 Correct 57 ms 8936 KB Output is correct
37 Correct 369 ms 22508 KB Output is correct
38 Correct 367 ms 21020 KB Output is correct
39 Correct 360 ms 20332 KB Output is correct
40 Correct 77 ms 7656 KB Output is correct
41 Correct 108 ms 19028 KB Output is correct
42 Correct 42 ms 8412 KB Output is correct
43 Correct 428 ms 31188 KB Output is correct
44 Correct 393 ms 30168 KB Output is correct
45 Correct 404 ms 30168 KB Output is correct
46 Correct 182 ms 28632 KB Output is correct
47 Correct 141 ms 9292 KB Output is correct
48 Correct 58 ms 8168 KB Output is correct
49 Correct 379 ms 28372 KB Output is correct
50 Correct 408 ms 30528 KB Output is correct
51 Correct 344 ms 28636 KB Output is correct
52 Correct 94 ms 8788 KB Output is correct
53 Correct 128 ms 27348 KB Output is correct