Submission #1102804

# Submission time Handle Problem Language Result Execution time Memory
1102804 2024-10-19T01:43:22 Z Icelast Examination (JOI19_examination) C++17
100 / 100
946 ms 139688 KB
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 4e18+9;
struct point{
    ll x, y, z, id;
};
struct normalize{
    vector<ll> poi, pot;
    void add(ll x){
        poi.push_back(x);
    }
    void start(){
        sort(poi.begin(), poi.end());
        pot.push_back(poi[0]);
        for(int i = 1; i < (int)poi.size(); i++){
            if(poi[i] != poi[i-1]){
                pot.push_back(poi[i]);
            }
        }
    }
    int encode(ll x){
        return lower_bound(pot.begin(), pot.end(), x) - pot.begin()+1;
    }
};
struct Fenwick2D {
    int n, m;
    vector<vector<int>> bit;
    vector<vector<int>> f;

    Fenwick2D(int n, int m) : n(n), m(m), bit(n + 1), f(n + 1) {}

    void fakeAdd(int i0, int j0) {
        for (int i = i0; i <= n; i += i & -i) {
            for (int j = j0; j <= m; j += j & -j) {
                f[i].push_back(j);
            }
        }
    }

    void work() {
        for (int i = 1; i <= n; i++) {
            f[i].push_back(0);
            sort(f[i].begin(), f[i].end());
            f[i].resize(unique(f[i].begin(), f[i].end()) - f[i].begin());
            bit[i].resize(f[i].size(), 0);
        }
    }

    void add(int i0, int j0, int x) {
        for (int i = i0; i <= n; i += i & -i) {
            for (int j = lower_bound(f[i].begin(), f[i].end(), j0) - f[i].begin(); j < (int)f[i].size(); j += j & -j) {
                bit[i][j] += x;
            }
        }
    }

    int sum(int i0, int j0) {
        int res = 0;
        for (int i = i0; i > 0; i -= i & -i) {
            for (int j = upper_bound(f[i].begin(), f[i].end(), j0) - f[i].begin() - 1; j > 0; j -= j & -j) {
                res += bit[i][j];
            }
        }
        return res;
    }
};
void solve(){
    int n, Q;
    cin >> n >> Q;
    vector<point> a(n+1);
    for(int i = 1; i <= n; i++){
        cin >> a[i].x >> a[i].y;
        a[i].z = a[i].x+a[i].y;
    }
    vector<point> q(Q+1);
    for(int i = 1; i <= Q; i++){
        cin >> q[i].x >> q[i].y >> q[i].z;
        q[i].id = i;
    }
    normalize norm;
    for(int i = 1; i <= n; i++){
        norm.add(a[i].x);
        norm.add(a[i].y);
    }
    for(int i = 1; i <= Q; i++){
        norm.add(q[i].x);
        norm.add(q[i].y);
    }
    norm.start();
    int N = norm.pot.size()+1;
    for(int i = 1; i <= n; i++){
        a[i].x = N-norm.encode(a[i].x);
        a[i].y = N-norm.encode(a[i].y);
    }
    for(int i = 1; i <= Q; i++){
        q[i].x = N-norm.encode(q[i].x);
        q[i].y = N-norm.encode(q[i].y);
    }
    Fenwick2D bit(N+1, N+1);
    for(int i = 1; i <= n; i++){
        bit.fakeAdd(a[i].x, a[i].y);
    }
    bit.work();
    sort(a.begin()+1, a.end(), [&](point a, point b){return a.z > b.z;});
    sort(q.begin()+1, q.end(), [&](point a, point b){return a.z > b.z;});
    vector<ll> ans(Q+1);
    int j = 1;
    for(int i = 1; i <= Q; i++){
        while(j <= n && a[j].z >= q[i].z){
            bit.add(a[j].x, a[j].y, 1);
            j++;
        }
        ans[q[i].id] = bit.sum(q[i].x, q[i].y);
    }
    for(int i = 1; i <= Q; i++){
        cout << ans[i] << "\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 13 ms 3152 KB Output is correct
8 Correct 15 ms 3152 KB Output is correct
9 Correct 16 ms 3152 KB Output is correct
10 Correct 7 ms 1616 KB Output is correct
11 Correct 7 ms 1756 KB Output is correct
12 Correct 4 ms 848 KB Output is correct
13 Correct 13 ms 3200 KB Output is correct
14 Correct 13 ms 3144 KB Output is correct
15 Correct 16 ms 3152 KB Output is correct
16 Correct 7 ms 1752 KB Output is correct
17 Correct 6 ms 1616 KB Output is correct
18 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 646 ms 81312 KB Output is correct
2 Correct 693 ms 82160 KB Output is correct
3 Correct 673 ms 82352 KB Output is correct
4 Correct 201 ms 32952 KB Output is correct
5 Correct 227 ms 34488 KB Output is correct
6 Correct 75 ms 16580 KB Output is correct
7 Correct 652 ms 81448 KB Output is correct
8 Correct 639 ms 82268 KB Output is correct
9 Correct 572 ms 79312 KB Output is correct
10 Correct 199 ms 31936 KB Output is correct
11 Correct 145 ms 32952 KB Output is correct
12 Correct 41 ms 13772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 646 ms 81312 KB Output is correct
2 Correct 693 ms 82160 KB Output is correct
3 Correct 673 ms 82352 KB Output is correct
4 Correct 201 ms 32952 KB Output is correct
5 Correct 227 ms 34488 KB Output is correct
6 Correct 75 ms 16580 KB Output is correct
7 Correct 652 ms 81448 KB Output is correct
8 Correct 639 ms 82268 KB Output is correct
9 Correct 572 ms 79312 KB Output is correct
10 Correct 199 ms 31936 KB Output is correct
11 Correct 145 ms 32952 KB Output is correct
12 Correct 41 ms 13772 KB Output is correct
13 Correct 661 ms 82600 KB Output is correct
14 Correct 651 ms 82620 KB Output is correct
15 Correct 679 ms 82364 KB Output is correct
16 Correct 202 ms 34216 KB Output is correct
17 Correct 248 ms 38296 KB Output is correct
18 Correct 75 ms 16832 KB Output is correct
19 Correct 672 ms 82924 KB Output is correct
20 Correct 699 ms 82756 KB Output is correct
21 Correct 644 ms 81596 KB Output is correct
22 Correct 191 ms 32444 KB Output is correct
23 Correct 158 ms 32960 KB Output is correct
24 Correct 52 ms 13812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 13 ms 3152 KB Output is correct
8 Correct 15 ms 3152 KB Output is correct
9 Correct 16 ms 3152 KB Output is correct
10 Correct 7 ms 1616 KB Output is correct
11 Correct 7 ms 1756 KB Output is correct
12 Correct 4 ms 848 KB Output is correct
13 Correct 13 ms 3200 KB Output is correct
14 Correct 13 ms 3144 KB Output is correct
15 Correct 16 ms 3152 KB Output is correct
16 Correct 7 ms 1752 KB Output is correct
17 Correct 6 ms 1616 KB Output is correct
18 Correct 3 ms 1016 KB Output is correct
19 Correct 646 ms 81312 KB Output is correct
20 Correct 693 ms 82160 KB Output is correct
21 Correct 673 ms 82352 KB Output is correct
22 Correct 201 ms 32952 KB Output is correct
23 Correct 227 ms 34488 KB Output is correct
24 Correct 75 ms 16580 KB Output is correct
25 Correct 652 ms 81448 KB Output is correct
26 Correct 639 ms 82268 KB Output is correct
27 Correct 572 ms 79312 KB Output is correct
28 Correct 199 ms 31936 KB Output is correct
29 Correct 145 ms 32952 KB Output is correct
30 Correct 41 ms 13772 KB Output is correct
31 Correct 661 ms 82600 KB Output is correct
32 Correct 651 ms 82620 KB Output is correct
33 Correct 679 ms 82364 KB Output is correct
34 Correct 202 ms 34216 KB Output is correct
35 Correct 248 ms 38296 KB Output is correct
36 Correct 75 ms 16832 KB Output is correct
37 Correct 672 ms 82924 KB Output is correct
38 Correct 699 ms 82756 KB Output is correct
39 Correct 644 ms 81596 KB Output is correct
40 Correct 191 ms 32444 KB Output is correct
41 Correct 158 ms 32960 KB Output is correct
42 Correct 52 ms 13812 KB Output is correct
43 Correct 946 ms 137280 KB Output is correct
44 Correct 856 ms 138176 KB Output is correct
45 Correct 858 ms 137432 KB Output is correct
46 Correct 256 ms 50116 KB Output is correct
47 Correct 264 ms 51564 KB Output is correct
48 Correct 72 ms 16568 KB Output is correct
49 Correct 910 ms 132468 KB Output is correct
50 Correct 883 ms 132332 KB Output is correct
51 Correct 891 ms 139688 KB Output is correct
52 Correct 176 ms 43856 KB Output is correct
53 Correct 169 ms 41652 KB Output is correct