結果

問題 No.59 鉄道の旅
ユーザー latte0119latte0119
提出日時 2015-10-26 18:58:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 144,248 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2023-08-26 06:49:17
合計ジャッジ時間 2,204 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,008 KB
testcase_01 AC 5 ms
12,108 KB
testcase_02 AC 5 ms
12,032 KB
testcase_03 AC 5 ms
12,120 KB
testcase_04 AC 43 ms
12,192 KB
testcase_05 AC 5 ms
12,104 KB
testcase_06 AC 5 ms
12,136 KB
testcase_07 AC 5 ms
12,164 KB
testcase_08 AC 9 ms
12,116 KB
testcase_09 AC 9 ms
12,032 KB
testcase_10 AC 9 ms
12,192 KB
testcase_11 AC 7 ms
12,012 KB
testcase_12 AC 19 ms
12,040 KB
testcase_13 AC 39 ms
12,192 KB
testcase_14 AC 38 ms
12,288 KB
testcase_15 AC 5 ms
12,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()

int bit_n,dat[1111111];
void init(int n){bit_n=n;memset(dat,0,sizeof(dat));}
void add(int k,int x){for(k++;k<=bit_n;k+=k&-k)dat[k]+=x;}
int sum(int k){int ret=0;for(k++;k;k-=k&-k)ret+=dat[k];return ret;}

signed main(){
    int N,K;
    cin>>N>>K;

    init(1010101);
    for(int i=0;i<N;i++){
        int W;cin>>W;
        if(W<0){
            W=abs(W);
            if(sum(W)-sum(W-1)>0)add(W,-1);
            continue;
        }

        int k=sum(1010101)-sum(W-1);
        if(k>=K)continue;
        add(W,1);
    }


    cout<<sum(1010101)<<endl;
    return 0;
}
0