結果

問題 No.2220 Range Insert & Point Mex
ユーザー otamay6otamay6
提出日時 2023-02-17 22:24:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,231 bytes
コンパイル時間 2,303 ms
コンパイル使用メモリ 212,620 KB
実行使用メモリ 10,660 KB
最終ジャッジ日時 2023-09-26 19:40:02
合計ジャッジ時間 13,449 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,660 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 276 ms
6,456 KB
testcase_14 AC 276 ms
6,588 KB
testcase_15 AC 275 ms
6,408 KB
testcase_16 AC 271 ms
6,404 KB
testcase_17 AC 274 ms
6,552 KB
testcase_18 AC 277 ms
6,412 KB
testcase_19 AC 274 ms
6,512 KB
testcase_20 AC 289 ms
6,592 KB
testcase_21 AC 285 ms
6,584 KB
testcase_22 AC 286 ms
6,540 KB
testcase_23 AC 268 ms
9,700 KB
testcase_24 AC 188 ms
9,704 KB
testcase_25 AC 222 ms
6,492 KB
testcase_26 AC 255 ms
9,560 KB
testcase_27 AC 96 ms
9,912 KB
testcase_28 AC 157 ms
4,376 KB
testcase_29 AC 170 ms
4,380 KB
testcase_30 AC 169 ms
4,380 KB
testcase_31 AC 245 ms
6,600 KB
testcase_32 AC 209 ms
5,356 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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(){
    int n;cin>>n;
    vector<pair<int, pair<int,int>>> op(n);
    REP(i,n){
        int l, r,a;
        cin>>l>>r>>a;
        op[i] = {a, {l, r}};
    } 
    sort(All(op));
    // 数iを含む区間[l,r]の範囲
    vector<vector<pair<int,int>>> dp(n);
    for(auto p:op){
        int a = p.first;
        pair<int,int> range = p.second;
        int l = range.first;
        int r = range.second;
        if(a >= n) {
            // どうせn以上のaは意味がない
            break;
        }
        if(a == 0) {
            dp[0].push_back(range);
            connect(dp[0]);
        }
        else{
            for(auto prev_range: dp[a-1]){
                int nl = max(l, prev_range.first);
                int nr = min(r, prev_range.second);
                if(nl <= nr) {
                    dp[a].push_back({nl, nr});
                }
            }
            connect(dp[a]);
        }
    }
    int q;cin>>q;
    REP(_,q){
        int x;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