結果
問題 |
No.59 鉄道の旅
|
ユーザー |
![]() |
提出日時 | 2015-08-17 16:40:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 43 ms / 5,000 ms |
コード長 | 743 bytes |
コンパイル時間 | 1,661 ms |
コンパイル使用メモリ | 159,688 KB |
実行使用メモリ | 7,136 KB |
最終ジャッジ日時 | 2024-12-24 21:47:52 |
合計ジャッジ時間 | 2,678 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; class BIT { private: vector<int> v; public: BIT(int n) : v(vector<int>(n + 1, 0)) {} // [0, i) int sum(int i) { return i ? v[i] + sum(i & (i - 1)) : 0; } // [a, b) int sum(int a, int b) { return sum(b) - sum(a); } void add(int i, int x) { for (++i; i < (int)v.size(); i += i & -i) v[i] += x; } }; int main() { int n, k; cin >> n >> k; BIT bit(1000001); int res = 0; for (int i = 0; i < n; ++i) { int w; cin >> w; if (w > 0) { if (bit.sum(w, 1000001) >= k) continue; bit.add(w, 1); ++res; } else { if (bit.sum(-w, -w + 1) == 0) continue; bit.add(-w, -1); --res; } } cout << res << endl; }