Submission #685291

# Submission time Handle Problem Language Result Execution time Memory
685291 2023-01-24T01:08:47 Z izanbf Examination (JOI19_examination) C++14
100 / 100
407 ms 23384 KB
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
const int MOD = 1e9 + 7;
const int maxN = 200000;
 
bool cmp(pair<int, int> a, pair<int, int> b){
    return a.first + a.second > b.first + b.second;
}
 
bool cmp2(tuple<int, int, int, int> a, tuple<int, int, int, int> b){
    return get<2>(a) > get<2>(b);
}
 
struct BIT {
    int* bit;
    int n;
 
    void init(int n_) {
        n = n_+1;
        bit = new int[n+1];
        fill(bit, bit+n+1, 0);
    }

    int sum(int r) {
        int sum = 0;
        for (; r > 0; r -= r&-r)
            sum += bit[r];
        return sum;
    }

    int sum(int l, int r) { return sum(r) - sum(l-1); }
     
    void add(int r, int delta) {
        for (++r; r <= n; r += r&-r)
            bit[r] += delta;
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    int n, q; cin >> n >> q;
    vector<pair<int, int>> v(n);
    set<int> sa, sb;
    for(int i = 0; i < n; i++){
        int x, y; cin >> x >> y;
        v[i] = {x, y};
        sa.insert(x);
        sb.insert(y);
    }
    map<int, int> a, b;
    int curr = 1;
    for(auto x : sa){
        a[x] = curr;
        curr++;
    }
    BIT sta; sta.init(curr);
    int sza = curr;
    curr = 1;
    for(auto x : sb){
        b[x] = curr;
        curr++;
    }
    BIT stb; stb.init(curr);
    int szb = curr;
    sort(v.begin(), v.end(), cmp);
    vector<tuple<int, int, int, int>> queries(q);
    for(int i = 0; i < q; i++){
        int x, y, z; cin >> x >> y >> z;
        int nx = sza;
        auto it = a.lower_bound(x);
        if(it != a.end()) nx = (*it).second;
        int ny = szb;
        it = b.lower_bound(y);
        if(it != b.end()) ny = (*it).second;
        queries[i] = {nx, ny, max(z, x + y), i};
    }
    sort(queries.begin(), queries.end(), cmp2);
    vector<int> ans(q);
    curr = 0;
    for(int i = 0; i < q; i++){
        while(curr < n && v[curr].first + v[curr].second >= get<2>(queries[i])){
            sta.add(a[v[curr].first], 1);
            stb.add(b[v[curr].second], 1);
            curr++;
        }
        int total = curr - sta.sum(1, get<0>(queries[i])) - stb.sum(1, get<1>(queries[i]));
        ans[get<3>(queries[i])] = total;
    }
    for(int x : ans) cout << x << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 216 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 6 ms 1100 KB Output is correct
8 Correct 6 ms 1028 KB Output is correct
9 Correct 6 ms 1108 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 6 ms 1008 KB Output is correct
14 Correct 5 ms 1112 KB Output is correct
15 Correct 5 ms 1108 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 239 ms 16128 KB Output is correct
2 Correct 256 ms 16160 KB Output is correct
3 Correct 234 ms 16148 KB Output is correct
4 Correct 162 ms 9932 KB Output is correct
5 Correct 136 ms 9940 KB Output is correct
6 Correct 58 ms 3764 KB Output is correct
7 Correct 229 ms 16200 KB Output is correct
8 Correct 224 ms 16136 KB Output is correct
9 Correct 218 ms 16168 KB Output is correct
10 Correct 136 ms 9772 KB Output is correct
11 Correct 127 ms 9840 KB Output is correct
12 Correct 49 ms 3388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 239 ms 16128 KB Output is correct
2 Correct 256 ms 16160 KB Output is correct
3 Correct 234 ms 16148 KB Output is correct
4 Correct 162 ms 9932 KB Output is correct
5 Correct 136 ms 9940 KB Output is correct
6 Correct 58 ms 3764 KB Output is correct
7 Correct 229 ms 16200 KB Output is correct
8 Correct 224 ms 16136 KB Output is correct
9 Correct 218 ms 16168 KB Output is correct
10 Correct 136 ms 9772 KB Output is correct
11 Correct 127 ms 9840 KB Output is correct
12 Correct 49 ms 3388 KB Output is correct
13 Correct 287 ms 16140 KB Output is correct
14 Correct 250 ms 16164 KB Output is correct
15 Correct 284 ms 16228 KB Output is correct
16 Correct 131 ms 9960 KB Output is correct
17 Correct 133 ms 9964 KB Output is correct
18 Correct 65 ms 3768 KB Output is correct
19 Correct 286 ms 16128 KB Output is correct
20 Correct 251 ms 16148 KB Output is correct
21 Correct 255 ms 16180 KB Output is correct
22 Correct 128 ms 9816 KB Output is correct
23 Correct 126 ms 9748 KB Output is correct
24 Correct 48 ms 3376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 216 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 6 ms 1100 KB Output is correct
8 Correct 6 ms 1028 KB Output is correct
9 Correct 6 ms 1108 KB Output is correct
10 Correct 4 ms 724 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 6 ms 1008 KB Output is correct
14 Correct 5 ms 1112 KB Output is correct
15 Correct 5 ms 1108 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 4 ms 724 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 239 ms 16128 KB Output is correct
20 Correct 256 ms 16160 KB Output is correct
21 Correct 234 ms 16148 KB Output is correct
22 Correct 162 ms 9932 KB Output is correct
23 Correct 136 ms 9940 KB Output is correct
24 Correct 58 ms 3764 KB Output is correct
25 Correct 229 ms 16200 KB Output is correct
26 Correct 224 ms 16136 KB Output is correct
27 Correct 218 ms 16168 KB Output is correct
28 Correct 136 ms 9772 KB Output is correct
29 Correct 127 ms 9840 KB Output is correct
30 Correct 49 ms 3388 KB Output is correct
31 Correct 287 ms 16140 KB Output is correct
32 Correct 250 ms 16164 KB Output is correct
33 Correct 284 ms 16228 KB Output is correct
34 Correct 131 ms 9960 KB Output is correct
35 Correct 133 ms 9964 KB Output is correct
36 Correct 65 ms 3768 KB Output is correct
37 Correct 286 ms 16128 KB Output is correct
38 Correct 251 ms 16148 KB Output is correct
39 Correct 255 ms 16180 KB Output is correct
40 Correct 128 ms 9816 KB Output is correct
41 Correct 126 ms 9748 KB Output is correct
42 Correct 48 ms 3376 KB Output is correct
43 Correct 352 ms 23260 KB Output is correct
44 Correct 407 ms 23384 KB Output is correct
45 Correct 373 ms 23372 KB Output is correct
46 Correct 170 ms 13668 KB Output is correct
47 Correct 160 ms 13572 KB Output is correct
48 Correct 57 ms 3508 KB Output is correct
49 Correct 331 ms 23340 KB Output is correct
50 Correct 324 ms 23344 KB Output is correct
51 Correct 299 ms 23340 KB Output is correct
52 Correct 186 ms 13428 KB Output is correct
53 Correct 153 ms 13408 KB Output is correct