답안 #874447

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874447 2023-11-17T04:07:36 Z Requiem Examination (JOI19_examination) C++17
100 / 100
2472 ms 231160 KB
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef int ll;
typedef long double ld;
typedef pair<ll, ll> pl;

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = (l); i < r; ++i)

#define NN 100010
#define M 1000000007 // 998244353

//GCC extensions
#include <bits/extc++.h>
using namespace __gnu_cxx;
using namespace __gnu_pbds;

struct query_multiset {
    // multiset that keeps track of things above you (basically oset)
    map<ll, ll> cnts;

    // order stats tree
    // find_by_order(i) returns ptr
    // order_of_key(key) return int
    typedef tree<pl, null_type, less<pl>,
    rb_tree_tag, tree_order_statistics_node_update> set_t;

    set_t oset;

    void insert(ll i) {
        oset.insert(pl{i, ++cnts[i]});
    }

    // returns how many elements >= i
    ll query(ll i) {
        return oset.size() - oset.order_of_key(pl{i, -1});
    }
};

namespace mstree {
    query_multiset t[2 * NN];
    vector<ll> items;
    ll n;

    ll f(ll i, ll k) {

        // cout << "Im querying " << k << ": " << t[i].query(k) << endl;
        // for (const auto &[k, v]: t[i].cnts) cout << k << ", " << v << endl;

        return t[i].query(k);
    }
    void init() {
        sort(A(items));
        items.erase(unique(A(items)), items.end());
        n = items.size();
    }

    void add(ll a, ll b) {
        // A should always be in items
        ll idx = lower_bound(A(items), a) - items.begin();

        idx += n;
        for (t[idx].insert(b); idx/=2;) t[idx].insert(b);
    }

    ll i_query(ll l, ll r, ll k) { //num elements < k in interval [l, r)
        ll res = 0;
        for(l += n, r += n; l < r; l /= 2, r /= 2) {
            if(l & 1) res += f(l++, k);
            if(r & 1) res += f(--r, k);
        }
        return res;
    }

    ll query(ll a, ll b) {
        // a isn't necessarily guranteed to be in items
        ll suff = ll(lower_bound(A(items), a) - items.begin());

        // cout << "query " << a << " " << b << endl;
        // for (auto x: items) cout << x << " " ; cout << endl;
        // cout << suff << ", " << a << endl;

        return i_query(suff, n, b);
    }

}

int main(){
  

    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(20);
    G(n) G(qn)
    vector<pair<ll, array<ll, 3>>> q;
    vector<pl> students;
    F(i, 0, n) {
        G(x) G(y) students.emplace_back(x, y); mstree::items.push_back(x);
    }
    mstree::init();
    sort(A(students), [](const auto &a, const auto &b) {
        return a.K + a.V > b.K + b.V;
    });

    F(i, 0, qn) {
        array<ll, 3> arr; F(i, 0, 3) cin >> arr[i];
        q.emplace_back(i, arr);
    }
    vector<ll> ans(qn);
    sort(A(q), [](const auto &a, const auto &b) {
        return a.V[2] > b.V[2];
    });

    ll fp = 0;
    for (const auto &[qidx, qarr]: q) {
        auto &[a, b, c] = qarr;
        while (fp < n && students[fp].K + students[fp].V >= c) {
            mstree::add(students[fp].K, students[fp].V);
            fp++;
        }

        ans[qidx] = mstree::query(a, b);
    }

    for (auto x: ans) cout << x << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 28508 KB Output is correct
2 Correct 12 ms 28508 KB Output is correct
3 Correct 14 ms 28504 KB Output is correct
4 Correct 13 ms 28760 KB Output is correct
5 Correct 12 ms 28508 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 28 ms 32860 KB Output is correct
8 Correct 28 ms 32852 KB Output is correct
9 Correct 28 ms 32860 KB Output is correct
10 Correct 24 ms 31940 KB Output is correct
11 Correct 19 ms 30044 KB Output is correct
12 Correct 17 ms 29532 KB Output is correct
13 Correct 28 ms 32860 KB Output is correct
14 Correct 28 ms 32860 KB Output is correct
15 Correct 29 ms 32860 KB Output is correct
16 Correct 14 ms 29020 KB Output is correct
17 Correct 25 ms 31320 KB Output is correct
18 Correct 14 ms 28796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2267 ms 214436 KB Output is correct
2 Correct 2285 ms 214456 KB Output is correct
3 Correct 2257 ms 214396 KB Output is correct
4 Correct 1124 ms 157596 KB Output is correct
5 Correct 413 ms 78328 KB Output is correct
6 Correct 235 ms 60612 KB Output is correct
7 Correct 2087 ms 214360 KB Output is correct
8 Correct 2060 ms 217040 KB Output is correct
9 Correct 1897 ms 216684 KB Output is correct
10 Correct 114 ms 43080 KB Output is correct
11 Correct 792 ms 146136 KB Output is correct
12 Correct 128 ms 39180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2267 ms 214436 KB Output is correct
2 Correct 2285 ms 214456 KB Output is correct
3 Correct 2257 ms 214396 KB Output is correct
4 Correct 1124 ms 157596 KB Output is correct
5 Correct 413 ms 78328 KB Output is correct
6 Correct 235 ms 60612 KB Output is correct
7 Correct 2087 ms 214360 KB Output is correct
8 Correct 2060 ms 217040 KB Output is correct
9 Correct 1897 ms 216684 KB Output is correct
10 Correct 114 ms 43080 KB Output is correct
11 Correct 792 ms 146136 KB Output is correct
12 Correct 128 ms 39180 KB Output is correct
13 Correct 2227 ms 217124 KB Output is correct
14 Correct 2445 ms 217016 KB Output is correct
15 Correct 2339 ms 217068 KB Output is correct
16 Correct 1034 ms 159680 KB Output is correct
17 Correct 403 ms 80496 KB Output is correct
18 Correct 240 ms 61700 KB Output is correct
19 Correct 2193 ms 217524 KB Output is correct
20 Correct 2402 ms 217184 KB Output is correct
21 Correct 2055 ms 217396 KB Output is correct
22 Correct 96 ms 43104 KB Output is correct
23 Correct 799 ms 145844 KB Output is correct
24 Correct 126 ms 39280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 28508 KB Output is correct
2 Correct 12 ms 28508 KB Output is correct
3 Correct 14 ms 28504 KB Output is correct
4 Correct 13 ms 28760 KB Output is correct
5 Correct 12 ms 28508 KB Output is correct
6 Correct 12 ms 28508 KB Output is correct
7 Correct 28 ms 32860 KB Output is correct
8 Correct 28 ms 32852 KB Output is correct
9 Correct 28 ms 32860 KB Output is correct
10 Correct 24 ms 31940 KB Output is correct
11 Correct 19 ms 30044 KB Output is correct
12 Correct 17 ms 29532 KB Output is correct
13 Correct 28 ms 32860 KB Output is correct
14 Correct 28 ms 32860 KB Output is correct
15 Correct 29 ms 32860 KB Output is correct
16 Correct 14 ms 29020 KB Output is correct
17 Correct 25 ms 31320 KB Output is correct
18 Correct 14 ms 28796 KB Output is correct
19 Correct 2267 ms 214436 KB Output is correct
20 Correct 2285 ms 214456 KB Output is correct
21 Correct 2257 ms 214396 KB Output is correct
22 Correct 1124 ms 157596 KB Output is correct
23 Correct 413 ms 78328 KB Output is correct
24 Correct 235 ms 60612 KB Output is correct
25 Correct 2087 ms 214360 KB Output is correct
26 Correct 2060 ms 217040 KB Output is correct
27 Correct 1897 ms 216684 KB Output is correct
28 Correct 114 ms 43080 KB Output is correct
29 Correct 792 ms 146136 KB Output is correct
30 Correct 128 ms 39180 KB Output is correct
31 Correct 2227 ms 217124 KB Output is correct
32 Correct 2445 ms 217016 KB Output is correct
33 Correct 2339 ms 217068 KB Output is correct
34 Correct 1034 ms 159680 KB Output is correct
35 Correct 403 ms 80496 KB Output is correct
36 Correct 240 ms 61700 KB Output is correct
37 Correct 2193 ms 217524 KB Output is correct
38 Correct 2402 ms 217184 KB Output is correct
39 Correct 2055 ms 217396 KB Output is correct
40 Correct 96 ms 43104 KB Output is correct
41 Correct 799 ms 145844 KB Output is correct
42 Correct 126 ms 39280 KB Output is correct
43 Correct 2180 ms 230980 KB Output is correct
44 Correct 2173 ms 231160 KB Output is correct
45 Correct 2472 ms 230932 KB Output is correct
46 Correct 1106 ms 168676 KB Output is correct
47 Correct 458 ms 85336 KB Output is correct
48 Correct 232 ms 61524 KB Output is correct
49 Correct 2175 ms 230748 KB Output is correct
50 Correct 1994 ms 231060 KB Output is correct
51 Correct 1928 ms 230852 KB Output is correct
52 Correct 125 ms 46276 KB Output is correct
53 Correct 844 ms 154744 KB Output is correct