結果

問題 No.59 鉄道の旅
ユーザー beetbeet
提出日時 2019-01-31 16:16:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 5,000 ms
コード長 1,082 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 200,988 KB
実行使用メモリ 11,600 KB
最終ジャッジ日時 2023-08-09 23:05:22
合計ジャッジ時間 3,363 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,760 KB
testcase_01 AC 5 ms
10,764 KB
testcase_02 AC 5 ms
11,072 KB
testcase_03 AC 6 ms
10,952 KB
testcase_04 AC 38 ms
11,056 KB
testcase_05 AC 5 ms
10,920 KB
testcase_06 AC 5 ms
10,896 KB
testcase_07 AC 5 ms
10,812 KB
testcase_08 AC 9 ms
10,812 KB
testcase_09 AC 8 ms
10,896 KB
testcase_10 AC 9 ms
10,880 KB
testcase_11 AC 7 ms
10,764 KB
testcase_12 AC 19 ms
11,388 KB
testcase_13 AC 36 ms
11,600 KB
testcase_14 AC 36 ms
11,304 KB
testcase_15 AC 5 ms
10,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template<typename T> 
struct BIT{
  int n;
  vector<T> bit;
  //1-indexed
  BIT():n(-1){}
  BIT(int n_,T d):n(n_),bit(n_+1,d){}
  
  T sum(int i){
    T s=bit[0];
    for(int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  void add(int i,T a){
    if(i==0) return;
    for(int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }
};

//INSERT ABOVE HERE
signed main(){
  int n,k;
  cin>>n>>k;
  vector<int> w(n);
  for(int i=0;i<n;i++) cin>>w[i];

  const int MAX = 1e6+100;
  BIT<int> bit(MAX,0);
  vector<int> cnt(MAX);  
  int res=0;

  for(int i=0;i<n;i++){
    if(w[i]<0){
      if(cnt[-w[i]]==0) continue;
      cnt[-w[i]]--;
      res--;
      bit.add(-w[i],-1);      
    }
    if(w[i]>0){
      int num=res-bit.sum(w[i]-1);
      if(num>=k) continue;
      cnt[w[i]]++;
      res++;
      bit.add(w[i],1);
    }
  }
  
  cout<<res<<endl;
  return 0;
}
0