結果
問題 | No.59 鉄道の旅 |
ユーザー |
![]() |
提出日時 | 2015-03-05 17:53:24 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 23 ms / 5,000 ms |
コード長 | 596 bytes |
コンパイル時間 | 653 ms |
コンパイル使用メモリ | 24,448 KB |
実行使用メモリ | 5,504 KB |
最終ジャッジ日時 | 2024-12-24 20:33:27 |
合計ジャッジ時間 | 1,363 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:25:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | int w; scanf("%d", &w); | ~~~~~^~~~~~~~~~
ソースコード
#include <cstdio>#include <cstring>const int maxw=1000001;int b[maxw];void add(int i, int x){while (i<maxw) { b[i]+=x; i+=i&-i; }}int sum(int i){int res=0;while (i>0) { res+=b[i]; i-=i&-i; }return res;}int main(){int n, k;while (~scanf("%d%d", &n, &k)) {memset(b, 0, sizeof(b));while (n--) {int w; scanf("%d", &w);if (w>0 and sum(maxw)-sum(w-1)<k)add(w, 1);else if (w<0 and sum(-w)-sum(-w-1)>0)add(-w, -1);}printf("%d\n", sum(maxw));}}