Submission #267078

# Submission time Handle Problem Language Result Execution time Memory
267078 2020-08-15T19:18:24 Z keko37 Examination (JOI19_examination) C++14
100 / 100
491 ms 120404 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long llint;
typedef pair <int, int> pi;

const int MAXN = 100005;
const int SIZ = 600005;

int n, q;
int x[MAXN], y[MAXN], z[MAXN], a[MAXN], b[MAXN], c[MAXN], ez[MAXN], sol[MAXN];
int fen[SIZ], pa[SIZ], pb[SIZ], pc[SIZ];
vector <int> saz, v[SIZ][3];
vector <pi> u[SIZ][3];

void ubaci (int x, int k) {
    for (; x < SIZ; x += x&-x) fen[x] += k;
}

int upit (int x) {
    int res = 0;
    for (; x > 0; x -= x&-x) res += fen[x];
    return res;
}

void sazmi () {
    sort(saz.begin(), saz.end());
    saz.erase(unique(saz.begin(), saz.end()), saz.end());
    for (int i = 1; i <= n; i++) {
        x[i] = lower_bound(saz.begin(), saz.end(), x[i]) - saz.begin() + 1;
        y[i] = lower_bound(saz.begin(), saz.end(), y[i]) - saz.begin() + 1;
        z[i] = lower_bound(saz.begin(), saz.end(), z[i]) - saz.begin() + 1;
    }
    for (int i = 1; i <= q; i++) {
        a[i] = lower_bound(saz.begin(), saz.end(), a[i]) - saz.begin() + 1;
        b[i] = lower_bound(saz.begin(), saz.end(), b[i]) - saz.begin() + 1;
        c[i] = lower_bound(saz.begin(), saz.end(), c[i]) - saz.begin() + 1;
    }
}

void init () {
    for (int i = 1; i <= n; i++) {
        v[x[i]][0].push_back(y[i]);
        v[x[i]][1].push_back(z[i]);
        v[y[i]][2].push_back(z[i]);
        pa[x[i]]++; pb[y[i]]++; pc[z[i]]++;
    }
    for (int i = 1; i < SIZ; i++) {
        pa[i] += pa[i - 1];
        pb[i] += pb[i - 1];
        pc[i] += pc[i - 1];
    }
    for (int i = 1; i <= q; i++) {
        if (ez[i]) u[a[i]][0].push_back({b[i], i});
        if (!ez[i]) u[a[i]][1].push_back({c[i], i});
        if (!ez[i]) u[b[i]][2].push_back({c[i], i});
        sol[i] -= pa[a[i] - 1];
        sol[i] -= pb[b[i] - 1];
        if (!ez[i]) sol[i] -= pc[c[i] - 1];
    }
}

void sweep (int tip) {
    memset(fen, 0, sizeof fen);
    for (int i = 1; i < SIZ; i++) {
        for (auto e : u[i][tip]) {
            int val = e.first, ind = e.second;
            sol[ind] += upit(val - 1);
        }
        for (auto val : v[i][tip]) {
            ubaci(val, 1);
        }
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
        z[i] = x[i] + y[i];
        saz.push_back(x[i]); saz.push_back(y[i]); saz.push_back(z[i]);
    }
    for (int i = 1; i <= q; i++) {
        cin >> a[i] >> b[i] >> c[i];
        ez[i] = c[i] <= a[i] + b[i];
        sol[i] = n;
        saz.push_back(a[i]); saz.push_back(b[i]); saz.push_back(c[i]);
    }
    sazmi();
    init();
    for (int i = 0; i < 3; i++) sweep(i);
    for (int i = 1; i <= q; i++) {
        cout << sol[i] << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 75 ms 94328 KB Output is correct
2 Correct 79 ms 94328 KB Output is correct
3 Correct 74 ms 94328 KB Output is correct
4 Correct 74 ms 94328 KB Output is correct
5 Correct 75 ms 94328 KB Output is correct
6 Correct 74 ms 94328 KB Output is correct
7 Correct 82 ms 95096 KB Output is correct
8 Correct 84 ms 95108 KB Output is correct
9 Correct 83 ms 95100 KB Output is correct
10 Correct 81 ms 94968 KB Output is correct
11 Correct 80 ms 94844 KB Output is correct
12 Correct 76 ms 94712 KB Output is correct
13 Correct 81 ms 95096 KB Output is correct
14 Correct 81 ms 94988 KB Output is correct
15 Correct 81 ms 94968 KB Output is correct
16 Correct 81 ms 94712 KB Output is correct
17 Correct 81 ms 94968 KB Output is correct
18 Correct 77 ms 94640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 361 ms 111072 KB Output is correct
2 Correct 348 ms 110944 KB Output is correct
3 Correct 352 ms 110944 KB Output is correct
4 Correct 289 ms 108700 KB Output is correct
5 Correct 250 ms 106556 KB Output is correct
6 Correct 168 ms 104652 KB Output is correct
7 Correct 335 ms 110176 KB Output is correct
8 Correct 354 ms 110816 KB Output is correct
9 Correct 330 ms 110176 KB Output is correct
10 Correct 239 ms 106204 KB Output is correct
11 Correct 304 ms 108388 KB Output is correct
12 Correct 158 ms 103656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 361 ms 111072 KB Output is correct
2 Correct 348 ms 110944 KB Output is correct
3 Correct 352 ms 110944 KB Output is correct
4 Correct 289 ms 108700 KB Output is correct
5 Correct 250 ms 106556 KB Output is correct
6 Correct 168 ms 104652 KB Output is correct
7 Correct 335 ms 110176 KB Output is correct
8 Correct 354 ms 110816 KB Output is correct
9 Correct 330 ms 110176 KB Output is correct
10 Correct 239 ms 106204 KB Output is correct
11 Correct 304 ms 108388 KB Output is correct
12 Correct 158 ms 103656 KB Output is correct
13 Correct 394 ms 112980 KB Output is correct
14 Correct 379 ms 112096 KB Output is correct
15 Correct 351 ms 110944 KB Output is correct
16 Correct 311 ms 110048 KB Output is correct
17 Correct 279 ms 108000 KB Output is correct
18 Correct 175 ms 104416 KB Output is correct
19 Correct 391 ms 112864 KB Output is correct
20 Correct 387 ms 112608 KB Output is correct
21 Correct 389 ms 112608 KB Output is correct
22 Correct 241 ms 106468 KB Output is correct
23 Correct 274 ms 108388 KB Output is correct
24 Correct 155 ms 103520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 94328 KB Output is correct
2 Correct 79 ms 94328 KB Output is correct
3 Correct 74 ms 94328 KB Output is correct
4 Correct 74 ms 94328 KB Output is correct
5 Correct 75 ms 94328 KB Output is correct
6 Correct 74 ms 94328 KB Output is correct
7 Correct 82 ms 95096 KB Output is correct
8 Correct 84 ms 95108 KB Output is correct
9 Correct 83 ms 95100 KB Output is correct
10 Correct 81 ms 94968 KB Output is correct
11 Correct 80 ms 94844 KB Output is correct
12 Correct 76 ms 94712 KB Output is correct
13 Correct 81 ms 95096 KB Output is correct
14 Correct 81 ms 94988 KB Output is correct
15 Correct 81 ms 94968 KB Output is correct
16 Correct 81 ms 94712 KB Output is correct
17 Correct 81 ms 94968 KB Output is correct
18 Correct 77 ms 94640 KB Output is correct
19 Correct 361 ms 111072 KB Output is correct
20 Correct 348 ms 110944 KB Output is correct
21 Correct 352 ms 110944 KB Output is correct
22 Correct 289 ms 108700 KB Output is correct
23 Correct 250 ms 106556 KB Output is correct
24 Correct 168 ms 104652 KB Output is correct
25 Correct 335 ms 110176 KB Output is correct
26 Correct 354 ms 110816 KB Output is correct
27 Correct 330 ms 110176 KB Output is correct
28 Correct 239 ms 106204 KB Output is correct
29 Correct 304 ms 108388 KB Output is correct
30 Correct 158 ms 103656 KB Output is correct
31 Correct 394 ms 112980 KB Output is correct
32 Correct 379 ms 112096 KB Output is correct
33 Correct 351 ms 110944 KB Output is correct
34 Correct 311 ms 110048 KB Output is correct
35 Correct 279 ms 108000 KB Output is correct
36 Correct 175 ms 104416 KB Output is correct
37 Correct 391 ms 112864 KB Output is correct
38 Correct 387 ms 112608 KB Output is correct
39 Correct 389 ms 112608 KB Output is correct
40 Correct 241 ms 106468 KB Output is correct
41 Correct 274 ms 108388 KB Output is correct
42 Correct 155 ms 103520 KB Output is correct
43 Correct 490 ms 119400 KB Output is correct
44 Correct 491 ms 119396 KB Output is correct
45 Correct 466 ms 118240 KB Output is correct
46 Correct 362 ms 114016 KB Output is correct
47 Correct 318 ms 110432 KB Output is correct
48 Correct 193 ms 104544 KB Output is correct
49 Correct 473 ms 119136 KB Output is correct
50 Correct 488 ms 119900 KB Output is correct
51 Correct 485 ms 120404 KB Output is correct
52 Correct 322 ms 109792 KB Output is correct
53 Correct 315 ms 112880 KB Output is correct