結果

問題 No.59 鉄道の旅
ユーザー なおなお
提出日時 2014-11-07 01:46:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 720 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 145,608 KB
実行使用メモリ 6,964 KB
最終ジャッジ日時 2023-08-26 05:29:56
合計ジャッジ時間 2,113 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,684 KB
testcase_01 AC 3 ms
6,864 KB
testcase_02 AC 3 ms
6,840 KB
testcase_03 AC 3 ms
6,680 KB
testcase_04 AC 33 ms
6,848 KB
testcase_05 AC 3 ms
6,772 KB
testcase_06 AC 4 ms
6,760 KB
testcase_07 AC 3 ms
6,824 KB
testcase_08 AC 7 ms
6,876 KB
testcase_09 AC 7 ms
6,964 KB
testcase_10 AC 6 ms
6,892 KB
testcase_11 AC 5 ms
6,820 KB
testcase_12 AC 16 ms
6,796 KB
testcase_13 AC 36 ms
6,896 KB
testcase_14 AC 35 ms
6,948 KB
testcase_15 AC 4 ms
6,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))

template<class _T>struct BIT{
    int N;vector<_T>bit;
    BIT(int n):bit(n+1){N=n;}
    void add(int i, _T v){for(int x=i;x<=N;x+=x&-x)bit[x]+=v;}
    _T sum(int i){_T r=0;for(int x=i;x>0;x-=x&-x)r+=bit[x];return r;}
    _T sum(int l,int r){return sum(r)-sum(l-1);}
};

int main(){
    const int MAX = 1000000;
    BIT<int> bit(MAX);
    int N, K; cin >> N >> K;
    REP(i,N){
        int W; cin >> W;
        if(W < 0){
            if(bit.sum(-W,-W) > 0) bit.add(-W,-1);
        } else {
            if(bit.sum(W,MAX) < K) bit.add(W,1);
        }
    }
    cout << bit.sum(MAX) << endl;
}
0