Submission #1102802

# Submission time Handle Problem Language Result Execution time Memory
1102802 2024-10-19T01:30:12 Z Icelast Examination (JOI19_examination) C++17
2 / 100
1130 ms 1048576 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);
        norm.add(a[i].z);
    }
    for(int i = 1; i <= Q; i++){
        norm.add(q[i].x);
        norm.add(q[i].y);
        norm.add(q[i].z);
    }
    norm.start();
    int N = norm.pot.size();
    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);
        a[i].z = norm.encode(a[i].z);
    }
    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);
        q[i].z = norm.encode(q[i].z);
    }
    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 456 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 17 ms 4176 KB Output is correct
8 Correct 16 ms 4176 KB Output is correct
9 Correct 18 ms 4176 KB Output is correct
10 Correct 8 ms 2308 KB Output is correct
11 Correct 10 ms 2512 KB Output is correct
12 Correct 4 ms 952 KB Output is correct
13 Correct 16 ms 3512 KB Output is correct
14 Correct 14 ms 3536 KB Output is correct
15 Correct 15 ms 3544 KB Output is correct
16 Correct 7 ms 1744 KB Output is correct
17 Correct 7 ms 2124 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 757 ms 90036 KB Output is correct
2 Correct 772 ms 91060 KB Output is correct
3 Correct 720 ms 89524 KB Output is correct
4 Correct 204 ms 36784 KB Output is correct
5 Correct 254 ms 39860 KB Output is correct
6 Correct 76 ms 18356 KB Output is correct
7 Correct 697 ms 89308 KB Output is correct
8 Correct 722 ms 89356 KB Output is correct
9 Correct 617 ms 81332 KB Output is correct
10 Correct 217 ms 33996 KB Output is correct
11 Runtime error 1130 ms 1048576 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 757 ms 90036 KB Output is correct
2 Correct 772 ms 91060 KB Output is correct
3 Correct 720 ms 89524 KB Output is correct
4 Correct 204 ms 36784 KB Output is correct
5 Correct 254 ms 39860 KB Output is correct
6 Correct 76 ms 18356 KB Output is correct
7 Correct 697 ms 89308 KB Output is correct
8 Correct 722 ms 89356 KB Output is correct
9 Correct 617 ms 81332 KB Output is correct
10 Correct 217 ms 33996 KB Output is correct
11 Runtime error 1130 ms 1048576 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 456 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 17 ms 4176 KB Output is correct
8 Correct 16 ms 4176 KB Output is correct
9 Correct 18 ms 4176 KB Output is correct
10 Correct 8 ms 2308 KB Output is correct
11 Correct 10 ms 2512 KB Output is correct
12 Correct 4 ms 952 KB Output is correct
13 Correct 16 ms 3512 KB Output is correct
14 Correct 14 ms 3536 KB Output is correct
15 Correct 15 ms 3544 KB Output is correct
16 Correct 7 ms 1744 KB Output is correct
17 Correct 7 ms 2124 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
19 Correct 757 ms 90036 KB Output is correct
20 Correct 772 ms 91060 KB Output is correct
21 Correct 720 ms 89524 KB Output is correct
22 Correct 204 ms 36784 KB Output is correct
23 Correct 254 ms 39860 KB Output is correct
24 Correct 76 ms 18356 KB Output is correct
25 Correct 697 ms 89308 KB Output is correct
26 Correct 722 ms 89356 KB Output is correct
27 Correct 617 ms 81332 KB Output is correct
28 Correct 217 ms 33996 KB Output is correct
29 Runtime error 1130 ms 1048576 KB Execution killed with signal 9
30 Halted 0 ms 0 KB -