結果

問題 No.59 鉄道の旅
ユーザー kosakkunkosakkun
提出日時 2016-12-14 00:49:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 1,616 bytes
コンパイル時間 789 ms
コンパイル使用メモリ 93,532 KB
実行使用メモリ 15,056 KB
最終ジャッジ日時 2023-08-26 08:00:30
合計ジャッジ時間 1,749 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,696 KB
testcase_01 AC 6 ms
10,720 KB
testcase_02 AC 5 ms
10,848 KB
testcase_03 AC 5 ms
10,768 KB
testcase_04 AC 42 ms
14,736 KB
testcase_05 AC 5 ms
10,720 KB
testcase_06 AC 5 ms
10,836 KB
testcase_07 AC 5 ms
10,664 KB
testcase_08 AC 11 ms
15,056 KB
testcase_09 AC 14 ms
14,292 KB
testcase_10 AC 12 ms
14,224 KB
testcase_11 AC 6 ms
10,916 KB
testcase_12 AC 17 ms
10,820 KB
testcase_13 AC 34 ms
11,040 KB
testcase_14 AC 36 ms
11,336 KB
testcase_15 AC 5 ms
10,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
using namespace std;
typedef long long ll;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))

template <class T> class FenwickTree{
    vector<T> bit_sum; int size;
public:
    FenwickTree(int _size){ size=_size+1; bit_sum = *new vector<T>(size,0); }
    void add(int i, T x){ while(i<=size){ bit_sum[i] += x; i+=i&-i; } }
    T getsum(int i){ T res=0; while(i>0) { res+=bit_sum[i]; i-=i&-i; } return res; }
};

int wcnt[1000010];
FenwickTree<int> inst(1000010);

int main(){
    
    int N,K; cin>>N>>K;
    
    REP(i,N){
        int w; cin>>w;
        if(w<0){
            if(wcnt[abs(w)]>0){
                wcnt[abs(w)]--;
                inst.add(abs(w),-1);
            }
        }else{
            int sum=inst.getsum(1000010)-inst.getsum(abs(w)-1);
            if(sum<K){
                wcnt[abs(w)]++;
                inst.add(abs(w),1);
            }
        }
    }
    
    cout<<inst.getsum(1000010)<<endl;
    
    return 0;
}
0