Submission #636588

# Submission time Handle Problem Language Result Execution time Memory
636588 2022-08-29T16:08:44 Z Ronin13 Examination (JOI19_examination) C++14
100 / 100
412 ms 49512 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int NMAX = 1e5 + 1;
int a[NMAX], b[NMAX];
vector <vector <int> > t[2];

void build(int v, int l, int r){
    if(l == r){
        t[0][v].pb(a[l]);
        t[1][v].pb(b[l]);
        return;
    }
    int m = (l + r) / 2;
    build(2 * v, l, m);
    build(2 * v + 1, m + 1, r);
    for(int i = 0; i < 2; i++){
        t[i][v].resize(t[i][2 * v].size() + t[i][2 * v + 1].size());
        merge(t[i][2 * v].begin(), t[i][2 * v].end(), t[i][2 * v + 1].begin(), t[i][2 * v + 1].end(), t[i][v].begin());
    }
}

int get(int v, int l, int r, int st, int fin, int ind, int val){
    if(l > fin || r < st) return 0;
    if(l >= st && r <= fin){
        return (int)(t[ind][v].end() - lower_bound(t[ind][v].begin(), t[ind][v].end(), val));
    }
    int m = (l + r) / 2;
    return get(2 * v, l, m, st, fin, ind, val) + get(2 * v + 1, m + 1, r, st, fin, ind, val);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, q; cin >> n >> q;
    vector <pii> vec;
    vector <int> vv;
    for(int i = 1; i <= n; i++){
        int x, y; cin >> x >> y;
        vec.pb({x, y});
        vv.pb(x);
    }
    sort(vec.begin(), vec.end());
    sort(vv.begin(), vv.end());
    for(int i = 0; i < vec.size(); i++){
        a[i + 1] = vec[i].s;
        b[i + 1] = vec[i].s + vec[i].f;
    }
    t[0].resize(4 * n + 1);
    t[1].resize(4 * n + 1);
    build(1, 1, n);
   // cout << 1;
    while(q--){
        int x, y, z; cin >> x >> y >> z;
        int ind = lower_bound(vv.begin(), vv.end(), x) - vv.begin();
        int ind1 = lower_bound(vv.begin(), vv.end(), z - y) - vv.begin();
        ind++;
        ind1++;
        ind1 = max(ind, ind1);
        //cout << ind << ' ' << ind1 << "\n";
        cout << get(1, 1, n, ind, ind1 - 1, 1, z) + get(1 ,1, n, ind1, n, 0, y) << "\n";
    }
    return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i = 0; i < vec.size(); i++){
      |                    ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 6 ms 1704 KB Output is correct
8 Correct 6 ms 1620 KB Output is correct
9 Correct 7 ms 1664 KB Output is correct
10 Correct 6 ms 1620 KB Output is correct
11 Correct 4 ms 1660 KB Output is correct
12 Correct 4 ms 1492 KB Output is correct
13 Correct 6 ms 1620 KB Output is correct
14 Correct 6 ms 1620 KB Output is correct
15 Correct 6 ms 1600 KB Output is correct
16 Correct 4 ms 1620 KB Output is correct
17 Correct 6 ms 1628 KB Output is correct
18 Correct 3 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 261 ms 47108 KB Output is correct
2 Correct 295 ms 47196 KB Output is correct
3 Correct 281 ms 47044 KB Output is correct
4 Correct 238 ms 46440 KB Output is correct
5 Correct 177 ms 46336 KB Output is correct
6 Correct 155 ms 45696 KB Output is correct
7 Correct 262 ms 46996 KB Output is correct
8 Correct 238 ms 46976 KB Output is correct
9 Correct 251 ms 46936 KB Output is correct
10 Correct 117 ms 46104 KB Output is correct
11 Correct 195 ms 46120 KB Output is correct
12 Correct 101 ms 45300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 261 ms 47108 KB Output is correct
2 Correct 295 ms 47196 KB Output is correct
3 Correct 281 ms 47044 KB Output is correct
4 Correct 238 ms 46440 KB Output is correct
5 Correct 177 ms 46336 KB Output is correct
6 Correct 155 ms 45696 KB Output is correct
7 Correct 262 ms 46996 KB Output is correct
8 Correct 238 ms 46976 KB Output is correct
9 Correct 251 ms 46936 KB Output is correct
10 Correct 117 ms 46104 KB Output is correct
11 Correct 195 ms 46120 KB Output is correct
12 Correct 101 ms 45300 KB Output is correct
13 Correct 331 ms 47548 KB Output is correct
14 Correct 312 ms 47476 KB Output is correct
15 Correct 287 ms 47168 KB Output is correct
16 Correct 307 ms 46692 KB Output is correct
17 Correct 172 ms 46648 KB Output is correct
18 Correct 168 ms 45620 KB Output is correct
19 Correct 366 ms 47440 KB Output is correct
20 Correct 335 ms 47544 KB Output is correct
21 Correct 329 ms 47456 KB Output is correct
22 Correct 114 ms 46188 KB Output is correct
23 Correct 193 ms 46164 KB Output is correct
24 Correct 97 ms 45248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 328 KB Output is correct
7 Correct 6 ms 1704 KB Output is correct
8 Correct 6 ms 1620 KB Output is correct
9 Correct 7 ms 1664 KB Output is correct
10 Correct 6 ms 1620 KB Output is correct
11 Correct 4 ms 1660 KB Output is correct
12 Correct 4 ms 1492 KB Output is correct
13 Correct 6 ms 1620 KB Output is correct
14 Correct 6 ms 1620 KB Output is correct
15 Correct 6 ms 1600 KB Output is correct
16 Correct 4 ms 1620 KB Output is correct
17 Correct 6 ms 1628 KB Output is correct
18 Correct 3 ms 1492 KB Output is correct
19 Correct 261 ms 47108 KB Output is correct
20 Correct 295 ms 47196 KB Output is correct
21 Correct 281 ms 47044 KB Output is correct
22 Correct 238 ms 46440 KB Output is correct
23 Correct 177 ms 46336 KB Output is correct
24 Correct 155 ms 45696 KB Output is correct
25 Correct 262 ms 46996 KB Output is correct
26 Correct 238 ms 46976 KB Output is correct
27 Correct 251 ms 46936 KB Output is correct
28 Correct 117 ms 46104 KB Output is correct
29 Correct 195 ms 46120 KB Output is correct
30 Correct 101 ms 45300 KB Output is correct
31 Correct 331 ms 47548 KB Output is correct
32 Correct 312 ms 47476 KB Output is correct
33 Correct 287 ms 47168 KB Output is correct
34 Correct 307 ms 46692 KB Output is correct
35 Correct 172 ms 46648 KB Output is correct
36 Correct 168 ms 45620 KB Output is correct
37 Correct 366 ms 47440 KB Output is correct
38 Correct 335 ms 47544 KB Output is correct
39 Correct 329 ms 47456 KB Output is correct
40 Correct 114 ms 46188 KB Output is correct
41 Correct 193 ms 46164 KB Output is correct
42 Correct 97 ms 45248 KB Output is correct
43 Correct 342 ms 49456 KB Output is correct
44 Correct 330 ms 49512 KB Output is correct
45 Correct 317 ms 49448 KB Output is correct
46 Correct 337 ms 47908 KB Output is correct
47 Correct 184 ms 47796 KB Output is correct
48 Correct 151 ms 45384 KB Output is correct
49 Correct 359 ms 49260 KB Output is correct
50 Correct 342 ms 49396 KB Output is correct
51 Correct 412 ms 49216 KB Output is correct
52 Correct 128 ms 47684 KB Output is correct
53 Correct 199 ms 46976 KB Output is correct