結果
問題 | No.59 鉄道の旅 |
ユーザー |
|
提出日時 | 2015-01-15 23:02:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 61 ms / 5,000 ms |
コード長 | 1,555 bytes |
コンパイル時間 | 916 ms |
コンパイル使用メモリ | 97,268 KB |
実行使用メモリ | 11,740 KB |
最終ジャッジ日時 | 2024-12-24 20:30:07 |
合計ジャッジ時間 | 1,674 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
#include <cstdio>#include <iostream>#include <sstream>#include <fstream>#include <iomanip>#include <algorithm>#include <cmath>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <set>#include <map>#include <bitset>#include <numeric>#include <limits>#include <climits>#include <cfloat>#include <functional>using namespace std;class BinaryIndexedTree{int n;vector<int> data;public:BinaryIndexedTree(int n){ // コンストラクタthis->n = n;data.assign(n+1, 0);}void add(int k, int x){ // k番目の要素にxを加算する++ k;while(k <= n){data[k] += x;k += k & -k;}}int sum(int k){ // 区間[0,k]の総和を返す++ k;int ret = 0;while(k > 0){ret += data[k];k -= k & -k;}return ret;}int sum(int a, int b){ // 区間[a,b]の総和を返すreturn sum(b) - sum(a-1);}};int main(){int n, k;cin >> n >> k;multiset<int> ms;BinaryIndexedTree b(1000001);while(--n >= 0){int w;cin >> w;if(w > 0){if(b.sum(w, 1000000) < k){ms.insert(w);b.add(w, 1);}}else{auto it = ms.find(-w);if(it != ms.end()){ms.erase(it);b.add(-w, -1);}}}cout << ms.size() << endl;return 0;}