Submission #839413

# Submission time Handle Problem Language Result Execution time Memory
839413 2023-08-30T02:13:06 Z anhduc2701 Examination (JOI19_examination) C++17
100 / 100
770 ms 42628 KB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
int n, q;
vector<pair<pair<int, int>, int>> s;
vector<int> poi;
vector<int> poi1;
struct BIT2D
{
    vector<int> po[maxn];
    vector<int> bit[maxn];
    void pre_upd(int x, int y)
    {
        for (int i = x; i >= 1; i -= i & (-i))
        {
            po[i].pb(y);
        }
    }
    void pre_get(int x, int y)
    {
        for (int i = x; i <= (int)(poi.size()); i += i & (-i))
        {
            po[i].pb(y);
        }
    }
    void init()
    {
        for (int i = 1; i <= (int)(poi.size()); i++)
        {
            sort(po[i].begin(), po[i].end());
            po[i].resize(unique(po[i].begin(), po[i].end()) - po[i].begin());
            bit[i].resize(po[i].size() + 1, 0);
        }
    }
    void upd(int x, int y)
    {
        for (int i = x; i >= 1; i -= i & (-i))
        {
            int id = lower_bound(po[i].begin(), po[i].end(), y) - po[i].begin() + 1;
            for (int j = id; j >= 1; j -= j & (-j))
            {
                bit[i][j] += 1;
            }
        }
    }
    int calc(int x, int y)
    {
        int res = 0;
        for (int i = x; i <= (int)(poi.size()); i += i & (-i))
        {
            int id = lower_bound(po[i].begin(), po[i].end(), y) - po[i].begin() + 1;
            for (int j = id; j < (int)(bit[i].size()); j += j & (-j))
            {
                res += bit[i][j];
            }
        }
        return res;
    }
} DS;
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b)
{
    if (a.fi.fi == b.fi.fi)
        return a.se > b.se;
    return a.fi.fi < b.fi.fi;
}
int X[maxn];
int Y[maxn];
int A[maxn], B[maxn], C[maxn];
int ans[maxn];
signed main()
{
    // freopen("input.inp", "r", stdin);
    // freopen("output.out", "w", stdout);
    cin.tie(0), cout.tie(0)->sync_with_stdio(0);
    cin >> n >> q;
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        poi.pb(y);
        poi1.pb(x + y);
        X[i] = x;
        Y[i] = y;
        s.pb({{x, i}, 0});
    }
    for (int i = 1; i <= q; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        A[i] = a;
        B[i] = b;
        C[i] = c;
        poi.pb(b);
        poi1.pb(c);
        s.pb({{a, i}, 1});
    }
    sort(poi.begin(), poi.end());
    sort(poi1.begin(), poi1.end());
    poi.resize(unique(poi.begin(), poi.end()) - poi.begin());
    poi1.resize(unique(poi1.begin(), poi1.end()) - poi1.begin());
    for (int i = 1; i <= n; i++)
    {
        int c = lower_bound(poi.begin(), poi.end(), Y[i]) - poi.begin() + 1;
        int d = lower_bound(poi1.begin(), poi1.end(), X[i]+Y[i]) - poi1.begin() + 1;
        DS.pre_upd(c, d);
    }
    for (int i = 1; i <= q; i++)
    {
        int b = lower_bound(poi.begin(), poi.end(), B[i]) - poi.begin() + 1;
        int c = lower_bound(poi1.begin(), poi1.end(), C[i]) - poi1.begin() + 1;
        DS.pre_get(b, c);
    }
    sort(s.begin(), s.end(),cmp);
    DS.init();
    for (int i = (int)(s.size()) - 1; i >= 0; i--)
    {
        int id = s[i].fi.se;
        int type = s[i].se;
        if (type == 0)
        {
            int c = lower_bound(poi.begin(), poi.end(), Y[id]) - poi.begin() + 1;
            int d = lower_bound(poi1.begin(), poi1.end(), X[id]+Y[id]) - poi1.begin() + 1;
            DS.upd(c, d);
        }
        else
        {
            int b = lower_bound(poi.begin(), poi.end(), B[id]) - poi.begin() + 1;
            int c = lower_bound(poi1.begin(), poi1.end(), C[id]) - poi1.begin() + 1;
            ans[id] = DS.calc(b, c);
        }
    }
    for (int i = 1; i <= q; i++)
    {
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 4 ms 9648 KB Output is correct
7 Correct 14 ms 10632 KB Output is correct
8 Correct 13 ms 10708 KB Output is correct
9 Correct 14 ms 10700 KB Output is correct
10 Correct 11 ms 10144 KB Output is correct
11 Correct 14 ms 10680 KB Output is correct
12 Correct 8 ms 10068 KB Output is correct
13 Correct 14 ms 10628 KB Output is correct
14 Correct 12 ms 10640 KB Output is correct
15 Correct 12 ms 10628 KB Output is correct
16 Correct 11 ms 10496 KB Output is correct
17 Correct 10 ms 10196 KB Output is correct
18 Correct 6 ms 10068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 391 ms 33040 KB Output is correct
2 Correct 408 ms 33236 KB Output is correct
3 Correct 396 ms 33268 KB Output is correct
4 Correct 143 ms 19764 KB Output is correct
5 Correct 369 ms 32376 KB Output is correct
6 Correct 81 ms 19440 KB Output is correct
7 Correct 382 ms 33260 KB Output is correct
8 Correct 363 ms 31804 KB Output is correct
9 Correct 329 ms 31872 KB Output is correct
10 Correct 342 ms 32076 KB Output is correct
11 Correct 118 ms 18532 KB Output is correct
12 Correct 60 ms 18364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 391 ms 33040 KB Output is correct
2 Correct 408 ms 33236 KB Output is correct
3 Correct 396 ms 33268 KB Output is correct
4 Correct 143 ms 19764 KB Output is correct
5 Correct 369 ms 32376 KB Output is correct
6 Correct 81 ms 19440 KB Output is correct
7 Correct 382 ms 33260 KB Output is correct
8 Correct 363 ms 31804 KB Output is correct
9 Correct 329 ms 31872 KB Output is correct
10 Correct 342 ms 32076 KB Output is correct
11 Correct 118 ms 18532 KB Output is correct
12 Correct 60 ms 18364 KB Output is correct
13 Correct 571 ms 36044 KB Output is correct
14 Correct 552 ms 35900 KB Output is correct
15 Correct 406 ms 33196 KB Output is correct
16 Correct 203 ms 20416 KB Output is correct
17 Correct 526 ms 35028 KB Output is correct
18 Correct 91 ms 19436 KB Output is correct
19 Correct 563 ms 36096 KB Output is correct
20 Correct 553 ms 35908 KB Output is correct
21 Correct 557 ms 34872 KB Output is correct
22 Correct 347 ms 32020 KB Output is correct
23 Correct 134 ms 18540 KB Output is correct
24 Correct 61 ms 18504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 4 ms 9648 KB Output is correct
7 Correct 14 ms 10632 KB Output is correct
8 Correct 13 ms 10708 KB Output is correct
9 Correct 14 ms 10700 KB Output is correct
10 Correct 11 ms 10144 KB Output is correct
11 Correct 14 ms 10680 KB Output is correct
12 Correct 8 ms 10068 KB Output is correct
13 Correct 14 ms 10628 KB Output is correct
14 Correct 12 ms 10640 KB Output is correct
15 Correct 12 ms 10628 KB Output is correct
16 Correct 11 ms 10496 KB Output is correct
17 Correct 10 ms 10196 KB Output is correct
18 Correct 6 ms 10068 KB Output is correct
19 Correct 391 ms 33040 KB Output is correct
20 Correct 408 ms 33236 KB Output is correct
21 Correct 396 ms 33268 KB Output is correct
22 Correct 143 ms 19764 KB Output is correct
23 Correct 369 ms 32376 KB Output is correct
24 Correct 81 ms 19440 KB Output is correct
25 Correct 382 ms 33260 KB Output is correct
26 Correct 363 ms 31804 KB Output is correct
27 Correct 329 ms 31872 KB Output is correct
28 Correct 342 ms 32076 KB Output is correct
29 Correct 118 ms 18532 KB Output is correct
30 Correct 60 ms 18364 KB Output is correct
31 Correct 571 ms 36044 KB Output is correct
32 Correct 552 ms 35900 KB Output is correct
33 Correct 406 ms 33196 KB Output is correct
34 Correct 203 ms 20416 KB Output is correct
35 Correct 526 ms 35028 KB Output is correct
36 Correct 91 ms 19436 KB Output is correct
37 Correct 563 ms 36096 KB Output is correct
38 Correct 553 ms 35908 KB Output is correct
39 Correct 557 ms 34872 KB Output is correct
40 Correct 347 ms 32020 KB Output is correct
41 Correct 134 ms 18540 KB Output is correct
42 Correct 61 ms 18504 KB Output is correct
43 Correct 675 ms 42628 KB Output is correct
44 Correct 700 ms 42628 KB Output is correct
45 Correct 682 ms 42504 KB Output is correct
46 Correct 216 ms 20840 KB Output is correct
47 Correct 705 ms 42468 KB Output is correct
48 Correct 107 ms 19264 KB Output is correct
49 Correct 688 ms 42372 KB Output is correct
50 Correct 770 ms 42356 KB Output is correct
51 Correct 661 ms 42444 KB Output is correct
52 Correct 671 ms 42256 KB Output is correct
53 Correct 116 ms 18532 KB Output is correct