結果
| 問題 | No.59 鉄道の旅 |
| コンテスト | |
| ユーザー |
fiord
|
| 提出日時 | 2015-07-31 01:28:14 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 5,000 ms |
| コード長 | 635 bytes |
| 記録 | |
| コンパイル時間 | 977 ms |
| コンパイル使用メモリ | 174,760 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2026-05-30 16:12:36 |
| 合計ジャッジ時間 | 1,966 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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