結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,548 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 275 ms
7,468 KB
testcase_14 AC 280 ms
7,484 KB
testcase_15 AC 279 ms
7,592 KB
testcase_16 AC 277 ms
7,572 KB
testcase_17 AC 278 ms
7,512 KB
testcase_18 AC 277 ms
7,512 KB
testcase_19 AC 277 ms
7,512 KB
testcase_20 AC 295 ms
6,536 KB
testcase_21 AC 288 ms
6,480 KB
testcase_22 AC 292 ms
6,456 KB
testcase_23 AC 270 ms
9,652 KB
testcase_24 AC 188 ms
9,592 KB
testcase_25 AC 224 ms
6,460 KB
testcase_26 AC 257 ms
9,560 KB
testcase_27 AC 95 ms
9,632 KB
testcase_28 AC 164 ms
4,376 KB
testcase_29 AC 169 ms
4,380 KB
testcase_30 AC 169 ms
4,380 KB
testcase_31 AC 244 ms
7,532 KB
testcase_32 TLE -
testcase_33 -- -
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);
    int mx = 0;
    for(auto p:op){
        int a = p.first;
        pair<int,int> range = p.second;
        int l = range.first;
        int r = range.second;
        if(a > mx){
            connect(dp[mx]);
            mx = a;
        }
        if(a >= n) {
            // どうせn以上のaは意味がない
            break;
        }
        if(a == 0) {
            dp[0].push_back(range);
        }
        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});
                }
            }
        }
    }
    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