結果

問題 No.649 ここでちょっとQK!
ユーザー latte0119latte0119
提出日時 2018-02-09 23:07:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 108 ms / 3,000 ms
コード長 1,579 bytes
コンパイル時間 1,535 ms
コンパイル使用メモリ 165,132 KB
実行使用メモリ 9,940 KB
最終ジャッジ日時 2024-04-17 06:05:54
合計ジャッジ時間 4,828 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 76 ms
6,528 KB
testcase_04 AC 79 ms
9,812 KB
testcase_05 AC 78 ms
9,940 KB
testcase_06 AC 75 ms
9,940 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 57 ms
7,488 KB
testcase_13 AC 54 ms
7,620 KB
testcase_14 AC 53 ms
7,492 KB
testcase_15 AC 54 ms
7,492 KB
testcase_16 AC 54 ms
7,488 KB
testcase_17 AC 58 ms
7,620 KB
testcase_18 AC 65 ms
7,928 KB
testcase_19 AC 71 ms
8,128 KB
testcase_20 AC 77 ms
8,384 KB
testcase_21 AC 83 ms
8,632 KB
testcase_22 AC 88 ms
8,884 KB
testcase_23 AC 96 ms
9,008 KB
testcase_24 AC 100 ms
9,136 KB
testcase_25 AC 103 ms
9,528 KB
testcase_26 AC 108 ms
9,908 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 46 ms
7,492 KB
testcase_31 AC 46 ms
7,492 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
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |     scanf("%lld%lld",&Q,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:41:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |         scanf("%lld",&T[i]);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:43:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |             scanf("%lld",&A[i]);
      |             ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct BinaryIndexedTree{
    int n;
    vector<int>dat;
    BinaryIndexedTree(int n=0):n(n){
        dat.resize(n+1);
    }
    void add(int k,int x){
        for(k++;k<=n;k+=k&-k)dat[k]+=x;
    }
    int sum(int k){
        int ret=0;
        for(k++;k;k-=k&-k)ret+=dat[k];
        return ret;
    }
};

int Q,K;
int T[222222],A[222222];

signed main(){
    scanf("%lld%lld",&Q,&K);
    vint latte;
    rep(i,Q){
        scanf("%lld",&T[i]);
        if(T[i]==1){
            scanf("%lld",&A[i]);
            latte.pb(A[i]);
        }
    }
    sort(all(latte));latte.erase(unique(all(latte)),latte.end());

    BinaryIndexedTree bit(222222);
    rep(i,Q){
        if(T[i]==1){
            A[i]=lower_bound(all(latte),A[i])-latte.begin();
            bit.add(A[i],1);
        }
        else{
            int lb=-1,ub=222222;
            while(ub-lb>1){
                int mid=(ub+lb)/2;
                if(bit.sum(mid)<K)lb=mid;
                else ub=mid;
            }
            if(ub==222222)puts("-1");
            else{
                printf("%lld\n",latte[ub]);
                bit.add(ub,-1);
            }
        }
    }
    return 0;
}
0