結果

問題 No.59 鉄道の旅
ユーザー motxxmotxx
提出日時 2014-11-07 00:35:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 826 bytes
コンパイル時間 1,171 ms
コンパイル使用メモリ 147,108 KB
実行使用メモリ 7,088 KB
最終ジャッジ日時 2023-08-26 05:28:43
合計ジャッジ時間 2,032 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,088 KB
testcase_01 AC 3 ms
6,892 KB
testcase_02 AC 3 ms
6,968 KB
testcase_03 AC 3 ms
6,892 KB
testcase_04 AC 32 ms
7,020 KB
testcase_05 AC 3 ms
6,956 KB
testcase_06 AC 4 ms
6,956 KB
testcase_07 AC 3 ms
7,020 KB
testcase_08 AC 7 ms
6,944 KB
testcase_09 AC 7 ms
6,900 KB
testcase_10 AC 7 ms
6,892 KB
testcase_11 AC 4 ms
6,956 KB
testcase_12 AC 16 ms
6,900 KB
testcase_13 AC 34 ms
6,940 KB
testcase_14 AC 33 ms
6,952 KB
testcase_15 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int N, K;

#define MX (1000010)

class BIT {
private:
  
  vector<int> bit;
  int size;
  
public:
  
  BIT(int n) : size(n)
  {
    bit.resize(n+1);
  }
  
  int sum(int i) {
    int s = 0;
    while(i > 0) {
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
  
  void add(int i, int x) {
    while(i <= size) {
      bit[i] += x;
      i += i & -i;
    }
  }
};

int main() {

  cin >> N >> K;
  static BIT b(MX+1);
  
  for(int i=0; i<N; i++) {
    int W; cin >> W;
    if(W > 0) {
      if(b.sum(MX)-b.sum(W-1) < K) {
        b.add(W, 1);
      }
    }
    else {
      W *= -1;
      if(b.sum(W)-b.sum(W-1) > 0) {
        b.add(W, -1);
      }
    }
  }
  
  cout << b.sum(MX) << endl;
  return 0;
}
0