結果

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

テストケース

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

ソースコード

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=100000;
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[100001]={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