結果

問題 No.59 鉄道の旅
ユーザー TAISA_TAISA_
提出日時 2018-06-01 12:37:26
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 986 bytes
コンパイル時間 1,180 ms
コンパイル使用メモリ 146,284 KB
実行使用メモリ 7,584 KB
最終ジャッジ日時 2023-09-12 21:17:03
合計ジャッジ時間 2,204 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,992 KB
testcase_01 AC 3 ms
6,996 KB
testcase_02 AC 4 ms
7,244 KB
testcase_03 AC 4 ms
6,924 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 5 ms
6,912 KB
testcase_12 AC 18 ms
7,148 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 3 ms
6,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
struct BinaryIndexedTree{
    vector<int> bit;
    BinaryIndexedTree(int siz){
        bit.assign(++siz,0);
    }

    int sum(int k){
        int ret=0;
        for(++k;k>0;k-=k&-k){
            ret+=bit[k];
        }
        return ret;
    }

    void add(int k,int x){
        for(++k;k<(int)bit.size();k+=k&-k){
            bit[k]+=x;
        }
    }
};
int main(){
	int n,k;cin>>n>>k;
	int w[100010];
	BinaryIndexedTree bit(1000010);
	for(int i=0;i<n;i++){
		cin>>w[i];
	}
	for(int i=0;i<n;i++){
		if(w[i]<0){
			if(bit.sum(-w[i])-bit.sum(-w[i]-1)<=0)continue;
			bit.add(-w[i],-1);
		}else{
			if(bit.sum(1000000)-bit.sum(w[i]-1)<k){
				bit.add(w[i],1);
			}
		}
	}
	cout<<bit.sum(100000)<<endl;
	return 0;
}
0