結果

問題 No.59 鉄道の旅
ユーザー kou6839kou6839
提出日時 2014-12-19 19:41:36
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 933 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 73,960 KB
実行使用メモリ 75,616 KB
最終ジャッジ日時 2023-08-26 05:34:57
合計ジャッジ時間 6,614 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
65,840 KB
testcase_01 AC 121 ms
65,316 KB
testcase_02 AC 126 ms
65,908 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 132 ms
65,224 KB
testcase_06 WA -
testcase_07 AC 129 ms
65,380 KB
testcase_08 AC 247 ms
74,368 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 216 ms
73,768 KB
testcase_12 AC 431 ms
74,460 KB
testcase_13 AC 546 ms
75,616 KB
testcase_14 AC 482 ms
75,184 KB
testcase_15 AC 124 ms
65,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;
 
class BIT{
	int[] bit=new int[2000001];
    void add(int a,int w){;
    	for(int x = a;x<=2000000;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;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n= sc.nextInt();
        int k = sc.nextInt();
        BIT bit = new BIT();
        int[] aru = new int[1000001];
    	int ans=0;
        for(int i=0;i<n;i++){
        	int temp = sc.nextInt();
        	if(temp>0){
        		if( (bit.sum(2000000)-bit.sum(temp-1))>=k) continue;
        		bit.add(temp,1);
        		aru[temp]++;
        		ans++;
        	}else{
        		if(aru[-temp]>0) {
        			ans--;
        			bit.add(-temp,-1);
        		}
        	}
        }
        System.out.println(ans);
    }
}		
0