結果

問題 No.2687 所により大雨
ユーザー t98slidert98slider
提出日時 2024-03-21 00:14:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,908 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 216,388 KB
実行使用メモリ 11,328 KB
最終ジャッジ日時 2024-03-21 00:14:09
合計ジャッジ時間 7,126 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
11,200 KB
testcase_01 AC 84 ms
11,200 KB
testcase_02 AC 83 ms
11,200 KB
testcase_03 AC 84 ms
11,200 KB
testcase_04 AC 84 ms
11,200 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 264 ms
11,328 KB
testcase_11 AC 267 ms
11,328 KB
testcase_12 AC 261 ms
11,328 KB
testcase_13 AC 264 ms
11,328 KB
testcase_14 AC 259 ms
11,328 KB
testcase_15 AC 266 ms
11,328 KB
testcase_16 AC 262 ms
11,328 KB
testcase_17 AC 263 ms
11,328 KB
testcase_18 AC 258 ms
11,328 KB
testcase_19 AC 257 ms
11,328 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <class T> struct fenwick_tree {
    using U = T;

    public:
    fenwick_tree() : _n(0) {}
    fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += U(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

    private:
    int _n;
    std::vector<U> data;

    U sum(int r) {
        U s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, id = 0, K;
    cin >> n >> m;
    vector<pair<ll,ll>> L(n), R(m);
    vector<ll> ca(2 * (n + m));
    for(auto &&[l, r] : L){
        cin >> l >> r;
        l *= 2, r *= 2;
        ca[id++] = l;
        ca[id++] = r;
        ca.push_back(r + 1);
    }
    for(auto &&[l, r] : R){
        cin >> l >> r;
        l *= 2, r *= 2;
        ca[id++] = l;
        ca[id++] = r;
    }
    cin >> K;
    vector<ll> query(K);
    for(auto &&v : query) cin >> v, v *= 2;
    ca.insert(ca.end(), query.begin(), query.end());
    sort(ca.begin(), ca.end());
    ca.erase(unique(ca.begin(), ca.end()), ca.end());
    vector<int> Limos(ca.size()), Rimos(ca.size());
    fenwick_tree<int> fw(ca.size());
    for(auto [l, r] : L){
        l = lower_bound(ca.begin(), ca.end(), l) - ca.begin();
        r = lower_bound(ca.begin(), ca.end(), r + 1) - ca.begin();
        Limos[l]++;
        Limos[r]--;
    }
    for(auto [l, r] : R){
        l = lower_bound(ca.begin(), ca.end(), l) - ca.begin();
        r = lower_bound(ca.begin(), ca.end(), r) - ca.begin();
        Rimos[l]++;
        Rimos[r]--;
    }
    ll aL = 1ll << 60, aR = -aL;
    for(int i = 0; i + 1 < ca.size(); i++){
        Limos[i + 1] += Limos[i];
        Rimos[i + 1] += Rimos[i];
        if(Limos[i] >= 1) fw.add(i, 1);
        if(ca[i] < aL && Limos[i] >= 2) aL = ca[i];
        if(Rimos[i] >= 2) aR = ca[i];
    }
    for(int i = 0; i < K; i++){
        ll v = query[i];
        int p = lower_bound(ca.begin(), ca.end(), v) - ca.begin();
        if(Limos[p] + Rimos[p] >= 2 || aL <= v || v <= aR){
            cout << 1 << (i + 1 == K ? '\n' : ' ');
            continue;
        }
        bool flg = false;
        for(auto [l, r] : R){
            ll l2 = v, r2 = v;
            r2 -= l - v;
            l2 -= r - v;
            if(l2 > r2) swap(l2, r2);
            l2 = lower_bound(ca.begin(), ca.end(), l2) - ca.begin();
            r2 = upper_bound(ca.begin(), ca.end(), r2) - ca.begin();
            if(fw.sum(l2, r2) >= 1){
                flg = true;
                break;
            }
        }
        cout << (flg ? 1 : 0) << (i + 1 == K ? '\n' : ' ');
    }
}
0