結果
| 問題 |
No.59 鉄道の旅
|
| コンテスト | |
| ユーザー |
goodbaton
|
| 提出日時 | 2015-07-29 22:30:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,225 bytes |
| コンパイル時間 | 632 ms |
| コンパイル使用メモリ | 71,796 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-24 21:41:20 |
| 合計ジャッジ時間 | 3,675 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 2 RE * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:54:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
54 | scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:57:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
57 | scanf("%d",&in);
| ~~~~~^~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>
typedef long long ll;
using namespace std;
#define mod 1000003
#define INF 10000000
#define LLINF 2000000000000000000LL
#define SIZE 10000
/* BIT(1-index) */
const int BIT_SIZE=100000;
int BIT_n=BIT_SIZE;
int BIT[BIT_SIZE+1];
void add(int k,int x){
while(k<=BIT_n){
BIT[k]+=x;
k+= k&(-k);
}
}
int query(int k){
if(k==0) return 0;
int rec=0;
while(k>0){
rec+=BIT[k];
k-= k&(-k);
}
return rec;
}
int main(){
int n,k;
int on[100001]={0},in;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%d",&in);
if(in<0){
in = abs(in);
if(on[in]>0){
on[in]--;
add(in,-1);
}
}else{
if(query(100000)-query(in-1) < k){
add(in,1);
on[in]++;
}
}
}
printf("%d\n",query(100000));
return 0;
}
goodbaton