結果
問題 | No.59 鉄道の旅 |
ユーザー |
![]() |
提出日時 | 2015-07-29 22:31:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 30 ms / 5,000 ms |
コード長 | 1,229 bytes |
コンパイル時間 | 601 ms |
コンパイル使用メモリ | 72,320 KB |
実行使用メモリ | 11,520 KB |
最終ジャッジ日時 | 2024-12-24 21:42:16 |
合計ジャッジ時間 | 1,495 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
コンパイルメッセージ
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=1000000; 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[1000001]={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(1000000)-query(in-1) < k){ add(in,1); on[in]++; } } } printf("%d\n",query(1000000)); return 0; }