結果
問題 |
No.59 鉄道の旅
|
ユーザー |
![]() |
提出日時 | 2015-09-30 16:19:55 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 958 bytes |
コンパイル時間 | 1,494 ms |
コンパイル使用メモリ | 157,788 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-12-24 21:56:04 |
合計ジャッジ時間 | 2,552 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 8 WA * 4 |
ソースコード
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(int i=0; i<(n); i++) #define RREP(i, n) for(int i=(n-1); i>=0; i--) template<int ME> class BIT { public: int bits[1<<ME]; int sum(int i) { int ret = 0; while(i > 0) { ret += bits[i]; i -= i & -i; } return ret; } int total() { return sum((1<<ME)-1); } void add(int i, int add) { while(i < 1<<ME) { bits[i] += add; i += i & -i; } } }; BIT<20> bt; int N,K,W; signed main() { cin>>N>>K; REP(i,N) { cin >> W; int j = abs(W); if (W > 0) { if (bt.total() - bt.sum(j-1) < K) { bt.add(j,1); } } else { // あれば下ろせる if (bt.bits[j] > 0) { bt.add(j,-1); } } } cout << bt.total() << endl; return 0; }