답안 #935821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
935821 2024-02-29T15:17:05 Z Whisper Examination (JOI19_examination) C++17
100 / 100
649 ms 45744 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define int long long
#define FOR(i, a, b) for ( int i = a ; i <= b ; i++ )
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define Lg(x) 31 - __builtin_clz(x)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int MAX = 2e5 + 5;
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void setupIO(){
    #define name "Whisper"
    //Phu Trong from Nguyen Tat Thanh High School for gifted student
    srand(time(NULL));
    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    cout << fixed << setprecision(10);
}

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
int nArr, numQuery;

map<int, int> compress;

vector<array<int, 4>> events;

struct FenwickTree{
    int n;
    vector<int> f;
    FenwickTree(int _n){
        this -> n = _n;
        f.resize(n + 5);
    }

    void modify(int p, int val){
        for ( ; p <= n; p += p & (-p)) f[p] += val;
    }
    int query(int p){
        int res = 0;
        for ( ; p > 0; p -= p & (-p)) res += f[p];
        return res;
    }
    int query(int l, int r){
        return query(r) - query(l - 1);
    }
};

const int N = 4e5;
int ans[MAX];
void Whisper(){
    cin >> nArr >> numQuery;
    for (int i = 1; i <= nArr; ++i){
        int t, s; cin >> t >> s;
        compress[t] = compress[s] = 0;
        events.push_back({t, s, t + s, 0});
    }
    for (int i = 1; i <= numQuery; ++i){
        int a, b, c; cin >> a >> b >> c;
        compress[a] = compress[b] = 0;
        events.push_back({a, b, max(a + b, c), i});
    }
    sort(events.begin(), events.end(), [&](const array<int, 4>& a, const array<int, 4>& b){
        if (a[2] == b[2]) return a[3] < b[3];
        return a[2] > b[2];
    });


    FenwickTree fenA(N), fenB(N);
    int cnt = 0;
    for (auto&v : compress){
        v.second = ++cnt;
    }
    cnt = 0;
    for (array<int, 4> &x : events){
        int a = x[0], b = x[1], c = x[2], id = x[3];
        a = compress[a], b = compress[b];
        if (id > 0){
            ans[id] = fenA.query(a, N) + fenB.query(b, N) - cnt;
        }
        else{
            ++cnt;
            // vì s + t >= c = max(c, a + b)
            // => s + t >= a + b
            // => tồn tại số 1 trong hai số s >= a hoặc t >= b
            // -> cnt là số > a hoặc > b hoặc cả hai
            // -> bao hàm loại trừ
            fenA.modify(a, 1); fenB.modify(b, 1);
        }
    }
    for (int i = 1; i <= numQuery; ++i){
        cout << ans[i] << "\n";
    }
}


signed main(){
    setupIO();
    int Test = 1;
//    cin >> Test;
    for ( int i = 1 ; i <= Test ; i++ ){
        Whisper();
        if (i < Test) cout << '\n';
    }
}


Compilation message

examination.cpp: In function 'void Whisper()':
examination.cpp:99:33: warning: unused variable 'c' [-Wunused-variable]
   99 |         int a = x[0], b = x[1], c = x[2], id = x[3];
      |                                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 10 ms 7820 KB Output is correct
8 Correct 8 ms 7640 KB Output is correct
9 Correct 8 ms 7640 KB Output is correct
10 Correct 6 ms 7384 KB Output is correct
11 Correct 6 ms 7440 KB Output is correct
12 Correct 4 ms 6876 KB Output is correct
13 Correct 8 ms 7640 KB Output is correct
14 Correct 8 ms 7776 KB Output is correct
15 Correct 8 ms 7836 KB Output is correct
16 Correct 6 ms 7384 KB Output is correct
17 Correct 7 ms 7384 KB Output is correct
18 Correct 4 ms 6880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 23424 KB Output is correct
2 Correct 230 ms 23072 KB Output is correct
3 Correct 247 ms 23468 KB Output is correct
4 Correct 129 ms 22848 KB Output is correct
5 Correct 138 ms 21320 KB Output is correct
6 Correct 59 ms 15796 KB Output is correct
7 Correct 222 ms 22796 KB Output is correct
8 Correct 212 ms 22704 KB Output is correct
9 Correct 198 ms 22156 KB Output is correct
10 Correct 133 ms 22424 KB Output is correct
11 Correct 118 ms 21680 KB Output is correct
12 Correct 56 ms 16344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 23424 KB Output is correct
2 Correct 230 ms 23072 KB Output is correct
3 Correct 247 ms 23468 KB Output is correct
4 Correct 129 ms 22848 KB Output is correct
5 Correct 138 ms 21320 KB Output is correct
6 Correct 59 ms 15796 KB Output is correct
7 Correct 222 ms 22796 KB Output is correct
8 Correct 212 ms 22704 KB Output is correct
9 Correct 198 ms 22156 KB Output is correct
10 Correct 133 ms 22424 KB Output is correct
11 Correct 118 ms 21680 KB Output is correct
12 Correct 56 ms 16344 KB Output is correct
13 Correct 256 ms 23472 KB Output is correct
14 Correct 234 ms 24140 KB Output is correct
15 Correct 286 ms 24648 KB Output is correct
16 Correct 152 ms 22896 KB Output is correct
17 Correct 143 ms 22448 KB Output is correct
18 Correct 60 ms 15284 KB Output is correct
19 Correct 250 ms 23772 KB Output is correct
20 Correct 232 ms 23980 KB Output is correct
21 Correct 225 ms 22968 KB Output is correct
22 Correct 134 ms 22448 KB Output is correct
23 Correct 122 ms 23220 KB Output is correct
24 Correct 49 ms 15032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 10 ms 7820 KB Output is correct
8 Correct 8 ms 7640 KB Output is correct
9 Correct 8 ms 7640 KB Output is correct
10 Correct 6 ms 7384 KB Output is correct
11 Correct 6 ms 7440 KB Output is correct
12 Correct 4 ms 6876 KB Output is correct
13 Correct 8 ms 7640 KB Output is correct
14 Correct 8 ms 7776 KB Output is correct
15 Correct 8 ms 7836 KB Output is correct
16 Correct 6 ms 7384 KB Output is correct
17 Correct 7 ms 7384 KB Output is correct
18 Correct 4 ms 6880 KB Output is correct
19 Correct 248 ms 23424 KB Output is correct
20 Correct 230 ms 23072 KB Output is correct
21 Correct 247 ms 23468 KB Output is correct
22 Correct 129 ms 22848 KB Output is correct
23 Correct 138 ms 21320 KB Output is correct
24 Correct 59 ms 15796 KB Output is correct
25 Correct 222 ms 22796 KB Output is correct
26 Correct 212 ms 22704 KB Output is correct
27 Correct 198 ms 22156 KB Output is correct
28 Correct 133 ms 22424 KB Output is correct
29 Correct 118 ms 21680 KB Output is correct
30 Correct 56 ms 16344 KB Output is correct
31 Correct 256 ms 23472 KB Output is correct
32 Correct 234 ms 24140 KB Output is correct
33 Correct 286 ms 24648 KB Output is correct
34 Correct 152 ms 22896 KB Output is correct
35 Correct 143 ms 22448 KB Output is correct
36 Correct 60 ms 15284 KB Output is correct
37 Correct 250 ms 23772 KB Output is correct
38 Correct 232 ms 23980 KB Output is correct
39 Correct 225 ms 22968 KB Output is correct
40 Correct 134 ms 22448 KB Output is correct
41 Correct 122 ms 23220 KB Output is correct
42 Correct 49 ms 15032 KB Output is correct
43 Correct 649 ms 44116 KB Output is correct
44 Correct 527 ms 45744 KB Output is correct
45 Correct 522 ms 45488 KB Output is correct
46 Correct 206 ms 30864 KB Output is correct
47 Correct 214 ms 31148 KB Output is correct
48 Correct 61 ms 15792 KB Output is correct
49 Correct 525 ms 45284 KB Output is correct
50 Correct 576 ms 45212 KB Output is correct
51 Correct 464 ms 44464 KB Output is correct
52 Correct 194 ms 31172 KB Output is correct
53 Correct 180 ms 29916 KB Output is correct