답안 #839433

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839433 2023-08-30T03:05:18 Z CDuong Examination (JOI19_examination) C++17
100 / 100
550 ms 41140 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 1 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 8 ms 1364 KB Output is correct
8 Correct 8 ms 1364 KB Output is correct
9 Correct 7 ms 1364 KB Output is correct
10 Correct 6 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 1364 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 342 ms 29436 KB Output is correct
2 Correct 363 ms 29376 KB Output is correct
3 Correct 345 ms 29352 KB Output is correct
4 Correct 98 ms 10152 KB Output is correct
5 Correct 368 ms 29532 KB Output is correct
6 Correct 68 ms 10304 KB Output is correct
7 Correct 316 ms 29444 KB Output is correct
8 Correct 330 ms 27864 KB Output is correct
9 Correct 306 ms 27860 KB Output is correct
10 Correct 352 ms 29368 KB Output is correct
11 Correct 73 ms 8760 KB Output is correct
12 Correct 45 ms 7980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 342 ms 29436 KB Output is correct
2 Correct 363 ms 29376 KB Output is correct
3 Correct 345 ms 29352 KB Output is correct
4 Correct 98 ms 10152 KB Output is correct
5 Correct 368 ms 29532 KB Output is correct
6 Correct 68 ms 10304 KB Output is correct
7 Correct 316 ms 29444 KB Output is correct
8 Correct 330 ms 27864 KB Output is correct
9 Correct 306 ms 27860 KB Output is correct
10 Correct 352 ms 29368 KB Output is correct
11 Correct 73 ms 8760 KB Output is correct
12 Correct 45 ms 7980 KB Output is correct
13 Correct 449 ms 29560 KB Output is correct
14 Correct 430 ms 29444 KB Output is correct
15 Correct 338 ms 29344 KB Output is correct
16 Correct 145 ms 10148 KB Output is correct
17 Correct 449 ms 29516 KB Output is correct
18 Correct 82 ms 10148 KB Output is correct
19 Correct 471 ms 29384 KB Output is correct
20 Correct 470 ms 29372 KB Output is correct
21 Correct 457 ms 27788 KB Output is correct
22 Correct 346 ms 29200 KB Output is correct
23 Correct 75 ms 8764 KB Output is correct
24 Correct 48 ms 7988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 8 ms 1364 KB Output is correct
8 Correct 8 ms 1364 KB Output is correct
9 Correct 7 ms 1364 KB Output is correct
10 Correct 6 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 1364 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 342 ms 29436 KB Output is correct
20 Correct 363 ms 29376 KB Output is correct
21 Correct 345 ms 29352 KB Output is correct
22 Correct 98 ms 10152 KB Output is correct
23 Correct 368 ms 29532 KB Output is correct
24 Correct 68 ms 10304 KB Output is correct
25 Correct 316 ms 29444 KB Output is correct
26 Correct 330 ms 27864 KB Output is correct
27 Correct 306 ms 27860 KB Output is correct
28 Correct 352 ms 29368 KB Output is correct
29 Correct 73 ms 8760 KB Output is correct
30 Correct 45 ms 7980 KB Output is correct
31 Correct 449 ms 29560 KB Output is correct
32 Correct 430 ms 29444 KB Output is correct
33 Correct 338 ms 29344 KB Output is correct
34 Correct 145 ms 10148 KB Output is correct
35 Correct 449 ms 29516 KB Output is correct
36 Correct 82 ms 10148 KB Output is correct
37 Correct 471 ms 29384 KB Output is correct
38 Correct 470 ms 29372 KB Output is correct
39 Correct 457 ms 27788 KB Output is correct
40 Correct 346 ms 29200 KB Output is correct
41 Correct 75 ms 8764 KB Output is correct
42 Correct 48 ms 7988 KB Output is correct
43 Correct 550 ms 41016 KB Output is correct
44 Correct 540 ms 41080 KB Output is correct
45 Correct 532 ms 41140 KB Output is correct
46 Correct 166 ms 10220 KB Output is correct
47 Correct 537 ms 40928 KB Output is correct
48 Correct 90 ms 10016 KB Output is correct
49 Correct 510 ms 41016 KB Output is correct
50 Correct 532 ms 41080 KB Output is correct
51 Correct 517 ms 41128 KB Output is correct
52 Correct 533 ms 40856 KB Output is correct
53 Correct 78 ms 8736 KB Output is correct