답안 #709244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709244 2023-03-13T09:23:23 Z finn__ Examination (JOI19_examination) C++17
100 / 100
708 ms 47212 KB
#include <bits/stdc++.h>
using namespace std;

struct OfflineBit2d
{
    vector<vector<int64_t>> c, t;
    bool b;

    OfflineBit2d(size_t n)
    {
        b = 0;
        c = vector<vector<int64_t>>(n);
        t = vector<vector<int64_t>>(n);
    }

    void initialize()
    {
        b = 1;
        for (size_t 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<int64_t>(c[i].size(), 0);
        }
    }

    void increment(int64_t i, int64_t j)
    {
        i++, j++;
        while (i <= t.size())
        {
            if (!b)
                c[i - 1].push_back(j);
            else
            {
                int64_t 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;
        }
    }

    int64_t prefix_sum(size_t i, size_t j)
    {
        int64_t x = 0;
        i++, j++;

        while (i)
        {
            int64_t 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;
    }

    int64_t range_sum(size_t i1, size_t i2, size_t j1, size_t j2)
    {
        int64_t x = prefix_sum(i2, j2);
        if (i1)
            x -= prefix_sum(i1 - 1, j2);
        if (j1)
            x -= prefix_sum(i2, j1 - 1);
        if (i1 && j1)
            x += prefix_sum(i1 - 1, j1 - 1);
        return x;
    }
};

struct Event
{
    int64_t t, x, y;
    size_t i;
    bool student;

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

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

    size_t n, q;
    cin >> n >> q;

    vector<Event> events;
    vector<int64_t> xcoords;

    for (size_t i = 0; i < n; i++)
    {
        int64_t x, y;
        cin >> x >> y;
        xcoords.push_back(x);
        events.push_back({x + y, x, y, SIZE_MAX, 1});
    }

    for (size_t i = 0; i < q; i++)
    {
        int64_t x, y, z;
        cin >> x >> y >> z;
        xcoords.push_back(x);
        events.push_back({z, x, y, i, 0});
    }

    sort(events.begin(), events.end());
    sort(xcoords.begin(), xcoords.end());
    xcoords.resize(unique(xcoords.begin(), xcoords.end()) - xcoords.begin());
    OfflineBit2d tree(xcoords.size());

    vector<int64_t> ans(q, 0);

    for (auto const &[t, x, y, i, student] : events)
        if (student)
            tree.increment(lower_bound(xcoords.begin(), xcoords.end(), x) - xcoords.begin(), y);
    tree.initialize();
    for (auto const &[t, x, y, i, student] : events)
    {
        if (student)
            tree.increment(lower_bound(xcoords.begin(), xcoords.end(), x) - xcoords.begin(), y);
        else
            ans[i] = tree.range_sum(
                lower_bound(xcoords.begin(), xcoords.end(), x) - xcoords.begin(),
                xcoords.size() - 1, y, 2000000000);
    }

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

Compilation message

examination.cpp: In member function 'void OfflineBit2d::increment(int64_t, int64_t)':
examination.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<std::vector<long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         while (i <= t.size())
      |                ~~^~~~~~~~~~~
examination.cpp:38:26: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |                 while (k <= c[i - 1].size())
      |                        ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 9 ms 1456 KB Output is correct
8 Correct 9 ms 1468 KB Output is correct
9 Correct 9 ms 1432 KB Output is correct
10 Correct 6 ms 1328 KB Output is correct
11 Correct 5 ms 816 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 9 ms 1584 KB Output is correct
14 Correct 9 ms 1584 KB Output is correct
15 Correct 9 ms 1576 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 5 ms 1456 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 514 ms 33316 KB Output is correct
2 Correct 512 ms 33348 KB Output is correct
3 Correct 494 ms 33328 KB Output is correct
4 Correct 248 ms 28528 KB Output is correct
5 Correct 169 ms 14916 KB Output is correct
6 Correct 91 ms 14200 KB Output is correct
7 Correct 423 ms 33464 KB Output is correct
8 Correct 457 ms 35816 KB Output is correct
9 Correct 363 ms 33412 KB Output is correct
10 Correct 105 ms 15932 KB Output is correct
11 Correct 155 ms 29400 KB Output is correct
12 Correct 65 ms 15492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 514 ms 33316 KB Output is correct
2 Correct 512 ms 33348 KB Output is correct
3 Correct 494 ms 33328 KB Output is correct
4 Correct 248 ms 28528 KB Output is correct
5 Correct 169 ms 14916 KB Output is correct
6 Correct 91 ms 14200 KB Output is correct
7 Correct 423 ms 33464 KB Output is correct
8 Correct 457 ms 35816 KB Output is correct
9 Correct 363 ms 33412 KB Output is correct
10 Correct 105 ms 15932 KB Output is correct
11 Correct 155 ms 29400 KB Output is correct
12 Correct 65 ms 15492 KB Output is correct
13 Correct 609 ms 36360 KB Output is correct
14 Correct 592 ms 36224 KB Output is correct
15 Correct 509 ms 35828 KB Output is correct
16 Correct 221 ms 30676 KB Output is correct
17 Correct 176 ms 17240 KB Output is correct
18 Correct 83 ms 14932 KB Output is correct
19 Correct 533 ms 36284 KB Output is correct
20 Correct 557 ms 36260 KB Output is correct
21 Correct 517 ms 35088 KB Output is correct
22 Correct 107 ms 16000 KB Output is correct
23 Correct 181 ms 29472 KB Output is correct
24 Correct 59 ms 15568 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 9 ms 1456 KB Output is correct
8 Correct 9 ms 1468 KB Output is correct
9 Correct 9 ms 1432 KB Output is correct
10 Correct 6 ms 1328 KB Output is correct
11 Correct 5 ms 816 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 9 ms 1584 KB Output is correct
14 Correct 9 ms 1584 KB Output is correct
15 Correct 9 ms 1576 KB Output is correct
16 Correct 5 ms 848 KB Output is correct
17 Correct 5 ms 1456 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
19 Correct 514 ms 33316 KB Output is correct
20 Correct 512 ms 33348 KB Output is correct
21 Correct 494 ms 33328 KB Output is correct
22 Correct 248 ms 28528 KB Output is correct
23 Correct 169 ms 14916 KB Output is correct
24 Correct 91 ms 14200 KB Output is correct
25 Correct 423 ms 33464 KB Output is correct
26 Correct 457 ms 35816 KB Output is correct
27 Correct 363 ms 33412 KB Output is correct
28 Correct 105 ms 15932 KB Output is correct
29 Correct 155 ms 29400 KB Output is correct
30 Correct 65 ms 15492 KB Output is correct
31 Correct 609 ms 36360 KB Output is correct
32 Correct 592 ms 36224 KB Output is correct
33 Correct 509 ms 35828 KB Output is correct
34 Correct 221 ms 30676 KB Output is correct
35 Correct 176 ms 17240 KB Output is correct
36 Correct 83 ms 14932 KB Output is correct
37 Correct 533 ms 36284 KB Output is correct
38 Correct 557 ms 36260 KB Output is correct
39 Correct 517 ms 35088 KB Output is correct
40 Correct 107 ms 16000 KB Output is correct
41 Correct 181 ms 29472 KB Output is correct
42 Correct 59 ms 15568 KB Output is correct
43 Correct 673 ms 46944 KB Output is correct
44 Correct 708 ms 47212 KB Output is correct
45 Correct 646 ms 46816 KB Output is correct
46 Correct 259 ms 40564 KB Output is correct
47 Correct 179 ms 18608 KB Output is correct
48 Correct 80 ms 15048 KB Output is correct
49 Correct 559 ms 43800 KB Output is correct
50 Correct 583 ms 46780 KB Output is correct
51 Correct 506 ms 43628 KB Output is correct
52 Correct 125 ms 18280 KB Output is correct
53 Correct 189 ms 38988 KB Output is correct