結果
| 問題 | No.59 鉄道の旅 | 
| コンテスト | |
| ユーザー |  togatoga | 
| 提出日時 | 2015-08-03 12:02:01 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 45 ms / 5,000 ms | 
| コード長 | 1,999 bytes | 
| コンパイル時間 | 871 ms | 
| コンパイル使用メモリ | 91,396 KB | 
| 実行使用メモリ | 11,136 KB | 
| 最終ジャッジ日時 | 2024-12-24 21:45:15 | 
| 合計ジャッジ時間 | 1,651 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 12 | 
ソースコード
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <bitset>
#include <tuple>
#include <unordered_map>
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
// 1-indexed
///////////////////////////////////////////////////////////////////
template <typename Weight> class BIT {
private:
  int N; //要素数
  vector<Weight> data;
public:
  BIT() {}
  BIT(int N) : N(N) { data.resize(N + 1); }
  void init(int N) {
    this->N = N;
    data.resize(N + 1);
  }
  Weight sum(int index) { // O(logN) sum [1, index]
    Weight res = 0;
    while (index > 0) {
      res += data[index];
      index -= index & -index;
    }
    return res;
  }
  Weight sum(int left, int right) { // sum[left, right]
    return sum(right) - sum(left - 1);
  }
  void add(int index, Weight x) {
    while (index <= N) {
      data[index] += x;
      index += index & -index;
    }
  }
  Weight operator[](int index) { return sum(index) - sum(index - 1); }
};
///////////////////////////////////////////////////////
int N, K;
const int MAX_W = 1000010;
int main() {
  cin >> N >> K;
  BIT<ll> bit;
  bit.init(MAX_W);
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x >= 0) {
      int res = bit.sum(x, MAX_W);
      if (res >= K) {
        continue;
      }
      bit.add(x, 1);
    } else {
      x = -x;
      int res = bit[x];
      if (res == 0)
        continue;
      bit.add(x, -1);
    }
  }
  cout << bit.sum(MAX_W) << endl;
  return 0;
}
            
            
            
        