結果

問題 No.59 鉄道の旅
ユーザー BantakoBantako
提出日時 2019-01-09 20:51:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 5,000 ms
コード長 986 bytes
コンパイル時間 1,610 ms
コンパイル使用メモリ 175,388 KB
実行使用メモリ 11,672 KB
最終ジャッジ日時 2023-08-15 16:58:58
合計ジャッジ時間 2,805 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,932 KB
testcase_01 AC 3 ms
6,972 KB
testcase_02 AC 3 ms
6,876 KB
testcase_03 AC 3 ms
7,020 KB
testcase_04 AC 65 ms
10,868 KB
testcase_05 AC 3 ms
7,160 KB
testcase_06 AC 3 ms
6,928 KB
testcase_07 AC 3 ms
7,024 KB
testcase_08 AC 8 ms
7,140 KB
testcase_09 AC 8 ms
7,452 KB
testcase_10 AC 8 ms
7,172 KB
testcase_11 AC 4 ms
7,028 KB
testcase_12 AC 17 ms
6,908 KB
testcase_13 AC 49 ms
10,568 KB
testcase_14 AC 55 ms
11,672 KB
testcase_15 AC 3 ms
6,884 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   20 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
struct BinaryIndexedTree{
   int N;
   std::vector<int> bit; //1-indexed
   BinaryIndexedTree(int n): N(n), bit(n+1, 0){}
   void add(int a, int w){
       for(int x = a; x <=N; x+=x&(-x)) bit[x] += w;
    }
   int sum(int a){ //1~aまでsum
        int ret = 0;
        for(int x = a; x>0; x-=x&(-x)) ret += bit[x];
        return ret;
    }
};
main(){
    int N,K;
    cin >> N >> K;
    int max_w = 1000000;
    BinaryIndexedTree bit(max_w);
    map<int,int> mp;
    rep(i,0,N){
        int w;
        cin >> w;
        if(w > 0){
            int cnt = bit.sum(max_w) - bit.sum(w-1);
            if(cnt >= K)continue;
            mp[w]++;
            bit.add(w, 1);
        }else{
            if(mp[-w] == 0)continue;
            mp[-w]--;
            bit.add(-w, -1);
        }
    }
    cout << bit.sum(max_w) << endl;
}
0