Submission #684905

# Submission time Handle Problem Language Result Execution time Memory
684905 2023-01-22T19:28:39 Z izanbf Examination (JOI19_examination) C++14
100 / 100
377 ms 23188 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define endl "\n"
//~ #define int long long
 
typedef long long int ll;
 
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 segTree {
    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 <= n; r += r&-r)
            bit[r] += delta;
    }

    void set(int r, int x) {
        add(r+1, x);
    }
};

 
 
void solve(){
    int n, q; cin >> n >> q;
    vector<pair<int, int>> v(n);
    set<int> sa;
    set<int> 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;
    map<int, int> b;
    int curr = 1;
    for(auto x : sa){
        a[x] = curr;
        curr++;
    }
    segTree sta; sta.init(curr);
    int sza = curr;
    curr = 1;
    for(auto x : sb){
        b[x] = curr;
        curr++;
    }
    segTree 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.set(a[v[curr].first], 1);
            stb.set(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 << endl;
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    //freopen("inpt.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    //~ int tt; cin >> tt;
    int tt = 1;
    for(int t = 1; t <= tt; t++){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 976 KB Output is correct
8 Correct 5 ms 980 KB Output is correct
9 Correct 7 ms 980 KB Output is correct
10 Correct 4 ms 684 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 5 ms 980 KB Output is correct
14 Correct 6 ms 980 KB Output is correct
15 Correct 6 ms 928 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 15924 KB Output is correct
2 Correct 276 ms 15860 KB Output is correct
3 Correct 285 ms 15988 KB Output is correct
4 Correct 130 ms 9780 KB Output is correct
5 Correct 149 ms 9812 KB Output is correct
6 Correct 57 ms 3568 KB Output is correct
7 Correct 242 ms 15908 KB Output is correct
8 Correct 261 ms 15924 KB Output is correct
9 Correct 214 ms 15912 KB Output is correct
10 Correct 132 ms 9628 KB Output is correct
11 Correct 143 ms 9628 KB Output is correct
12 Correct 46 ms 3296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 15924 KB Output is correct
2 Correct 276 ms 15860 KB Output is correct
3 Correct 285 ms 15988 KB Output is correct
4 Correct 130 ms 9780 KB Output is correct
5 Correct 149 ms 9812 KB Output is correct
6 Correct 57 ms 3568 KB Output is correct
7 Correct 242 ms 15908 KB Output is correct
8 Correct 261 ms 15924 KB Output is correct
9 Correct 214 ms 15912 KB Output is correct
10 Correct 132 ms 9628 KB Output is correct
11 Correct 143 ms 9628 KB Output is correct
12 Correct 46 ms 3296 KB Output is correct
13 Correct 251 ms 15864 KB Output is correct
14 Correct 279 ms 15924 KB Output is correct
15 Correct 238 ms 15932 KB Output is correct
16 Correct 148 ms 9824 KB Output is correct
17 Correct 142 ms 9676 KB Output is correct
18 Correct 56 ms 3568 KB Output is correct
19 Correct 287 ms 16044 KB Output is correct
20 Correct 261 ms 15956 KB Output is correct
21 Correct 276 ms 15952 KB Output is correct
22 Correct 142 ms 9604 KB Output is correct
23 Correct 127 ms 9612 KB Output is correct
24 Correct 45 ms 3280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 976 KB Output is correct
8 Correct 5 ms 980 KB Output is correct
9 Correct 7 ms 980 KB Output is correct
10 Correct 4 ms 684 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 5 ms 980 KB Output is correct
14 Correct 6 ms 980 KB Output is correct
15 Correct 6 ms 928 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 240 ms 15924 KB Output is correct
20 Correct 276 ms 15860 KB Output is correct
21 Correct 285 ms 15988 KB Output is correct
22 Correct 130 ms 9780 KB Output is correct
23 Correct 149 ms 9812 KB Output is correct
24 Correct 57 ms 3568 KB Output is correct
25 Correct 242 ms 15908 KB Output is correct
26 Correct 261 ms 15924 KB Output is correct
27 Correct 214 ms 15912 KB Output is correct
28 Correct 132 ms 9628 KB Output is correct
29 Correct 143 ms 9628 KB Output is correct
30 Correct 46 ms 3296 KB Output is correct
31 Correct 251 ms 15864 KB Output is correct
32 Correct 279 ms 15924 KB Output is correct
33 Correct 238 ms 15932 KB Output is correct
34 Correct 148 ms 9824 KB Output is correct
35 Correct 142 ms 9676 KB Output is correct
36 Correct 56 ms 3568 KB Output is correct
37 Correct 287 ms 16044 KB Output is correct
38 Correct 261 ms 15956 KB Output is correct
39 Correct 276 ms 15952 KB Output is correct
40 Correct 142 ms 9604 KB Output is correct
41 Correct 127 ms 9612 KB Output is correct
42 Correct 45 ms 3280 KB Output is correct
43 Correct 377 ms 23128 KB Output is correct
44 Correct 358 ms 23136 KB Output is correct
45 Correct 344 ms 23140 KB Output is correct
46 Correct 158 ms 13356 KB Output is correct
47 Correct 160 ms 13388 KB Output is correct
48 Correct 69 ms 3400 KB Output is correct
49 Correct 335 ms 23164 KB Output is correct
50 Correct 324 ms 23136 KB Output is correct
51 Correct 318 ms 23188 KB Output is correct
52 Correct 161 ms 13132 KB Output is correct
53 Correct 163 ms 13220 KB Output is correct