結果

問題 No.2220 Range Insert & Point Mex
ユーザー k1suxuk1suxu
提出日時 2023-02-17 23:14:50
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,460 bytes
コンパイル時間 5,500 ms
コンパイル使用メモリ 277,264 KB
実行使用メモリ 24,848 KB
最終ジャッジ日時 2023-09-28 18:14:34
合計ジャッジ時間 17,388 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,484 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 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,376 KB
testcase_07 AC 2 ms
4,380 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,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 301 ms
20,488 KB
testcase_14 AC 300 ms
19,656 KB
testcase_15 AC 300 ms
19,720 KB
testcase_16 AC 297 ms
19,868 KB
testcase_17 AC 299 ms
19,988 KB
testcase_18 AC 297 ms
19,424 KB
testcase_19 AC 301 ms
20,104 KB
testcase_20 AC 323 ms
19,632 KB
testcase_21 AC 324 ms
20,468 KB
testcase_22 AC 326 ms
20,316 KB
testcase_23 AC 296 ms
21,596 KB
testcase_24 AC 192 ms
18,732 KB
testcase_25 AC 226 ms
14,632 KB
testcase_26 AC 241 ms
21,756 KB
testcase_27 AC 91 ms
16,668 KB
testcase_28 AC 141 ms
7,964 KB
testcase_29 AC 147 ms
7,692 KB
testcase_30 AC 147 ms
7,836 KB
testcase_31 AC 239 ms
21,396 KB
testcase_32 AC 185 ms
13,348 KB
testcase_33 AC 184 ms
13,772 KB
testcase_34 AC 254 ms
18,800 KB
testcase_35 AC 257 ms
20,080 KB
testcase_36 AC 255 ms
19,852 KB
testcase_37 AC 257 ms
19,736 KB
testcase_38 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define pb push_back
#define all(x) x.begin(),x.end()
//#define mp make_pair
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vvll vector<vll>
#define vs vector<string>
#define vvs vector<vs>
#define vc vector<char>
#define vvc vector<vc>
#define pii pair<int,int>
#define pllll pair<ll,ll>
#define vpii vector<pair<int,int>>
#define vpllll vector<pair<ll,ll>>
#define vpis vector<pair<int,string>>
#define vplls vector<pair<ll, string>>
#define vpsi vector<pair<string, int>>
#define vpsll vector<pair<string, ll>>

template<typename T>
void chmax(T &a, const T &b) {a = (a > b? a : b);}
template<typename T>
void chmin(T &a, const T &b) {a = (a < b? a : b);}

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const ll INF = numeric_limits<long long>::max() / 2;
const ld pi = 3.1415926535897932384626433832795028;
const ll mod = 998244353;
int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, -1, 0, 1, -1, 1, -1, 1};

#define int long long

void solve() {
    int n;
    cin >> n;
    vi l(n), r(n), a(n);
    FOR(n) cin >> l[i] >> r[i] >> a[i];
    int q;
    cin >> q;
    vi x(q);
    FOR(q) cin >> x[i];

    vector<array<int, 3>> query;
    FOR(n) {
        query.push_back({0, l[i], a[i]});
        query.push_back({1, r[i]+1, a[i]});
    }
    FOR(q) {
        query.push_back({2, x[i], i});
    }

    vector<int> order(2*n+q);
    iota(all(order), 0);
    sort(all(order), [&](int i, int j) {
        if(query[i][1] != query[j][1]) return query[i][1] < query[j][1];
        return query[i][0] < query[j][0];
    });

    multiset<int> st;
    int mex = 0;
    vi ans(q, -1);

    for(int i : order) {
        auto e = query[i];
        if(e[0] == 0) {
            st.insert(e[2]);
            while(st.find(mex) != st.end()) {
                mex++;
            }
        }else if(e[0] == 1) {
            st.erase(st.find(e[2]));
            if(st.find(e[2]) == st.end()) chmin(mex, e[2]);
        }else {
            ans[e[2]] = mex;
        }
    }

    for(auto e : ans) cout << e << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
0