結果

問題 No.59 鉄道の旅
ユーザー togatogatogatoga
提出日時 2015-08-03 12:01:15
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,998 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 91,932 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 06:33:21
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 16 ms
4,376 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 = 100010;
int main() {
  cin >> N >> K;
  BIT<ll> bit;
  bit.init(100010);

  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;
}
0