結果

問題 No.59 鉄道の旅
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-20 02:50:28
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,368 bytes
コンパイル時間 1,117 ms
コンパイル使用メモリ 107,476 KB
実行使用メモリ 6,520 KB
最終ジャッジ日時 2023-08-11 10:11:45
合計ジャッジ時間 3,893 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>

using namespace std;

//RSQ (0-indexed)
template<class T> struct BIT {
    vector<T> bit;
    long long N;
    T P;

    BIT (long long n, T p = 0){
        N = n;
        P = p;
        bit.resize(N);
    }

    void add(long long loc, T val){
        loc++;
        while(loc <= N){
            bit[loc-1] += val;
            if (P) bit[loc-1] %= P;
            loc += loc & -loc;
        }
    }

    long long sum(long long l, long long r){
        T res = _sum(r) - _sum(l-1);
        if (P) res = (res + P) % P;
        return res;
    }

    long long _sum(long long r){
        r++;
        T res = 0;
        while(r > 0){
            res += bit[r-1];
            if (P) res %= P;
            r -= r & -r;
        }
        return res;
    }
};

int main(){
 
    long long N, K, W, cnt;
    cin >> N >> K;
    BIT<long long> tree(100001);

    for (int i=0; i<N; i++){
        cin >> W;
        if (W > 0){
            cnt = tree.sum(W, 100000);
            if (cnt < K) tree.add(W, 1);
        }
        else{
            W *= -1;
            if (tree.sum(W, W) > 0) tree.add(W, -1);
        }
    }

    cout << tree.sum(0, 100000) << endl;

    return 0;
}
0