Submission #104557

# Submission time Handle Problem Language Result Execution time Memory
104557 2019-04-08T03:29:41 Z minhtung0404 Examination (JOI19_examination) C++17
100 / 100
1223 ms 53208 KB
#include<bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;

vector <int> mv;
int n, m, st[N], ans[N];

struct point{
    int s, t;

    bool operator < (const point&a) const {
        return (s + t) < (a.s + a.t);
    }
} a[N];

struct query{
    int x, y, z, id;

    bool operator < (const query&a) const {
        return z > a.z;
    }
} q[N];

struct node{
    vector <int> mv;
    vector <int> bit;
    int n, cnt;

    void init(){
        sort(mv.begin(), mv.end());
        mv.resize(unique(mv.begin(), mv.end()) - mv.begin());
        n = mv.size();
        bit.resize(mv.size());
    }

    void update(int i){
        i = lower_bound(mv.begin(), mv.end(), i) - mv.begin();
        i++; cnt++;
        while (i <= n){
            bit[i-1]++;
            i += i&(-i);
        }
    }

    int get(int i){
        i = lower_bound(mv.begin(), mv.end(), i) - mv.begin();
        int ans = 0;
        while (i > 0){
            ans += bit[i-1];
            i -= i&(-i);
        }
        return cnt - ans;
    }
} it[N << 2];

void update(int i, int l, int r, int pos, int val){
    if (l > pos || pos > r) return;
    it[i].update(val);
    if (l == r) return;
    int mid = (l + r) >> 1;
    update(i << 1, l, mid, pos, val); update(i << 1 | 1, mid+1, r, pos, val);
}

int get(int i, int l, int r, int L, int R, int val){
    if (L > r || l > R) return 0;
    if (L <= l && r <= R) return it[i].get(val);
    int mid = (l + r) >> 1;
    return get(i << 1, l, mid, L, R, val) + get(i << 1 | 1, mid+1, r, L, R, val);
}

void prep(int i, int l, int r){
    if (l == r) {
        st[l] = i;
        return;
    }
    int mid = (l + r) >> 1;
    prep(i << 1, l, mid); prep(i << 1 | 1, mid+1, r);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i].s >> a[i].t, mv.push_back(a[i].s);
    sort(a+1, a+1+n); sort(mv.begin(), mv.end());

    mv.resize(unique(mv.begin(), mv.end()) - mv.begin());
    int MAX = (int)mv.size();
    prep(1, 1, MAX);
    for (int i = 1; i <= n; i++){
        int node = st[lower_bound(mv.begin(), mv.end(), a[i].s) - mv.begin() + 1];
        while (node) it[node]. mv.push_back(a[i].t), node >>= 1;
    }
    for (int i = 0; i < N << 2; i++) it[i].init();

    for (int i = 1; i <= m; i++){
        q[i].id = i;
        cin >> q[i].x >> q[i].y >> q[i].z;
    }
    sort(q+1, q+1+m);

    int cur = n;
    for (int i = 1; i <= m; i++){
        while (cur && a[cur].s + a[cur].t >= q[i].z) {
            update(1, 1, MAX, lower_bound(mv.begin(), mv.end(), a[cur].s) - mv.begin() + 1, a[cur].t);
            cur--;
        }
        ans[q[i].id] = get(1, 1, MAX, lower_bound(mv.begin(), mv.end(), q[i].x) - mv.begin() + 1, MAX, q[i].y);
    }

    for (int i = 1; i <= m; i++) cout << ans[i] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 27 ms 22272 KB Output is correct
2 Correct 25 ms 22272 KB Output is correct
3 Correct 26 ms 22272 KB Output is correct
4 Correct 25 ms 22272 KB Output is correct
5 Correct 26 ms 22272 KB Output is correct
6 Correct 29 ms 22272 KB Output is correct
7 Correct 39 ms 23160 KB Output is correct
8 Correct 38 ms 23164 KB Output is correct
9 Correct 47 ms 23168 KB Output is correct
10 Correct 40 ms 23032 KB Output is correct
11 Correct 31 ms 22648 KB Output is correct
12 Correct 30 ms 22492 KB Output is correct
13 Correct 39 ms 23168 KB Output is correct
14 Correct 42 ms 23164 KB Output is correct
15 Correct 40 ms 23160 KB Output is correct
16 Correct 29 ms 22520 KB Output is correct
17 Correct 32 ms 23032 KB Output is correct
18 Correct 27 ms 22520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 930 ms 47916 KB Output is correct
2 Correct 916 ms 48116 KB Output is correct
3 Correct 919 ms 48152 KB Output is correct
4 Correct 384 ms 43124 KB Output is correct
5 Correct 185 ms 31496 KB Output is correct
6 Correct 114 ms 29416 KB Output is correct
7 Correct 756 ms 48352 KB Output is correct
8 Correct 802 ms 48116 KB Output is correct
9 Correct 734 ms 48120 KB Output is correct
10 Correct 104 ms 28148 KB Output is correct
11 Correct 317 ms 42644 KB Output is correct
12 Correct 81 ms 27120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 930 ms 47916 KB Output is correct
2 Correct 916 ms 48116 KB Output is correct
3 Correct 919 ms 48152 KB Output is correct
4 Correct 384 ms 43124 KB Output is correct
5 Correct 185 ms 31496 KB Output is correct
6 Correct 114 ms 29416 KB Output is correct
7 Correct 756 ms 48352 KB Output is correct
8 Correct 802 ms 48116 KB Output is correct
9 Correct 734 ms 48120 KB Output is correct
10 Correct 104 ms 28148 KB Output is correct
11 Correct 317 ms 42644 KB Output is correct
12 Correct 81 ms 27120 KB Output is correct
13 Correct 902 ms 48068 KB Output is correct
14 Correct 959 ms 48180 KB Output is correct
15 Correct 894 ms 48240 KB Output is correct
16 Correct 459 ms 43460 KB Output is correct
17 Correct 236 ms 31892 KB Output is correct
18 Correct 102 ms 29556 KB Output is correct
19 Correct 1065 ms 48116 KB Output is correct
20 Correct 1055 ms 48100 KB Output is correct
21 Correct 1089 ms 48048 KB Output is correct
22 Correct 110 ms 28148 KB Output is correct
23 Correct 329 ms 42736 KB Output is correct
24 Correct 86 ms 27124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 22272 KB Output is correct
2 Correct 25 ms 22272 KB Output is correct
3 Correct 26 ms 22272 KB Output is correct
4 Correct 25 ms 22272 KB Output is correct
5 Correct 26 ms 22272 KB Output is correct
6 Correct 29 ms 22272 KB Output is correct
7 Correct 39 ms 23160 KB Output is correct
8 Correct 38 ms 23164 KB Output is correct
9 Correct 47 ms 23168 KB Output is correct
10 Correct 40 ms 23032 KB Output is correct
11 Correct 31 ms 22648 KB Output is correct
12 Correct 30 ms 22492 KB Output is correct
13 Correct 39 ms 23168 KB Output is correct
14 Correct 42 ms 23164 KB Output is correct
15 Correct 40 ms 23160 KB Output is correct
16 Correct 29 ms 22520 KB Output is correct
17 Correct 32 ms 23032 KB Output is correct
18 Correct 27 ms 22520 KB Output is correct
19 Correct 930 ms 47916 KB Output is correct
20 Correct 916 ms 48116 KB Output is correct
21 Correct 919 ms 48152 KB Output is correct
22 Correct 384 ms 43124 KB Output is correct
23 Correct 185 ms 31496 KB Output is correct
24 Correct 114 ms 29416 KB Output is correct
25 Correct 756 ms 48352 KB Output is correct
26 Correct 802 ms 48116 KB Output is correct
27 Correct 734 ms 48120 KB Output is correct
28 Correct 104 ms 28148 KB Output is correct
29 Correct 317 ms 42644 KB Output is correct
30 Correct 81 ms 27120 KB Output is correct
31 Correct 902 ms 48068 KB Output is correct
32 Correct 959 ms 48180 KB Output is correct
33 Correct 894 ms 48240 KB Output is correct
34 Correct 459 ms 43460 KB Output is correct
35 Correct 236 ms 31892 KB Output is correct
36 Correct 102 ms 29556 KB Output is correct
37 Correct 1065 ms 48116 KB Output is correct
38 Correct 1055 ms 48100 KB Output is correct
39 Correct 1089 ms 48048 KB Output is correct
40 Correct 110 ms 28148 KB Output is correct
41 Correct 329 ms 42736 KB Output is correct
42 Correct 86 ms 27124 KB Output is correct
43 Correct 1175 ms 52960 KB Output is correct
44 Correct 1135 ms 52980 KB Output is correct
45 Correct 1223 ms 53208 KB Output is correct
46 Correct 581 ms 48240 KB Output is correct
47 Correct 198 ms 32244 KB Output is correct
48 Correct 135 ms 29224 KB Output is correct
49 Correct 1107 ms 53104 KB Output is correct
50 Correct 1045 ms 53124 KB Output is correct
51 Correct 1142 ms 53108 KB Output is correct
52 Correct 152 ms 28764 KB Output is correct
53 Correct 373 ms 47608 KB Output is correct