답안 #631563

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631563 2022-08-18T08:40:31 Z K4YAN Examination (JOI19_examination) C++17
100 / 100
1797 ms 154108 KB
//Be Name Khoda

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast,unroll-loops")

using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define po pair<pll, pll>
#define ordered_set tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update>

const ll mxn = 1e5 + 16, MX = 27e4 + 16;
ll n, T, q, w, ans;
ll s[mxn], t[mxn], lbl[mxn], A[mxn], B[mxn], X[mxn], answer[mxn];
vector<pll> ord, qr, srt;
ordered_set v[MX];

void input() {

    cin >> n >> T;
    for(int i = 0; i < n; i++) {
        cin >> s[i] >> t[i];
        srt.push_back({s[i], i});
        ord.push_back({t[i], i});
    }
    for(int i = 0; i < T; i++) {
        ll a, b, x;
        cin >> a >> b >> x;
        qr.push_back({b, i});
        A[i] = a, B[i] = b, X[i] = x;
    }

}

int bs(int l, int r, int g) {
    if(r - l == 1) return r;
    int mid = (l + r) >> 1;
    if(srt[mid].first < g) {
        return bs(mid, r, g);
    } return bs(l, mid, g);
}

struct segtree {

    int sz = 1;
    inline void init(ll n) {
        while(sz < n) sz <<= 1;
        return;
    }
    void add(int i, pll p, int x, int lx, int rx) {
        v[x].insert(p);
        if(rx - lx == 1) return;
        int mid = (lx + rx) >> 1;
        if(i < mid) {
            add(i, p, 2 * x + 1, lx, mid);
        } else {
            add(i, p, 2 * x + 2, mid, rx);
        } return;
    }
    void add(int i, pll p) {
        add(i, p, 0, 0, sz);
        return;
    }
    void remove(int i, pll p, int x, int lx, int rx) {
        v[x].erase(p);
        if(rx - lx == 1) return;
        int mid = (lx + rx) >> 1;
        if(i < mid) {
            remove(i, p, 2 * x + 1, lx, mid);
        } else {
            remove(i, p, 2 * x + 2, mid, rx);
        } return;
    }
    void remove(int i, pll p) {
        remove(i, p, 0, 0, sz);
        return;
    }
    void ask(int l, int r, pll p, int x, int lx, int rx) {
        if(rx <= l || r <= lx) return;
        if(l <= lx && rx <= r) {
            ans += int(v[x].size());
            ans -= v[x].order_of_key(p);
            return;
        } int mid = (lx + rx) >> 1;
        ask(l, r, p, 2 * x + 1, lx, mid);
        ask(l, r, p, 2 * x + 2, mid, rx);
        return;
    }
    void ask(int l, int r, pll p) {
        ask(l, r, p, 0, 0, sz);
        return;
    }

};

void solve() {

    sort(all(srt)), sort(all(qr));
    sort(all(ord));
    for(int i = 0; i < n; i++) {
        lbl[srt[i].second] = i;
    } ll ptr = 0;
    segtree st;
    st.init(n);
    for(int i = 0; i < n; i++) {
        st.add(i, {s[srt[i].second] + t[srt[i].second], srt[i].second});
    }
    for(int i = 0; i < T; i++) {
        while(ptr < n && ord[ptr].first < qr[i].first) {
            st.remove(lbl[ord[ptr].second], {s[ord[ptr].second] + t[ord[ptr].second], ord[ptr].second});
            ptr++;
        } ans = 0;
        q = bs(-1, n, A[qr[i].second]);
        st.ask(q, n, {X[qr[i].second], -1});
        answer[qr[i].second] = ans;
    } for(int i = 0; i < T; i++) {
        cout << answer[i] << "\n";
    } return;

}

int main() {

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

    input(), solve();

    return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 25672 KB Output is correct
2 Correct 21 ms 25628 KB Output is correct
3 Correct 20 ms 25648 KB Output is correct
4 Correct 19 ms 25692 KB Output is correct
5 Correct 21 ms 25700 KB Output is correct
6 Correct 20 ms 25684 KB Output is correct
7 Correct 38 ms 28520 KB Output is correct
8 Correct 37 ms 28616 KB Output is correct
9 Correct 38 ms 28628 KB Output is correct
10 Correct 39 ms 28500 KB Output is correct
11 Correct 37 ms 28576 KB Output is correct
12 Correct 38 ms 28436 KB Output is correct
13 Correct 38 ms 28500 KB Output is correct
14 Correct 41 ms 28596 KB Output is correct
15 Correct 43 ms 28584 KB Output is correct
16 Correct 40 ms 28504 KB Output is correct
17 Correct 39 ms 28544 KB Output is correct
18 Correct 34 ms 28512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1493 ms 151632 KB Output is correct
2 Correct 1410 ms 151704 KB Output is correct
3 Correct 1372 ms 151600 KB Output is correct
4 Correct 1217 ms 150912 KB Output is correct
5 Correct 1083 ms 150816 KB Output is correct
6 Correct 903 ms 150116 KB Output is correct
7 Correct 1355 ms 151488 KB Output is correct
8 Correct 969 ms 151692 KB Output is correct
9 Correct 950 ms 151584 KB Output is correct
10 Correct 1032 ms 150696 KB Output is correct
11 Correct 1138 ms 150660 KB Output is correct
12 Correct 659 ms 149756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1493 ms 151632 KB Output is correct
2 Correct 1410 ms 151704 KB Output is correct
3 Correct 1372 ms 151600 KB Output is correct
4 Correct 1217 ms 150912 KB Output is correct
5 Correct 1083 ms 150816 KB Output is correct
6 Correct 903 ms 150116 KB Output is correct
7 Correct 1355 ms 151488 KB Output is correct
8 Correct 969 ms 151692 KB Output is correct
9 Correct 950 ms 151584 KB Output is correct
10 Correct 1032 ms 150696 KB Output is correct
11 Correct 1138 ms 150660 KB Output is correct
12 Correct 659 ms 149756 KB Output is correct
13 Correct 1608 ms 152016 KB Output is correct
14 Correct 1510 ms 152096 KB Output is correct
15 Correct 1336 ms 151600 KB Output is correct
16 Correct 1318 ms 151232 KB Output is correct
17 Correct 1323 ms 151240 KB Output is correct
18 Correct 917 ms 150140 KB Output is correct
19 Correct 1575 ms 151968 KB Output is correct
20 Correct 1540 ms 152012 KB Output is correct
21 Correct 1570 ms 152012 KB Output is correct
22 Correct 1022 ms 150704 KB Output is correct
23 Correct 1178 ms 150720 KB Output is correct
24 Correct 671 ms 149836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 25672 KB Output is correct
2 Correct 21 ms 25628 KB Output is correct
3 Correct 20 ms 25648 KB Output is correct
4 Correct 19 ms 25692 KB Output is correct
5 Correct 21 ms 25700 KB Output is correct
6 Correct 20 ms 25684 KB Output is correct
7 Correct 38 ms 28520 KB Output is correct
8 Correct 37 ms 28616 KB Output is correct
9 Correct 38 ms 28628 KB Output is correct
10 Correct 39 ms 28500 KB Output is correct
11 Correct 37 ms 28576 KB Output is correct
12 Correct 38 ms 28436 KB Output is correct
13 Correct 38 ms 28500 KB Output is correct
14 Correct 41 ms 28596 KB Output is correct
15 Correct 43 ms 28584 KB Output is correct
16 Correct 40 ms 28504 KB Output is correct
17 Correct 39 ms 28544 KB Output is correct
18 Correct 34 ms 28512 KB Output is correct
19 Correct 1493 ms 151632 KB Output is correct
20 Correct 1410 ms 151704 KB Output is correct
21 Correct 1372 ms 151600 KB Output is correct
22 Correct 1217 ms 150912 KB Output is correct
23 Correct 1083 ms 150816 KB Output is correct
24 Correct 903 ms 150116 KB Output is correct
25 Correct 1355 ms 151488 KB Output is correct
26 Correct 969 ms 151692 KB Output is correct
27 Correct 950 ms 151584 KB Output is correct
28 Correct 1032 ms 150696 KB Output is correct
29 Correct 1138 ms 150660 KB Output is correct
30 Correct 659 ms 149756 KB Output is correct
31 Correct 1608 ms 152016 KB Output is correct
32 Correct 1510 ms 152096 KB Output is correct
33 Correct 1336 ms 151600 KB Output is correct
34 Correct 1318 ms 151232 KB Output is correct
35 Correct 1323 ms 151240 KB Output is correct
36 Correct 917 ms 150140 KB Output is correct
37 Correct 1575 ms 151968 KB Output is correct
38 Correct 1540 ms 152012 KB Output is correct
39 Correct 1570 ms 152012 KB Output is correct
40 Correct 1022 ms 150704 KB Output is correct
41 Correct 1178 ms 150720 KB Output is correct
42 Correct 671 ms 149836 KB Output is correct
43 Correct 1726 ms 154000 KB Output is correct
44 Correct 1797 ms 154108 KB Output is correct
45 Correct 1586 ms 153932 KB Output is correct
46 Correct 1368 ms 152464 KB Output is correct
47 Correct 1400 ms 152412 KB Output is correct
48 Correct 1045 ms 149972 KB Output is correct
49 Correct 1681 ms 153836 KB Output is correct
50 Correct 1366 ms 154072 KB Output is correct
51 Correct 1248 ms 153940 KB Output is correct
52 Correct 1186 ms 152372 KB Output is correct
53 Correct 1217 ms 151488 KB Output is correct