結果

問題 No.59 鉄道の旅
ユーザー EmKjpEmKjp
提出日時 2015-03-21 14:45:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,522 bytes
コンパイル時間 584 ms
コンパイル使用メモリ 78,100 KB
実行使用メモリ 7,188 KB
最終ジャッジ日時 2023-08-26 05:37:17
合計ジャッジ時間 1,506 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,036 KB
testcase_01 AC 3 ms
7,064 KB
testcase_02 AC 4 ms
6,880 KB
testcase_03 AC 4 ms
7,188 KB
testcase_04 AC 19 ms
6,980 KB
testcase_05 AC 3 ms
6,924 KB
testcase_06 AC 4 ms
7,040 KB
testcase_07 AC 3 ms
6,960 KB
testcase_08 AC 5 ms
7,184 KB
testcase_09 AC 4 ms
7,040 KB
testcase_10 AC 5 ms
6,948 KB
testcase_11 AC 4 ms
7,044 KB
testcase_12 AC 10 ms
6,928 KB
testcase_13 AC 18 ms
6,972 KB
testcase_14 AC 18 ms
6,920 KB
testcase_15 AC 3 ms
6,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>

using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename T>
struct BIT
{
    vector<T> data;
    BIT(int size) :data(size + 1){}
    T sum(T a, T b){ // [a..b]
        if (a == 0){
            T val = 0;
            for (; b >= 0; b = (b&(b + 1)) - 1) val += data[b];
            return val;
        }
        else{
            return sum(0, b) - sum(0, a - 1);
        }
    }

    void add(int k, T val)
    {
        for (; k < (int)data.size(); k |= k + 1) {
            data[k] += val;
        }
    }
};

int main()
{
    int N,K;
    cin>>N>>K;
    int maxSize = 1000000+10;    
    BIT<int> bit(maxSize + 1);
    FOR(i,N){
        int w;
        scanf("%d",&w);
        if(w > 0){
            if(bit.sum(w, maxSize) < K) {
                bit.add(w, 1);
            }
        }else {
            if(bit.sum(-w, -w) > 0){
                bit.add(-w, -1);
            }
        }
    }
    cout<<bit.sum(0, maxSize)<<endl;
    return 0;
}
0