結果

問題 No.59 鉄道の旅
ユーザー CleyLCleyL
提出日時 2022-08-17 00:41:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 2,229 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 111,972 KB
実行使用メモリ 42,428 KB
最終ジャッジ日時 2024-04-14 18:16:45
合計ジャッジ時間 2,312 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
42,264 KB
testcase_01 AC 12 ms
42,256 KB
testcase_02 AC 12 ms
42,228 KB
testcase_03 AC 12 ms
42,420 KB
testcase_04 AC 31 ms
42,388 KB
testcase_05 AC 12 ms
42,428 KB
testcase_06 AC 12 ms
42,284 KB
testcase_07 AC 12 ms
42,284 KB
testcase_08 AC 15 ms
42,328 KB
testcase_09 AC 14 ms
42,232 KB
testcase_10 AC 14 ms
42,352 KB
testcase_11 AC 12 ms
42,404 KB
testcase_12 AC 20 ms
42,248 KB
testcase_13 AC 28 ms
42,324 KB
testcase_14 AC 28 ms
42,356 KB
testcase_15 AC 12 ms
42,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//yukicoder@cpp17

#include <iostream>

#include <cmath>
#include <algorithm>

#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>

#include <bitset>

#include <complex>

#include <cctype>
#include <utility>
#include <climits>

#include <numeric>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);

P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};




template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
 
 /*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/

/*
function corner below
*/

//B
template<typename T>
struct BIT{//1_Indexed
    int n;
    vector<T> bit;
    BIT(int n_):n(n_+1),bit(n,0){}

    T sum(int a){
        int ret = 0;
        for(int i = a; i > 0; i -= i & -i) ret += bit[i];
        return ret;
    }

    void add(int a,int w){
        for(int i = a; i <= n; i += i & -i)bit[i] += w;
    }

    T query(int r,int l){
        return sum(l-1)-sum(r-1);
    }

};
//E

/*
Function corner above
*/

__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}

int main(){
    int n,k;cin>>n>>k;
    int ans = 0;
    BIT<int> A(10000001);
    for(int i = 0; n > i; i++){
        int x;cin>>x;
        if(x < 0){
            x*=-1;
            auto z = A.query(x,x+1);
            if(z){
                A.add(x,-1);
                ans--;
            }
        }else{
            auto z = A.query(x,10000000);
            if(z >= k)continue;
            A.add(x,1);
            ans++;
        }
    }
    cout << ans << endl;
}

0