結果
| 問題 | 
                            No.59 鉄道の旅
                             | 
                    
| コンテスト | |
| ユーザー | 
                             kosakkun
                         | 
                    
| 提出日時 | 2016-12-14 00:49:16 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 37 ms / 5,000 ms | 
| コード長 | 1,616 bytes | 
| コンパイル時間 | 748 ms | 
| コンパイル使用メモリ | 95,336 KB | 
| 実行使用メモリ | 15,104 KB | 
| 最終ジャッジ日時 | 2024-12-25 00:43:47 | 
| 合計ジャッジ時間 | 1,550 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 12 | 
ソースコード
#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;
}
            
            
            
        
            
kosakkun