結果

問題 No.59 鉄道の旅
ユーザー TwizzTwizz
提出日時 2017-05-26 22:38:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 852 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 60,688 KB
実行使用メモリ 7,624 KB
最終ジャッジ日時 2023-10-20 00:19:32
合計ジャッジ時間 1,350 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,564 KB
testcase_01 AC 4 ms
7,564 KB
testcase_02 AC 4 ms
7,564 KB
testcase_03 AC 4 ms
7,564 KB
testcase_04 AC 42 ms
7,564 KB
testcase_05 AC 4 ms
7,568 KB
testcase_06 AC 4 ms
7,568 KB
testcase_07 AC 3 ms
7,568 KB
testcase_08 AC 8 ms
7,604 KB
testcase_09 AC 8 ms
7,604 KB
testcase_10 AC 8 ms
7,604 KB
testcase_11 AC 5 ms
7,604 KB
testcase_12 AC 20 ms
7,624 KB
testcase_13 AC 41 ms
7,624 KB
testcase_14 AC 39 ms
7,624 KB
testcase_15 AC 3 ms
7,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
//[1,n]
const int MAX_W = 1000010;
int bit[MAX_W + 1];

int sum(int i){//iまでの和を求める
    int s = 0;
    while(i > 0){
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add(int i, int x){//iの値にxを加える
    while(i <= MAX_W){
        bit[i] += x;
        i += i & -i;
    }
}

int main(void){
    int n, k; cin >> n >> k;
    vector<int> w(n);
    rep(i, MAX_W + 1) bit[i] = 0;
    rep(i, n){
        int w; cin >> w;
        if(w > 0){
            if(sum(MAX_W) - sum(w - 1) < k){
                add(w, 1);
            }
        }else{
            if(sum(-w) - sum(-w - 1) >= 1){
                add(-w, -1);
            }
        }
    }
    cout << sum(MAX_W) << endl;
    return 0;
}
0