結果

問題 No.2220 Range Insert & Point Mex
ユーザー otamay6otamay6
提出日時 2023-02-17 22:56:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,774 bytes
コンパイル時間 2,329 ms
コンパイル使用メモリ 213,892 KB
実行使用メモリ 814,024 KB
最終ジャッジ日時 2023-09-26 20:16:41
合計ジャッジ時間 14,413 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 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 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 67 ms
9,948 KB
testcase_14 AC 68 ms
9,748 KB
testcase_15 AC 68 ms
9,732 KB
testcase_16 AC 69 ms
9,880 KB
testcase_17 AC 68 ms
9,780 KB
testcase_18 AC 70 ms
9,872 KB
testcase_19 AC 68 ms
9,816 KB
testcase_20 AC 67 ms
8,780 KB
testcase_21 AC 67 ms
9,012 KB
testcase_22 AC 67 ms
8,824 KB
testcase_23 AC 76 ms
15,132 KB
testcase_24 AC 65 ms
15,164 KB
testcase_25 AC 50 ms
9,048 KB
testcase_26 AC 69 ms
15,152 KB
testcase_27 AC 51 ms
15,128 KB
testcase_28 AC 16 ms
4,500 KB
testcase_29 AC 19 ms
4,376 KB
testcase_30 AC 20 ms
4,380 KB
testcase_31 AC 53 ms
10,432 KB
testcase_32 AC 40 ms
7,524 KB
testcase_33 TLE -
testcase_34 AC 62 ms
9,524 KB
testcase_35 AC 1,554 ms
10,400 KB
testcase_36 AC 60 ms
9,532 KB
testcase_37 AC 1,549 ms
10,420 KB
testcase_38 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

void connect(vector<pair<int,int>> &ranges) {
    // rangesは昇順データ
    vector<pair<int,int>> nxt_range;
    for(const auto &range: ranges) {
        if(nxt_range.size() == 0){
            nxt_range.push_back(range);
        }
        else {
            pair<int,int> &fr = nxt_range.back();
            if(range.first <= fr.second + 1) {
                fr.second = max(fr.second, range.second);
            }
            else {
                nxt_range.push_back(range);
            }
        }
    }
    ranges = nxt_range;
}

int main(){
    std::cin.tie(0)->sync_with_stdio(0);
    int n;std::cin>>n;
    vector<pair<int, pair<int,int>>> op(n);
    REP(i,n){
        int l, r,a;
        std::cin>>l>>r>>a;
        op[i] = {a, {l, r}};
    } 
    sort(All(op));
    // 数iを含む区間[l,r]の範囲
    vector<vector<pair<int,int>>> rgs(n);
    int mx = 0;
    int Lidx = 0;
    for(auto p:op){
        int a = p.first;
        pair<int,int> range = p.second;
        if(a >= n) {
            // どうせn以上のaは意味がない
            break;
        }
        else{
            rgs[a].push_back(range);
        }
    }
    vector<vector<pair<int,int>>> dp(n);
    // 全部の範囲を連結してから判定する
    dp[0] = rgs[0];
    connect(dp[0]);
    rep(a, 1, n){
        connect(rgs[a]);
        int Lidx = 0;
        for(const auto &range: rgs[a]){
            int l = range.first;
            int r = range.second;
            rep(i, Lidx, dp[a-1].size()) {
                pair<int, int> prev_range = dp[a-1][i];
                if(prev_range.second < l){
                    Lidx = i+1;
                    continue;
                }
                if(r < prev_range.first) {
                    break;
                }
                int nl = max(l, prev_range.first);
                int nr = min(r, prev_range.second);
                if(nl <= nr) {
                    dp[a].push_back({nl, nr});
                }
            }
        }
    }
    int q;std::cin>>q;
    REP(_,q){
        int x;std::cin>>x;
        // (l, r]の区間はSxに含まれない
        int l = -1, r = n;
        while(l+1 < r){
            int mid = (l+r) >> 1;
            bool inc = false;
            for(auto range:dp[mid]) {
                if(range.first <= x && x <= range.second) {
                    inc = true;
                    l = mid;
                    break;
                }
            }
            if(!inc) r = mid;
        }
        cout << r << "\n";
    }
}
0