結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
latte0119
|
| 提出日時 | 2018-02-09 23:07:57 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 112 ms / 3,000 ms |
| コード長 | 1,579 bytes |
| コンパイル時間 | 1,873 ms |
| コンパイル使用メモリ | 165,232 KB |
| 実行使用メモリ | 10,068 KB |
| 最終ジャッジ日時 | 2024-10-08 18:12:27 |
| 合計ジャッジ時間 | 4,990 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
コンパイルメッセージ
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]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#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;
}
latte0119