답안 #839415

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839415 2023-08-30T02:13:44 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
688 ms 42124 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';
    }
}
# 결과 실행 시간 메모리 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 4 ms 9684 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 4 ms 9720 KB Output is correct
7 Correct 13 ms 10584 KB Output is correct
8 Correct 13 ms 10540 KB Output is correct
9 Correct 13 ms 10580 KB Output is correct
10 Correct 9 ms 10068 KB Output is correct
11 Correct 13 ms 10580 KB Output is correct
12 Correct 7 ms 10040 KB Output is correct
13 Correct 11 ms 10452 KB Output is correct
14 Correct 16 ms 10544 KB Output is correct
15 Correct 11 ms 10452 KB Output is correct
16 Correct 13 ms 10504 KB Output is correct
17 Correct 9 ms 9940 KB Output is correct
18 Correct 7 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 372 ms 32644 KB Output is correct
2 Correct 443 ms 32644 KB Output is correct
3 Correct 381 ms 32812 KB Output is correct
4 Correct 132 ms 19224 KB Output is correct
5 Correct 358 ms 31880 KB Output is correct
6 Correct 83 ms 19028 KB Output is correct
7 Correct 364 ms 32648 KB Output is correct
8 Correct 351 ms 31344 KB Output is correct
9 Correct 318 ms 31288 KB Output is correct
10 Correct 336 ms 31560 KB Output is correct
11 Correct 111 ms 17924 KB Output is correct
12 Correct 60 ms 17900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 372 ms 32644 KB Output is correct
2 Correct 443 ms 32644 KB Output is correct
3 Correct 381 ms 32812 KB Output is correct
4 Correct 132 ms 19224 KB Output is correct
5 Correct 358 ms 31880 KB Output is correct
6 Correct 83 ms 19028 KB Output is correct
7 Correct 364 ms 32648 KB Output is correct
8 Correct 351 ms 31344 KB Output is correct
9 Correct 318 ms 31288 KB Output is correct
10 Correct 336 ms 31560 KB Output is correct
11 Correct 111 ms 17924 KB Output is correct
12 Correct 60 ms 17900 KB Output is correct
13 Correct 572 ms 35504 KB Output is correct
14 Correct 561 ms 35380 KB Output is correct
15 Correct 392 ms 32616 KB Output is correct
16 Correct 221 ms 19888 KB Output is correct
17 Correct 499 ms 34608 KB Output is correct
18 Correct 89 ms 18980 KB Output is correct
19 Correct 556 ms 35584 KB Output is correct
20 Correct 572 ms 35420 KB Output is correct
21 Correct 552 ms 34416 KB Output is correct
22 Correct 350 ms 31600 KB Output is correct
23 Correct 106 ms 18032 KB Output is correct
24 Correct 60 ms 17992 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 9684 KB Output is correct
5 Correct 4 ms 9684 KB Output is correct
6 Correct 4 ms 9720 KB Output is correct
7 Correct 13 ms 10584 KB Output is correct
8 Correct 13 ms 10540 KB Output is correct
9 Correct 13 ms 10580 KB Output is correct
10 Correct 9 ms 10068 KB Output is correct
11 Correct 13 ms 10580 KB Output is correct
12 Correct 7 ms 10040 KB Output is correct
13 Correct 11 ms 10452 KB Output is correct
14 Correct 16 ms 10544 KB Output is correct
15 Correct 11 ms 10452 KB Output is correct
16 Correct 13 ms 10504 KB Output is correct
17 Correct 9 ms 9940 KB Output is correct
18 Correct 7 ms 9940 KB Output is correct
19 Correct 372 ms 32644 KB Output is correct
20 Correct 443 ms 32644 KB Output is correct
21 Correct 381 ms 32812 KB Output is correct
22 Correct 132 ms 19224 KB Output is correct
23 Correct 358 ms 31880 KB Output is correct
24 Correct 83 ms 19028 KB Output is correct
25 Correct 364 ms 32648 KB Output is correct
26 Correct 351 ms 31344 KB Output is correct
27 Correct 318 ms 31288 KB Output is correct
28 Correct 336 ms 31560 KB Output is correct
29 Correct 111 ms 17924 KB Output is correct
30 Correct 60 ms 17900 KB Output is correct
31 Correct 572 ms 35504 KB Output is correct
32 Correct 561 ms 35380 KB Output is correct
33 Correct 392 ms 32616 KB Output is correct
34 Correct 221 ms 19888 KB Output is correct
35 Correct 499 ms 34608 KB Output is correct
36 Correct 89 ms 18980 KB Output is correct
37 Correct 556 ms 35584 KB Output is correct
38 Correct 572 ms 35420 KB Output is correct
39 Correct 552 ms 34416 KB Output is correct
40 Correct 350 ms 31600 KB Output is correct
41 Correct 106 ms 18032 KB Output is correct
42 Correct 60 ms 17992 KB Output is correct
43 Correct 657 ms 42124 KB Output is correct
44 Correct 688 ms 42084 KB Output is correct
45 Correct 644 ms 41988 KB Output is correct
46 Correct 211 ms 20272 KB Output is correct
47 Correct 670 ms 41956 KB Output is correct
48 Correct 97 ms 18740 KB Output is correct
49 Correct 639 ms 41860 KB Output is correct
50 Correct 672 ms 41848 KB Output is correct
51 Correct 607 ms 41968 KB Output is correct
52 Correct 635 ms 41752 KB Output is correct
53 Correct 114 ms 17920 KB Output is correct