結果

問題 No.59 鉄道の旅
ユーザー ayame_pyayame_py
提出日時 2016-02-09 19:45:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 997 bytes
コンパイル時間 977 ms
コンパイル使用メモリ 144,240 KB
実行使用メモリ 7,352 KB
最終ジャッジ日時 2023-08-26 06:52:18
合計ジャッジ時間 1,788 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 19 ms
7,352 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 7 ms
7,260 KB
testcase_09 AC 7 ms
7,216 KB
testcase_10 AC 5 ms
6,912 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 14 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007
#define all(a) (a).begin(),(a).end()
#define MAX_N 1000010

//[1,n]
int n=MAX_N;
int bit[MAX_N+1];

int sum(int i){
    int s=0;
    while(i>0){
        s+=bit[i];
        i-=i&-i;
    }
    return s;
}

void add(int i, int x){
    while(i<=n){
        bit[i]+=x;
        i += i & -i;
    }
}


typedef long long ll;
typedef pair<int,int> p;

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};


int N,K,t;
int main(){
    ios::sync_with_stdio(false);
    cin >> N >> K;
    REP(i,N){
        cin >> t;
        //つむ
        if(t>0){
            int tmp = sum(MAX_N)-sum(t-1);
            if(K<=tmp) continue;
            add(t,1);
        }
        //おろす
        else{
            t=-t;
            if(sum(t)-sum(t-1)>0) add(t,-1);
        }
    }
    
    cout << sum(MAX_N) << endl;
    
    
    return 0;
}
0