結果

問題 No.649 ここでちょっとQK!
ユーザー i_am_nicolen_22i_am_nicolen_22
提出日時 2020-06-01 19:41:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 702 ms / 3,000 ms
コード長 3,709 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 180,584 KB
実行使用メモリ 20,572 KB
最終ジャッジ日時 2024-05-01 22:55:13
合計ジャッジ時間 13,499 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 286 ms
7,936 KB
testcase_04 AC 701 ms
20,444 KB
testcase_05 AC 683 ms
20,572 KB
testcase_06 AC 176 ms
9,476 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 344 ms
12,012 KB
testcase_13 AC 344 ms
12,012 KB
testcase_14 AC 335 ms
12,032 KB
testcase_15 AC 338 ms
12,028 KB
testcase_16 AC 329 ms
12,024 KB
testcase_17 AC 378 ms
12,732 KB
testcase_18 AC 413 ms
13,452 KB
testcase_19 AC 441 ms
14,148 KB
testcase_20 AC 471 ms
14,940 KB
testcase_21 AC 507 ms
15,592 KB
testcase_22 AC 533 ms
16,316 KB
testcase_23 AC 576 ms
17,040 KB
testcase_24 AC 593 ms
17,760 KB
testcase_25 AC 655 ms
18,608 KB
testcase_26 AC 702 ms
19,188 KB
testcase_27 AC 5 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 5 ms
5,376 KB
testcase_30 AC 239 ms
10,732 KB
testcase_31 AC 236 ms
10,856 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

template <class Abel>
struct BIT
{
    vector<Abel> dat;
    Abel UNITY_SUM = 0; // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n)
    {
        dat.resize(n + 1);
        for (int i = 0; i < (int)dat.size(); ++i)
            dat[i] = UNITY_SUM;
    }

    /* a is 1-indexed */
    inline void add(int a, Abel x)
    {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }

    /* [1, a], a is 1-indexed */
    inline Abel sum(int a)
    {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }

    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b)
    {
        return sum(b - 1) - sum(a - 1);
    }

    /* k-th number (k is 0-indexed) */
    int get(long long k)
    {
        ++k;
        int res = 0;
        int N = 1;
        while (N < (int)dat.size())
            N *= 2;
        for (int i = N / 2; i > 0; i /= 2)
        {
            if (res + i < (int)dat.size() && dat[res + i] < k)
            {
                k = k - dat[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

signed main()
{
    int q, k;
    cin >> q >> k;
    vector<int> type(q);
    vector<int> ad;
    vector<int> V(q);
    for (int i = 0; i < q; i++)
    {
        int x;
        cin >> x;
        if(x==1){
            int u;
            cin >> u;
            type[i] = x;
            V[i] = u;
            ad.push_back(u);
        }
        else{
            type[i] = x;
        }
    }
    sort(ad.begin(), ad.end());
    set<int> st(ad.begin(), ad.end());
    vector<int> v(st.begin(), st.end());
    show(v);
    BIT<int> bit(200010);
    for (int i = 0; i < q; i++)
    {
        if(type[i]==1){
            int idx = lower_bound(ALL(v), V[i]) - v.begin();
            //cerr << idx << endl;
            idx++;

            bit.add(idx, 1);
        }
        else{
            int size = bit.sum(200010);
            if(k>size){
                cout << -1 << endl;
            }
            else{
            int id = bit.get(k - 1);
            //cerr << "id" << id << endl;
            cout << v[id - 1] << endl;
            bit.add(id, -1);
            }
        }
    }
    

    return 0;
}
0