結果

問題 No.59 鉄道の旅
ユーザー kosakkunkosakkun
提出日時 2016-12-14 00:48:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 1,615 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 94,836 KB
実行使用メモリ 14,780 KB
最終ジャッジ日時 2023-08-26 08:00:22
合計ジャッジ時間 1,810 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,704 KB
testcase_01 AC 5 ms
10,612 KB
testcase_02 AC 5 ms
10,720 KB
testcase_03 AC 5 ms
10,612 KB
testcase_04 AC 44 ms
14,688 KB
testcase_05 AC 5 ms
10,860 KB
testcase_06 AC 6 ms
10,916 KB
testcase_07 AC 5 ms
10,624 KB
testcase_08 AC 12 ms
14,780 KB
testcase_09 AC 13 ms
14,380 KB
testcase_10 AC 12 ms
14,168 KB
testcase_11 AC 7 ms
10,604 KB
testcase_12 AC 19 ms
10,736 KB
testcase_13 AC 34 ms
11,368 KB
testcase_14 AC 34 ms
11,444 KB
testcase_15 AC 6 ms
10,588 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