結果

問題 No.59 鉄道の旅
ユーザー 0w10w1
提出日時 2016-12-05 15:39:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,499 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 167,748 KB
実行使用メモリ 7,556 KB
最終ジャッジ日時 2023-08-26 07:55:43
合計ジャッジ時間 2,557 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,300 KB
testcase_01 AC 4 ms
7,404 KB
testcase_02 AC 4 ms
7,388 KB
testcase_03 AC 3 ms
7,340 KB
testcase_04 AC 19 ms
7,272 KB
testcase_05 AC 4 ms
7,412 KB
testcase_06 AC 3 ms
7,220 KB
testcase_07 AC 3 ms
7,236 KB
testcase_08 AC 5 ms
7,320 KB
testcase_09 AC 5 ms
7,536 KB
testcase_10 AC 5 ms
7,316 KB
testcase_11 AC 4 ms
7,288 KB
testcase_12 AC 11 ms
7,548 KB
testcase_13 AC 17 ms
7,556 KB
testcase_14 AC 17 ms
7,236 KB
testcase_15 AC 3 ms
7,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector< string > vs;
typedef vector< double > vd;
typedef vector< vd > vvd;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int N, K;
vi W;

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

void preprocess(){
  
}

struct BIT{
  vi dat;
  BIT( int sz ){
    dat = vi( sz );
  }
  void add( int x, int v ){
    for( int i = x; i < dat.size(); i += i & -i )
      dat[ i ] += v;
  }
  int sum( int x ){
    int res = 0;
    for( int i = x; i > 0; i -= i & -i )
      res += dat[ i ];
    return res;
  }
};

void solve(){
  BIT *bit = new BIT( 1000000 + 1 );
  for( int i = 0; i < N; ++i ){
    if( W[ i ] > 0 ){
      if( bit->sum( 1000000 ) - bit->sum( W[ i ] - 1 ) >= K )
        continue;
      bit->add( W[ i ], 1 );
    } else{
      if( bit->sum( -W[ i ] ) - bit->sum( -W[ i ] - 1 ) > 0 )
        bit->add( -W[ i ], -1 ); 
    }
  }
  cout << bit->sum( 1000000 ) << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}
0