結果
| 問題 |
No.59 鉄道の旅
|
| コンテスト | |
| ユーザー |
fiord
|
| 提出日時 | 2015-07-31 01:28:14 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 5,000 ms |
| コード長 | 635 bytes |
| コンパイル時間 | 1,897 ms |
| コンパイル使用メモリ | 157,656 KB |
| 実行使用メモリ | 11,264 KB |
| 最終ジャッジ日時 | 2024-12-24 21:43:21 |
| 合計ジャッジ時間 | 2,715 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
class bit{
public:
int dp[1<<20];
void init(){
memset(dp,0,sizeof(dp));
}
int call(int x){
int ret=0;
while(x>0){
ret+=dp[x];
x&=x-1;
}
return ret;
}
void add(int x,int y){
while(x<1<<20){
dp[x]+=y;
x+=x-(x&(x-1));
}
}
};
int num[1<<20];
bit data;
int main(){
int n,k; cin>>n>>k;
int cnt=0;
for(int i=0;i<n;i++){
int w; cin>>w;
if(w<0){
w*=-1;
if(num[w]<=0) continue;
num[w]--;
data.add(w,-1);
cnt--;
}
else{
if(cnt-data.call(w-1)>=k) continue;
num[w]++;
data.add(w,1);
cnt++;
}
}
cout<<cnt<<endl;
return 0;
}
fiord