結果

問題 No.59 鉄道の旅
ユーザー nmnmnmnmnmnmnm
提出日時 2014-10-26 01:10:54
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 1,387 bytes
コンパイル時間 771 ms
コンパイル使用メモリ 86,528 KB
実行使用メモリ 7,432 KB
最終ジャッジ日時 2024-12-24 19:54:27
合計ジャッジ時間 1,458 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define MOD 1000000007
#define N_MAX 1000001
int bit[N_MAX + 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_MAX){
bit[i] += x;
i += i & -i;
}
}
int main(){
int ans = 0;
memset(bit, 0, sizeof(bit));
int n,k;
cin>>n>>k;
for(int i = 0; i < n; i++){
int w;
cin>>w;
if(w>=0){
int c = sum(1000000)-sum(w-1);
if(c<k){
add(w,1);
ans++;
}
}
else{
w = -w;
int c = sum(w)-sum(w-1);
if(c>0){
add(w,-1);
ans--;
}
}
}
cout << ans << endl;
return 0;
}
/*
BIT使
*/
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0