結果

問題 No.649 ここでちょっとQK!
ユーザー wakannyaaiwakannyaai
提出日時 2020-02-14 10:36:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 322 ms / 3,000 ms
コード長 4,667 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 179,728 KB
実行使用メモリ 37,296 KB
最終ジャッジ日時 2024-04-16 00:09:25
合計ジャッジ時間 7,252 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
34,432 KB
testcase_01 AC 11 ms
34,520 KB
testcase_02 AC 12 ms
34,560 KB
testcase_03 AC 322 ms
34,560 KB
testcase_04 AC 198 ms
37,296 KB
testcase_05 AC 186 ms
37,232 KB
testcase_06 AC 195 ms
36,840 KB
testcase_07 AC 12 ms
34,560 KB
testcase_08 AC 11 ms
34,432 KB
testcase_09 AC 12 ms
34,432 KB
testcase_10 AC 11 ms
34,432 KB
testcase_11 AC 12 ms
34,660 KB
testcase_12 AC 109 ms
35,688 KB
testcase_13 AC 108 ms
35,688 KB
testcase_14 AC 106 ms
35,816 KB
testcase_15 AC 112 ms
35,732 KB
testcase_16 AC 111 ms
35,684 KB
testcase_17 AC 123 ms
35,816 KB
testcase_18 AC 135 ms
35,816 KB
testcase_19 AC 145 ms
35,812 KB
testcase_20 AC 153 ms
35,692 KB
testcase_21 AC 164 ms
36,092 KB
testcase_22 AC 175 ms
36,280 KB
testcase_23 AC 187 ms
36,220 KB
testcase_24 AC 196 ms
36,244 KB
testcase_25 AC 208 ms
36,132 KB
testcase_26 AC 217 ms
36,100 KB
testcase_27 AC 12 ms
34,440 KB
testcase_28 AC 13 ms
34,560 KB
testcase_29 AC 11 ms
34,560 KB
testcase_30 AC 71 ms
35,820 KB
testcase_31 AC 72 ms
35,436 KB
testcase_32 AC 12 ms
34,600 KB
testcase_33 AC 12 ms
34,432 KB
testcase_34 AC 11 ms
34,432 KB
testcase_35 AC 11 ms
34,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include <unordered_set>
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define Sort(a) sort(a.begin(),a.end())
#define cSort(a,cmp) sort(a.begin(),a.end(),cmp)
#define reSort(a) sort(a.rbegin(), a.rend())
static const ll llMAX = numeric_limits<long long>::max();
static const int intMAX = numeric_limits<int>::max();
static const ll  llMIN = numeric_limits<long long>::min();
static const int intMIN = numeric_limits<int>::min();
static const ll d_5 = 100000;
static const ll d9_7 = 1000000007;
static const ll d_9 = 1000000000;
static const double PI=3.14159265358979323846;
template<class T>
void Printvector(std::vector<T> a){
  int size = a.size();
  rep(i,size){
    cout<<a[i]<<" ";
  }
  cout<<endl;
}
template<class T>
void Printvector(std::vector<std::vector<T>> a){
  int size = a.size();
  rep(i,size){
    int size2=a[i].size();
    rep(j,size2){
      cout<<a[i][j]<<" ";
    }
    cout<<endl;
  }
  cout<<endl;
}
ll digitpower(ll a,ll b){//aのb乗を計算
  if(b==1){
    return a;
  }else if(b==0){
    return 1;
  }
  int mode=0;
  if(b%2==1){
    ll tmp = digitpower(a,(b-1)/2);
    if(mode==1){
      tmp%=d9_7;
    }
    tmp*=tmp;
    if(mode==1){
      tmp%=d9_7;
    }
    tmp*=a;
    if(mode==1){
      return tmp%d9_7;
    }else{
      return tmp;
    }
  }else{
    ll tmp = digitpower(a,(b)/2);
    if(mode==1){
      tmp%=d9_7;
    }
    tmp*=tmp;
    if(mode==1){
      tmp%=d9_7;
    }
    if(mode==1){
      return tmp%d9_7;
    }else{
      return tmp;
    }
  }
}
vl facs(2000010,-1);
ll Factrial(ll num){
  if(facs[num]!=-1){
    return facs[num];
  }
  if(num==1||num<=0){
    return 1;
  }else if(num<0){
    printf("ERROR_minus\n");
    return 0;
  }else{
    facs[num]=(num*Factrial(num-1))%d9_7;
    return facs[num];
  }
}
long long modinv(long long a, long long m) {//modの逆元

    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

vl invs(2000010,-1);
ll linercomb(ll n,ll k, ll mod){//n,kの線形時間で求める
if(n<k)return 0;
if(n<0)return 0;
if(k==0 || k==n)return 1;
  ll ans=Factrial(n);
  if(invs[k]==-1){
    invs[k]=modinv(Factrial(k),mod);
  }
  ans*=invs[k];
  ans%=d9_7;
  ll k1=Factrial(n-k);
  k1%=mod;
  ans*=modinv(k1,mod);
  ans%=mod;
  return ans;
}
unordered_map<ll,ll> prime_factor(int64_t n) {
  unordered_map<ll,ll> ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

template<class T>
vector<T> getaccum(vector<T> a){
  int size=a.size();
  vector<T> ans(size);
  ans[0]=a[0];
  for(int i=0;i<size-1;i++){
    ans[i+1]=ans[i]+a[i+1];
    //ans[i+1]%=d9_7;
  }
  return ans;
}

ll getaccumnum(vector<ll> accum,int l,int r){//閉区間[l,r]の総和
  if(l==0){
    return accum[r];
  }else{
    return accum[r]-accum[l-1];
  }
}
struct datas{
  ll path;
  ll total;
};/*
bool cmp(const datas &a, const datas &b)
{
    return a.num < b.num;
}*/
struct opera{
  int x;
  int y;
  datas state;
};
int LCS(string s,string t) {
  int n=s.size();
  int m=t.size();
  vector<vector<int>> dp=vector<vector<int>>(n+1,vector<int>(m+1,0));
    for (int i=0; i<n; ++i) {
        for (int j=0; j<m; ++j) {
            if (s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            else {
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
    }
    return dp[n][m];
}

int main(void){
  ll q,k;
  cin>>q>>k;
  priority_queue<ll> numsmall;
  priority_queue<ll, vector<ll>, greater<ll>> numlarge;
  rep(i,q){
    int tmp;
    cin>>tmp;
    if(tmp==1){
      ll input;
      cin>>input;
      if(numsmall.size()<k){
        numsmall.push(input);
      }else{
        if(numsmall.top()<=input){
          numlarge.push(input);
        }else{
          ll tmp2=numsmall.top();
          numsmall.pop();
          numsmall.push(input);
          numlarge.push(tmp2);
        }
      }
    }else if(tmp==2){
      if(numsmall.size()<k){
        cout<<-1<<endl;
        continue;
      }
      cout<<numsmall.top()<<endl;
      numsmall.pop();
      if(numlarge.size()>0){
        ll tmp2=numlarge.top();
        numlarge.pop();
        numsmall.push(tmp2);
      }
    }
  }
  return 0;
}

//<<std::setprecision(30)w xd
0