結果

問題 No.59 鉄道の旅
ユーザー なおなお
提出日時 2014-11-07 00:49:01
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 626 bytes
コンパイル時間 1,148 ms
コンパイル使用メモリ 144,576 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 05:29:01
合計ジャッジ時間 7,460 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAX = 1000000;
int bit[MAX+1];
void add(int a, int w){for(int x=a;x<=MAX;x+=x&-x)bit[x]+=w;}
int sum(int a){int ret=0;for(int x=a;x>0;x-=x&-x)ret+=bit[x];return ret;}
int rangesum(int l,int r){return sum(r)-sum(l-1);}

int main(){
    int N, K; cin >> N >> K;
    REP(i,N){
        int W; cin >> W;
        if(W < 0){
            if(rangesum(-W,-W) > 0) add(W,-1);
        } else {
            if(rangesum(W,MAX) < K) add(W,1);
        }
    }
    cout << sum(MAX) << endl;
    return 0;
}
0