結果

問題 No.59 鉄道の旅
ユーザー たこしたこし
提出日時 2014-11-13 17:36:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 1,348 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 9,504 KB
最終ジャッジ日時 2023-08-26 05:34:04
合計ジャッジ時間 1,576 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,436 KB
testcase_01 AC 2 ms
5,600 KB
testcase_02 AC 2 ms
5,440 KB
testcase_03 AC 2 ms
5,440 KB
testcase_04 AC 37 ms
9,504 KB
testcase_05 AC 2 ms
5,488 KB
testcase_06 AC 2 ms
5,588 KB
testcase_07 AC 3 ms
5,444 KB
testcase_08 AC 8 ms
7,448 KB
testcase_09 AC 8 ms
7,408 KB
testcase_10 AC 8 ms
7,596 KB
testcase_11 AC 3 ms
5,480 KB
testcase_12 AC 16 ms
7,480 KB
testcase_13 AC 35 ms
7,608 KB
testcase_14 AC 33 ms
7,424 KB
testcase_15 AC 2 ms
5,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define INF 1000000000
#define EPS 1e-9
#define PI acos(-1)

typedef long long ll;
typedef pair<int, int> P;

#define MAX_N 1000000
#define MAX_K 1000000

int N, K;
int W[MAX_N];

//BITの実装
//[l, n]
int bit[MAX_N+1], n = MAX_N;

//i番目までの合計値
int sum(int i){
  int s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

//i番目の値をxだけ増やす
void add(int i, int x){
  while(i <= n){
    bit[i] += x;
    i += i & -i;
  }
}

int main(){

  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> W[i];
  }

  for(int i = 0; i < N; i++){
    if(W[i] > 0){
      int tmp = sum(MAX_N) - sum(W[i]-1);
      if(tmp < K){
	add(W[i], 1);
      }
    }
    else if(W[i] < 0){
      int w = abs(W[i]);
      if(sum(w) - sum(w-1) > 0){
	add(w, -1);
      }
    }
  }

  cout << sum(MAX_N) << endl;

  return 0;
  
}
0