Submission #478205

# Submission time Handle Problem Language Result Execution time Memory
478205 2021-10-06T13:05:32 Z Karliver Examination (JOI19_examination) C++17
100 / 100
220 ms 12824 KB
    
#include <bits/stdc++.h>

#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace  std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
#define sz(x) (int)x.size()

using ll = long long;
int mod = (ll)1e9 + 7;
#define PI acos(-1)
typedef pair<int, int> pairs;

const int INF = 1e9 + 1;
const int N = 2e5 + 100;
const double eps = 1e-7;

template <class T> using V = vector<T>;  
template <class T> using VV = V<V<T>>;  
template<class T, size_t SZ> using AR = array<T, SZ>;
template<class T> using PR = pair<T, T>;
template <typename XPAX>
bool ckma(XPAX &x, XPAX y) {
    return (x < y ? x = y, 1 : 0);
}
template <typename XPAX>
bool ckmi(XPAX &x, XPAX y) {
    return (x > y ? x = y, 1 : 0);
}

struct FenwickTree {
    vector<int> bit;  // binary indexed tree
    int n;

    FenwickTree(int n) {
        this->n = n;
        bit.assign(n, 0);
    }

    FenwickTree(vector<int> a) : FenwickTree(a.size()) {
        for (size_t i = 0; i < a.size(); i++)
            add(i, a[i]);
    }

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

    int sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }

    void add(int idx, int delta) {
        for (; idx < n; idx = idx | (idx + 1))
            bit[idx] += delta;
    }
};
int A[N], B[N], C[N], S[N], T[N];
V<int> GX, GY;
V<PR<int>> sm;
int n, q;
void solve() {

    cin >> n >> q;

    for(int i = 1;i <= n;++i) {
        cin >> S[i] >> T[i];
        GX.push_back(S[i]);
        GY.push_back(T[i]);
    }

    for(int i = 1;i <= q;++i) {
        cin >> A[i] >> B[i] >> C[i];

        ckma(C[i], A[i] + B[i]);

        GX.push_back(A[i]);
        GY.push_back(B[i]);
    }

    sort(all(GX));
    sort(all(GY));

    GX.erase(unique(all(GX)), GX.end());
    GY.erase(unique(all(GY)), GY.end());
    
    FenwickTree F1(sz(GX) + 2), F2(sz(GY) + 2);

    for(int i = 1;i <= n;++i) sm.push_back({S[i] + T[i], i});

    for(int i = 1;i <= q;++i) sm.push_back({C[i], -i});

    sort(all(sm));
    
    reverse(all(sm));
    int tot = 0;

    V<int> ret(q + 1);
    for(auto &[item, id] : sm) {
        if(id > 0) {
            int p1 = lower_bound(all(GX), S[id]) - GX.begin();
            int p2 = lower_bound(all(GY), T[id]) - GY.begin();

            F1.add(p1, 1);
            F2.add(p2, 1);
            ++tot;
        }
        else {
            id = -id;

            ret[id] = tot;
            int p1 = lower_bound(all(GX), A[id]) - GX.begin();
            int p2 = lower_bound(all(GY), B[id]) - GY.begin();
            ret[id] -= F1.sum(p1 - 1);
            ret[id] -= F2.sum(p2 - 1);
        }
    }

    for(int i = 1;i <= q;++i) cout << ret[i] << ' ';





}
void test_case() {
    int t;
    cin >> t;
    forn(p, t) {

        //cout << "Case #" << p + 1 << ": ";
        solve();
    }
}
int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 5 ms 716 KB Output is correct
8 Correct 6 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 4 ms 668 KB Output is correct
11 Correct 4 ms 716 KB Output is correct
12 Correct 5 ms 588 KB Output is correct
13 Correct 6 ms 716 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 5 ms 700 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 4 ms 636 KB Output is correct
18 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 193 ms 9544 KB Output is correct
2 Correct 196 ms 9512 KB Output is correct
3 Correct 175 ms 9520 KB Output is correct
4 Correct 119 ms 8388 KB Output is correct
5 Correct 127 ms 8488 KB Output is correct
6 Correct 94 ms 7332 KB Output is correct
7 Correct 172 ms 9328 KB Output is correct
8 Correct 175 ms 9336 KB Output is correct
9 Correct 162 ms 9248 KB Output is correct
10 Correct 113 ms 8236 KB Output is correct
11 Correct 125 ms 8296 KB Output is correct
12 Correct 72 ms 7012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 193 ms 9544 KB Output is correct
2 Correct 196 ms 9512 KB Output is correct
3 Correct 175 ms 9520 KB Output is correct
4 Correct 119 ms 8388 KB Output is correct
5 Correct 127 ms 8488 KB Output is correct
6 Correct 94 ms 7332 KB Output is correct
7 Correct 172 ms 9328 KB Output is correct
8 Correct 175 ms 9336 KB Output is correct
9 Correct 162 ms 9248 KB Output is correct
10 Correct 113 ms 8236 KB Output is correct
11 Correct 125 ms 8296 KB Output is correct
12 Correct 72 ms 7012 KB Output is correct
13 Correct 183 ms 9944 KB Output is correct
14 Correct 209 ms 9888 KB Output is correct
15 Correct 183 ms 9508 KB Output is correct
16 Correct 127 ms 8812 KB Output is correct
17 Correct 134 ms 8752 KB Output is correct
18 Correct 86 ms 7348 KB Output is correct
19 Correct 191 ms 10020 KB Output is correct
20 Correct 188 ms 9900 KB Output is correct
21 Correct 190 ms 9864 KB Output is correct
22 Correct 116 ms 8196 KB Output is correct
23 Correct 108 ms 8192 KB Output is correct
24 Correct 76 ms 6968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 5 ms 716 KB Output is correct
8 Correct 6 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 4 ms 668 KB Output is correct
11 Correct 4 ms 716 KB Output is correct
12 Correct 5 ms 588 KB Output is correct
13 Correct 6 ms 716 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 5 ms 700 KB Output is correct
16 Correct 3 ms 588 KB Output is correct
17 Correct 4 ms 636 KB Output is correct
18 Correct 2 ms 588 KB Output is correct
19 Correct 193 ms 9544 KB Output is correct
20 Correct 196 ms 9512 KB Output is correct
21 Correct 175 ms 9520 KB Output is correct
22 Correct 119 ms 8388 KB Output is correct
23 Correct 127 ms 8488 KB Output is correct
24 Correct 94 ms 7332 KB Output is correct
25 Correct 172 ms 9328 KB Output is correct
26 Correct 175 ms 9336 KB Output is correct
27 Correct 162 ms 9248 KB Output is correct
28 Correct 113 ms 8236 KB Output is correct
29 Correct 125 ms 8296 KB Output is correct
30 Correct 72 ms 7012 KB Output is correct
31 Correct 183 ms 9944 KB Output is correct
32 Correct 209 ms 9888 KB Output is correct
33 Correct 183 ms 9508 KB Output is correct
34 Correct 127 ms 8812 KB Output is correct
35 Correct 134 ms 8752 KB Output is correct
36 Correct 86 ms 7348 KB Output is correct
37 Correct 191 ms 10020 KB Output is correct
38 Correct 188 ms 9900 KB Output is correct
39 Correct 190 ms 9864 KB Output is correct
40 Correct 116 ms 8196 KB Output is correct
41 Correct 108 ms 8192 KB Output is correct
42 Correct 76 ms 6968 KB Output is correct
43 Correct 217 ms 12824 KB Output is correct
44 Correct 206 ms 12696 KB Output is correct
45 Correct 210 ms 12708 KB Output is correct
46 Correct 140 ms 10436 KB Output is correct
47 Correct 140 ms 10408 KB Output is correct
48 Correct 87 ms 7208 KB Output is correct
49 Correct 202 ms 12704 KB Output is correct
50 Correct 220 ms 12692 KB Output is correct
51 Correct 198 ms 12576 KB Output is correct
52 Correct 123 ms 10264 KB Output is correct
53 Correct 150 ms 9508 KB Output is correct