답안 #839434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839434 2023-08-30T03:05:57 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
562 ms 41204 KB
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define vvi vector<vi>
#define isz(x) (int)x.size()
using namespace std;

const int mxN = 2e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;

struct point {
    int x, y, sum, idx;
    
    point(int x, int y, int sum, int idx = 0) : x(x), y(y), sum(sum), idx(idx) {}

    bool operator < (const point &o) const {
        return x < o.x;
    }
};

struct FenwickTree2D {
    int n;
    vvi data;
    vvi BIT;

    FenwickTree2D(int n) : n(n) {
        BIT.resize(n + 1);
        data.resize(n + 1);
    }

    void fupdate(int x, int y) {
        for (; x <= n; x += x & -x)
            data[x].emplace_back(y);
    }

    void fget(int x, int y) {
        for (; x > 0; x -= x & -x)
            data[x].emplace_back(y);
    }

    void initBIT() {
        for (int i = 1; i <= n; ++i) {
            sort(all(data[i]));
            BIT[i].resize(isz(data[i]) + 1);
        }
    }

    void update(int x, int yy, int val) {
        for (; x <= n; x += x & -x) {
            int y = lower_bound(all(data[x]), yy) - data[x].begin() + 1;
            for (; y <= isz(data[x]); y += y & -y)
                BIT[x][y] += val;
        }
    }

    int get(int x, int yy) {
        int res = 0;
        for (; x; x -= x & -x) {
            int y = lower_bound(all(data[x]), yy) - data[x].begin() + 1;
            for (; y > 0; y -= y & -y)
                res += BIT[x][y];
        }
        return res;
    }
};

vi r, c;
int n, q, ans[mxN];
vector<point> a, qq;

void solve() {
    cin >> n >> q;
    for (int i = 1; i <= n; ++i) {
        int x, y;
        cin >> x >> y;
        x = -x, y = -y;
        r.emplace_back(y);
        c.emplace_back(x + y);
        a.emplace_back(x, y, x + y);
    }
    for (int i = 1; i <= q; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        x = -x, y = -y, z = -z;
        r.emplace_back(y);
        c.emplace_back(z);
        qq.emplace_back(x, y, z, i);
    }
    
    sort(all(a)); sort(all(qq));
    sort(all(r)); r.erase(unique(all(r)), r.end());
    sort(all(c)); c.erase(unique(all(c)), c.end());

    FenwickTree2D fenw(isz(r));
    for (auto &[x, y, sum, idx] : a) {
        y = lower_bound(all(r), y) - r.begin() + 1;
        sum = lower_bound(all(c), sum) - c.begin() + 1;
        fenw.fupdate(y, sum);
    }
    for (auto &[x, y, sum, idx] : qq) {
        y = lower_bound(all(r), y) - r.begin() + 1;
        sum = lower_bound(all(c), sum) - c.begin() + 1;
        fenw.fget(y, sum);
    }
    fenw.initBIT();

    int ptr = 0;
    for (int i = 0; i < q; ++i) {
        auto [x, y, sum, idx] = qq[i];
        while (ptr < n && a[ptr].x <= x) {
            fenw.update(a[ptr].y, a[ptr].sum, 1);
            ++ptr;
        }
        ans[idx] = fenw.get(y, sum);
    }

    for (int i = 1; i <= q; ++i) {
        cout << ans[i] << "\n";
    }
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
   auto end = chrono::high_resolution_clock::now();
   cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
   cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 10 ms 1364 KB Output is correct
8 Correct 10 ms 1364 KB Output is correct
9 Correct 7 ms 1364 KB Output is correct
10 Correct 4 ms 596 KB Output is correct
11 Correct 7 ms 1364 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 6 ms 1364 KB Output is correct
14 Correct 6 ms 1364 KB Output is correct
15 Correct 6 ms 1364 KB Output is correct
16 Correct 7 ms 1436 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 29440 KB Output is correct
2 Correct 348 ms 29348 KB Output is correct
3 Correct 335 ms 29372 KB Output is correct
4 Correct 100 ms 10144 KB Output is correct
5 Correct 349 ms 29500 KB Output is correct
6 Correct 71 ms 10224 KB Output is correct
7 Correct 346 ms 29448 KB Output is correct
8 Correct 357 ms 27864 KB Output is correct
9 Correct 292 ms 27840 KB Output is correct
10 Correct 338 ms 29320 KB Output is correct
11 Correct 80 ms 8748 KB Output is correct
12 Correct 46 ms 8060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 343 ms 29440 KB Output is correct
2 Correct 348 ms 29348 KB Output is correct
3 Correct 335 ms 29372 KB Output is correct
4 Correct 100 ms 10144 KB Output is correct
5 Correct 349 ms 29500 KB Output is correct
6 Correct 71 ms 10224 KB Output is correct
7 Correct 346 ms 29448 KB Output is correct
8 Correct 357 ms 27864 KB Output is correct
9 Correct 292 ms 27840 KB Output is correct
10 Correct 338 ms 29320 KB Output is correct
11 Correct 80 ms 8748 KB Output is correct
12 Correct 46 ms 8060 KB Output is correct
13 Correct 474 ms 29444 KB Output is correct
14 Correct 450 ms 29456 KB Output is correct
15 Correct 364 ms 29396 KB Output is correct
16 Correct 148 ms 10144 KB Output is correct
17 Correct 462 ms 29496 KB Output is correct
18 Correct 80 ms 10168 KB Output is correct
19 Correct 523 ms 29380 KB Output is correct
20 Correct 458 ms 29344 KB Output is correct
21 Correct 456 ms 27816 KB Output is correct
22 Correct 342 ms 29224 KB Output is correct
23 Correct 76 ms 8740 KB Output is correct
24 Correct 45 ms 7992 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 10 ms 1364 KB Output is correct
8 Correct 10 ms 1364 KB Output is correct
9 Correct 7 ms 1364 KB Output is correct
10 Correct 4 ms 596 KB Output is correct
11 Correct 7 ms 1364 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 6 ms 1364 KB Output is correct
14 Correct 6 ms 1364 KB Output is correct
15 Correct 6 ms 1364 KB Output is correct
16 Correct 7 ms 1436 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 343 ms 29440 KB Output is correct
20 Correct 348 ms 29348 KB Output is correct
21 Correct 335 ms 29372 KB Output is correct
22 Correct 100 ms 10144 KB Output is correct
23 Correct 349 ms 29500 KB Output is correct
24 Correct 71 ms 10224 KB Output is correct
25 Correct 346 ms 29448 KB Output is correct
26 Correct 357 ms 27864 KB Output is correct
27 Correct 292 ms 27840 KB Output is correct
28 Correct 338 ms 29320 KB Output is correct
29 Correct 80 ms 8748 KB Output is correct
30 Correct 46 ms 8060 KB Output is correct
31 Correct 474 ms 29444 KB Output is correct
32 Correct 450 ms 29456 KB Output is correct
33 Correct 364 ms 29396 KB Output is correct
34 Correct 148 ms 10144 KB Output is correct
35 Correct 462 ms 29496 KB Output is correct
36 Correct 80 ms 10168 KB Output is correct
37 Correct 523 ms 29380 KB Output is correct
38 Correct 458 ms 29344 KB Output is correct
39 Correct 456 ms 27816 KB Output is correct
40 Correct 342 ms 29224 KB Output is correct
41 Correct 76 ms 8740 KB Output is correct
42 Correct 45 ms 7992 KB Output is correct
43 Correct 531 ms 40996 KB Output is correct
44 Correct 542 ms 41072 KB Output is correct
45 Correct 531 ms 41132 KB Output is correct
46 Correct 155 ms 10168 KB Output is correct
47 Correct 562 ms 40876 KB Output is correct
48 Correct 88 ms 9980 KB Output is correct
49 Correct 505 ms 41080 KB Output is correct
50 Correct 548 ms 41064 KB Output is correct
51 Correct 522 ms 41204 KB Output is correct
52 Correct 554 ms 40932 KB Output is correct
53 Correct 80 ms 8732 KB Output is correct