답안 #873281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873281 2023-11-14T18:21:31 Z bobbilyking Examination (JOI19_examination) C++17
100 / 100
2343 ms 231192 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(){
//    freopen("a.in", "r", stdin);
//    freopen("a.out", "w", stdout);

    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 12 ms 28508 KB Output is correct
2 Correct 12 ms 28508 KB Output is correct
3 Correct 12 ms 28656 KB Output is correct
4 Correct 12 ms 28648 KB Output is correct
5 Correct 12 ms 28508 KB Output is correct
6 Correct 12 ms 28648 KB Output is correct
7 Correct 28 ms 32848 KB Output is correct
8 Correct 28 ms 32852 KB Output is correct
9 Correct 27 ms 32804 KB Output is correct
10 Correct 30 ms 31828 KB Output is correct
11 Correct 23 ms 30300 KB Output is correct
12 Correct 16 ms 29532 KB Output is correct
13 Correct 28 ms 32848 KB Output is correct
14 Correct 28 ms 33020 KB Output is correct
15 Correct 34 ms 32860 KB Output is correct
16 Correct 15 ms 29016 KB Output is correct
17 Correct 21 ms 31392 KB Output is correct
18 Correct 13 ms 28760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2211 ms 214544 KB Output is correct
2 Correct 2167 ms 216792 KB Output is correct
3 Correct 2242 ms 216664 KB Output is correct
4 Correct 1099 ms 159236 KB Output is correct
5 Correct 431 ms 80084 KB Output is correct
6 Correct 240 ms 61632 KB Output is correct
7 Correct 2009 ms 216628 KB Output is correct
8 Correct 1955 ms 216764 KB Output is correct
9 Correct 1762 ms 216508 KB Output is correct
10 Correct 100 ms 42936 KB Output is correct
11 Correct 755 ms 146028 KB Output is correct
12 Correct 134 ms 39288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2211 ms 214544 KB Output is correct
2 Correct 2167 ms 216792 KB Output is correct
3 Correct 2242 ms 216664 KB Output is correct
4 Correct 1099 ms 159236 KB Output is correct
5 Correct 431 ms 80084 KB Output is correct
6 Correct 240 ms 61632 KB Output is correct
7 Correct 2009 ms 216628 KB Output is correct
8 Correct 1955 ms 216764 KB Output is correct
9 Correct 1762 ms 216508 KB Output is correct
10 Correct 100 ms 42936 KB Output is correct
11 Correct 755 ms 146028 KB Output is correct
12 Correct 134 ms 39288 KB Output is correct
13 Correct 2103 ms 217296 KB Output is correct
14 Correct 2336 ms 217048 KB Output is correct
15 Correct 2186 ms 216816 KB Output is correct
16 Correct 1004 ms 159936 KB Output is correct
17 Correct 387 ms 80324 KB Output is correct
18 Correct 236 ms 61636 KB Output is correct
19 Correct 2020 ms 217196 KB Output is correct
20 Correct 2240 ms 217464 KB Output is correct
21 Correct 1903 ms 217336 KB Output is correct
22 Correct 93 ms 42940 KB Output is correct
23 Correct 742 ms 145908 KB Output is correct
24 Correct 131 ms 39028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 28508 KB Output is correct
2 Correct 12 ms 28508 KB Output is correct
3 Correct 12 ms 28656 KB Output is correct
4 Correct 12 ms 28648 KB Output is correct
5 Correct 12 ms 28508 KB Output is correct
6 Correct 12 ms 28648 KB Output is correct
7 Correct 28 ms 32848 KB Output is correct
8 Correct 28 ms 32852 KB Output is correct
9 Correct 27 ms 32804 KB Output is correct
10 Correct 30 ms 31828 KB Output is correct
11 Correct 23 ms 30300 KB Output is correct
12 Correct 16 ms 29532 KB Output is correct
13 Correct 28 ms 32848 KB Output is correct
14 Correct 28 ms 33020 KB Output is correct
15 Correct 34 ms 32860 KB Output is correct
16 Correct 15 ms 29016 KB Output is correct
17 Correct 21 ms 31392 KB Output is correct
18 Correct 13 ms 28760 KB Output is correct
19 Correct 2211 ms 214544 KB Output is correct
20 Correct 2167 ms 216792 KB Output is correct
21 Correct 2242 ms 216664 KB Output is correct
22 Correct 1099 ms 159236 KB Output is correct
23 Correct 431 ms 80084 KB Output is correct
24 Correct 240 ms 61632 KB Output is correct
25 Correct 2009 ms 216628 KB Output is correct
26 Correct 1955 ms 216764 KB Output is correct
27 Correct 1762 ms 216508 KB Output is correct
28 Correct 100 ms 42936 KB Output is correct
29 Correct 755 ms 146028 KB Output is correct
30 Correct 134 ms 39288 KB Output is correct
31 Correct 2103 ms 217296 KB Output is correct
32 Correct 2336 ms 217048 KB Output is correct
33 Correct 2186 ms 216816 KB Output is correct
34 Correct 1004 ms 159936 KB Output is correct
35 Correct 387 ms 80324 KB Output is correct
36 Correct 236 ms 61636 KB Output is correct
37 Correct 2020 ms 217196 KB Output is correct
38 Correct 2240 ms 217464 KB Output is correct
39 Correct 1903 ms 217336 KB Output is correct
40 Correct 93 ms 42940 KB Output is correct
41 Correct 742 ms 145908 KB Output is correct
42 Correct 131 ms 39028 KB Output is correct
43 Correct 2097 ms 231000 KB Output is correct
44 Correct 2058 ms 230884 KB Output is correct
45 Correct 2343 ms 230928 KB Output is correct
46 Correct 989 ms 168624 KB Output is correct
47 Correct 399 ms 85432 KB Output is correct
48 Correct 213 ms 61688 KB Output is correct
49 Correct 2060 ms 231068 KB Output is correct
50 Correct 1867 ms 230896 KB Output is correct
51 Correct 1789 ms 231192 KB Output is correct
52 Correct 119 ms 46272 KB Output is correct
53 Correct 812 ms 154852 KB Output is correct