結果

問題 No.59 鉄道の旅
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2014-10-26 01:10:54
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,387 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 85,136 KB
実行使用メモリ 7,504 KB
最終ジャッジ日時 2023-08-26 05:18:34
合計ジャッジ時間 1,833 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,224 KB
testcase_01 AC 5 ms
7,432 KB
testcase_02 AC 4 ms
7,240 KB
testcase_03 AC 5 ms
7,252 KB
testcase_04 AC 39 ms
7,236 KB
testcase_05 AC 5 ms
7,300 KB
testcase_06 AC 4 ms
7,244 KB
testcase_07 AC 4 ms
7,276 KB
testcase_08 AC 8 ms
7,244 KB
testcase_09 AC 8 ms
7,220 KB
testcase_10 AC 8 ms
7,252 KB
testcase_11 AC 6 ms
7,288 KB
testcase_12 AC 18 ms
7,248 KB
testcase_13 AC 38 ms
7,504 KB
testcase_14 AC 37 ms
7,296 KB
testcase_15 AC 4 ms
7,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))

#define MOD 1000000007

#define N_MAX 1000001

int bit[N_MAX + 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 <= N_MAX){
    bit[i] += x;
    i += i & -i;
  }
}

int main(){
  int ans = 0;
  memset(bit, 0, sizeof(bit));
  int n,k;
  cin>>n>>k;
  for(int i = 0; i < n; i++){
    int w;
    cin>>w;
    if(w>=0){
      int c = sum(1000000)-sum(w-1);
      if(c<k){
        add(w,1);
        ans++;
      }
    }
    else{
      w = -w;
      int c = sum(w)-sum(w-1);
      if(c>0){
        add(w,-1);
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

/*
BITを使った問題を考えました。
*/
0