結果

問題 No.2220 Range Insert & Point Mex
ユーザー ぷらぷら
提出日時 2023-01-31 04:21:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,358 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 222,208 KB
実行使用メモリ 21,276 KB
最終ジャッジ日時 2023-09-14 15:47:21
合計ジャッジ時間 10,586 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 421 ms
11,884 KB
testcase_14 AC 421 ms
11,728 KB
testcase_15 AC 422 ms
11,864 KB
testcase_16 AC 425 ms
11,880 KB
testcase_17 AC 423 ms
11,856 KB
testcase_18 AC 422 ms
11,812 KB
testcase_19 AC 424 ms
12,004 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 1,197 ms
20,820 KB
testcase_24 AC 1,084 ms
18,476 KB
testcase_25 AC 664 ms
13,684 KB
testcase_26 AC 1,051 ms
21,204 KB
testcase_27 AC 752 ms
15,728 KB
testcase_28 AC 39 ms
8,052 KB
testcase_29 AC 42 ms
8,064 KB
testcase_30 AC 42 ms
7,960 KB
testcase_31 AC 310 ms
12,120 KB
testcase_32 AC 384 ms
10,048 KB
testcase_33 AC 404 ms
9,852 KB
testcase_34 AC 1,171 ms
15,012 KB
testcase_35 AC 1,181 ms
14,976 KB
testcase_36 AC 1,009 ms
14,444 KB
testcase_37 AC 1,032 ms
14,712 KB
testcase_38 AC 955 ms
16,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <typename T>
struct BinaryIndexedTree {
    int N;
    vector<T>bit;
    BinaryIndexedTree(){}
    BinaryIndexedTree(int x) {
        N = x;
        bit.resize(x+1);
    }
    void add(int x,T y) {
        x++;
        while(x <= N) {
            bit[x] += y;
            x += x&-x;
        }
    }
    T sum(int x) {
        x++;
        T res = 0;
        while(x) {
            res += bit[x];
            x -= x&-x;
        }
        return res;
    }
    inline T sum(int l, int r) {//[l,r)
        return sum(r-1)-sum(l-1);
    }
    inline T operator[](int k) {
        return sum(k)-sum(k-1);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<int>L(N),R(N),a(N),cmp;
    for(int i = 0; i < N; i++) {
        cin >> L[i] >> R[i] >> a[i];
        cmp.push_back(L[i]);
        cmp.push_back(R[i]+1);
    }
    int Q;
    cin >> Q;
    vector<int>x(Q);
    for(int i = 0; i < Q; i++) {
        cin >> x[i];
        cmp.push_back(x[i]);
    }
    sort(cmp.begin(),cmp.end());
    cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
    vector<int>l(Q),r(Q,N+3);
    while(true) {
        bool flag = false;
        for(int i = 0; i < Q; i++) {
            if(l[i]+1 < r[i]) {
                flag = true;
            }
        }
        if(!flag) break;
        map<int,vector<pair<int,int>>>mp;
        for(int i = 0; i < N; i++) {
            mp[a[i]].push_back({L[i],R[i]+1});
        }
        for(int i = 0; i < Q; i++) {
            if(l[i]+1 < r[i]) {
                int mid = (l[i]+r[i])/2;
                mp[mid].push_back({i,-1});
            }
        }
        BinaryIndexedTree<int>bit(cmp.size());
        for(auto i:mp) {
            auto j = i.second;
            vector<pair<int,int>>tmp;
            for(auto k:j) {
                if(k.second != -1) {
                    tmp.push_back(k);
                }
                else {
                    int it = lower_bound(cmp.begin(),cmp.end(),x[k.first])-cmp.begin();
                    if(bit.sum(it) == i.first) {
                        l[k.first] = i.first;
                    }
                    else {
                        r[k.first] = i.first;
                    }
                }
            }
            sort(tmp.begin(),tmp.end());
            vector<pair<int,int>>res;
            int mi = -1,mx = -1;
            for(int k = 0; k < tmp.size(); k++) {
                if(mx == -1) {
                    mi = tmp[k].first;
                    mx = tmp[k].second;
                }
                else if(mx <= tmp[k].first) {
                    res.push_back({mi,mx});
                    mi = tmp[k].first;
                    mx = tmp[k].second;
                }
                else {
                    mx = max(mx,tmp[k].second);
                }
            }
            if(mi != -1) {
                res.push_back({mi,mx});
            }
            for(int k = 0; k < res.size(); k++) {
                int it1 = lower_bound(cmp.begin(),cmp.end(),res[k].first)-cmp.begin();
                int it2 = lower_bound(cmp.begin(),cmp.end(),res[k].second)-cmp.begin();;
                bit.add(it1,1);
                bit.add(it2,-1);
            }
        }
    }
    for(int i = 0; i < Q; i++) {
        cout << l[i] << "\n";
    }
}
0