結果
問題 |
No.59 鉄道の旅
|
ユーザー |
|
提出日時 | 2017-01-13 02:12:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 24 ms / 5,000 ms |
コード長 | 766 bytes |
コンパイル時間 | 1,989 ms |
コンパイル使用メモリ | 166,344 KB |
実行使用メモリ | 7,424 KB |
最終ジャッジ日時 | 2024-12-25 15:29:52 |
合計ジャッジ時間 | 3,775 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int MAX_W = 1000000; //1-indexであることに注意 struct BIT { int n = MAX_W, bit[MAX_W + 1] = {}; int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; BIT b; for (int i = 0; i < N; i++) { int W; cin >> W; if (W > 0) { if (b.sum(MAX_W) - b.sum(W - 1) < K) b.add(W, 1); } else { if (b.sum(-W) > b.sum(-W - 1)) b.add(-W, -1); } } cout << b.sum(MAX_W) << endl; return 0; }