제출 #935821

#제출 시각아이디문제언어결과실행 시간메모리
935821WhisperExamination (JOI19_examination)C++17
100 / 100
649 ms45744 KiB
#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';
    }
}


컴파일 시 표준 에러 (stderr) 메시지

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];
      |                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...