結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,512 KB
testcase_01 AC 4 ms
7,448 KB
testcase_02 AC 4 ms
7,364 KB
testcase_03 AC 3 ms
7,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 4 ms
7,372 KB
testcase_12 AC 12 ms
7,516 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 3 ms
7,416 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(100000)-query(in-1) < k){
                add(in,1);
                on[in]++;
            }
            
        }
    }
    
    printf("%d\n",query(100000));
    
    return 0;
}
0