結果

問題 No.59 鉄道の旅
ユーザー goodbatongoodbaton
提出日時 2015-07-29 22:31:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,229 bytes
コンパイル時間 1,079 ms
コンパイル使用メモリ 71,272 KB
実行使用メモリ 11,308 KB
最終ジャッジ日時 2023-08-26 06:30:15
合計ジャッジ時間 1,458 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,376 KB
testcase_01 AC 4 ms
7,448 KB
testcase_02 AC 4 ms
7,444 KB
testcase_03 AC 4 ms
7,364 KB
testcase_04 AC 29 ms
11,256 KB
testcase_05 AC 3 ms
7,448 KB
testcase_06 AC 4 ms
7,416 KB
testcase_07 AC 3 ms
7,520 KB
testcase_08 AC 10 ms
11,308 KB
testcase_09 AC 9 ms
11,212 KB
testcase_10 AC 9 ms
10,868 KB
testcase_11 AC 4 ms
7,384 KB
testcase_12 AC 11 ms
7,452 KB
testcase_13 AC 17 ms
7,656 KB
testcase_14 AC 18 ms
7,780 KB
testcase_15 AC 4 ms
7,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>

typedef long long ll;
using namespace std;

#define mod 1000003
#define INF 10000000
#define LLINF 2000000000000000000LL

#define SIZE 10000

/* BIT(1-index) */
const int BIT_SIZE=1000000;
int BIT_n=BIT_SIZE;

int BIT[BIT_SIZE+1];

void add(int k,int x){
    while(k<=BIT_n){
        BIT[k]+=x;
        k+= k&(-k);
    }
}

int query(int k){
    
    if(k==0) return 0;
    
    int rec=0;
    
    while(k>0){
        rec+=BIT[k];
        k-= k&(-k);
    }
    
    return rec;
}

int main(){
    int n,k;
    int on[1000001]={0},in;
    
    scanf("%d%d",&n,&k);
    
    for(int i=0;i<n;i++){
        scanf("%d",&in);
        
        if(in<0){
            in = abs(in);
            
            if(on[in]>0){
                on[in]--;
                add(in,-1);
            }
        }else{
            
            if(query(1000000)-query(in-1) < k){
                add(in,1);
                on[in]++;
            }
            
        }
    }
    
    printf("%d\n",query(1000000));
    
    return 0;
}
0