結果

問題 No.2220 Range Insert & Point Mex
ユーザー 👑 NachiaNachia
提出日時 2023-02-17 21:40:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 3,971 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 91,804 KB
実行使用メモリ 5,744 KB
最終ジャッジ日時 2023-09-28 18:00:14
合計ジャッジ時間 4,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 70 ms
5,524 KB
testcase_14 AC 69 ms
5,516 KB
testcase_15 AC 70 ms
5,744 KB
testcase_16 AC 70 ms
5,484 KB
testcase_17 AC 70 ms
5,572 KB
testcase_18 AC 70 ms
5,568 KB
testcase_19 AC 71 ms
5,480 KB
testcase_20 AC 51 ms
4,376 KB
testcase_21 AC 51 ms
4,380 KB
testcase_22 AC 51 ms
4,380 KB
testcase_23 AC 53 ms
5,588 KB
testcase_24 AC 44 ms
5,244 KB
testcase_25 AC 35 ms
4,384 KB
testcase_26 AC 50 ms
5,520 KB
testcase_27 AC 34 ms
5,256 KB
testcase_28 AC 15 ms
4,380 KB
testcase_29 AC 19 ms
4,380 KB
testcase_30 AC 18 ms
4,376 KB
testcase_31 AC 48 ms
5,584 KB
testcase_32 AC 41 ms
4,648 KB
testcase_33 AC 40 ms
4,752 KB
testcase_34 AC 56 ms
4,976 KB
testcase_35 AC 58 ms
5,040 KB
testcase_36 AC 56 ms
5,048 KB
testcase_37 AC 57 ms
5,044 KB
testcase_38 AC 48 ms
5,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Main.cpp"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#line 2 "nachia\\set\\word-size-tree.hpp"

#line 5 "nachia\\set\\word-size-tree.hpp"

namespace nachia{

struct WordsizeTree{
    using Word = unsigned long long;
    static constexpr int W = 64;
    int N;
    std::vector<std::vector<Word>> A;
    static int highBit(Word x){
        if(x == 0) return 0;
        return W-1 - __builtin_clzll(x);
    }
    static int lowBit(Word x){
        if(x == 0) return W;
        return __builtin_ctzll(x);
    }
    WordsizeTree(unsigned int length){
        N = length;
        int n = length;
        do {
            std::vector<Word> a(n/W+1,0);
            A.emplace_back(std::move(a));
            n /= W;
        } while(n);
    }
    WordsizeTree(const std::string& binStr = ""){
        N = binStr.size();
        int n = N;
        {
            std::vector<Word> a(n/W+1);
            for(int i=0; i<n; i++) if(binStr[i] == '1'){
                a[i/W] |= (Word)1 << (i%W);
            }
            A.emplace_back(std::move(a));
            n /= W;
        }
        while(n){
            std::vector<Word> a(n/W+1,0);
            for(int i=0; i<=n; i++){
                if(A.back()[i]) a[i/W] |= (Word)1 << (i%W);
            }
            A.emplace_back(std::move(a));
            n /= W;
        }
    }
    void insert(int x){
        for(auto& a : A){
            a[x/W] |= (Word)1 << (x % W);
            x /= W;
        }
    }
    void erase(int x){
        for(auto& a : A){
        a[x/W] &= ~((Word)1 << (x % W));
        if(a[x/W]) return;
        x /= W;
        }
    }
    int count(int x) const {
        return (int)((A[0][x/W] >> (x%W)) & 1);
    }
    int noLessThan(int x) const {
        int d = 0, i = x;
        while(true){
            if(d >= (int)A.size()) return -1;
            if(i/W >= (int)A[d].size()) return -1;
            Word m = A[d][i/W] & ((~(Word)0) << (i%W));
            if(!m){ d++; i /= W; i++; }
            else{
                int to = lowBit(m);
                i = i/W*W + to;
                if(d == 0) break;
                i *= W;
                d--;
            }
        }
        return i;
    }
    int noGreaterThan(int x) const {
        int d = 0, i = x;
        while(true){
            if(i < 0) return -1;
            if(d >= (int)A.size()) return -1;
            Word m = A[d][i/W] & ~((~(Word)1) << (i%W));
            if(!m){ d++; i /= W; i--; }
            else{
                int to = highBit(m);
                i = i/W*W + to;
                if(d == 0) break;
                i *= W;
                i += W-1;
                d--;
            }
        }
        return i;
    }
};

} // namespace nachia
#line 7 "Main.cpp"
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<1000000007>;

int main(){
    int N; cin >> N;
    vector<pair<int, int>> Ins, Rem;
    rep(i,N){
        int l, r, a; cin >> l >> r >> a; l--;
        if(a > N) continue;
        Ins.emplace_back(l, a);
        Rem.emplace_back(r, a);
    }
    sort(Ins.begin(), Ins.end());
    sort(Rem.begin(), Rem.end());
    int Q; cin >> Q;
    vector<int> T(Q); rep(i,Q) cin >> T[i];
    nachia::WordsizeTree rex(string(N+1, '1'));
    vector<int> cnt(N+1);
    int ii = 0;
    int ir = 0;
    rep(i,Q){
        while(ii < (int)Ins.size() && Ins[ii].first < T[i]) if(cnt[Ins[ii++].second]++ == 0) rex.erase(Ins[ii-1].second);
        while(ir < (int)Rem.size() && Rem[ir].first < T[i]) if(--cnt[Rem[ir++].second] == 0) rex.insert(Rem[ir-1].second);
        cout << rex.noLessThan(0) << '\n';
    }
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0