結果

問題 No.59 鉄道の旅
ユーザー TAISA_TAISA_
提出日時 2018-06-01 12:44:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 935 bytes
コンパイル時間 1,309 ms
コンパイル使用メモリ 146,276 KB
実行使用メモリ 7,772 KB
最終ジャッジ日時 2023-09-12 21:16:51
合計ジャッジ時間 2,662 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,944 KB
testcase_01 WA -
testcase_02 AC 4 ms
7,024 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 4 ms
6,864 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 5 ms
6,920 KB
testcase_12 AC 18 ms
7,084 KB
testcase_13 WA -
testcase_14 AC 35 ms
7,088 KB
testcase_15 AC 4 ms
7,068 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){
			bit.add(-w[i],0);
		}else{
			if(bit.sum(1000000)-bit.sum(w[i]-1)<k){
				bit.add(w[i],1);
			}
		}
	}
	cout<<bit.sum(1000000)<<endl;
	return 0;
}
0