結果

問題 No.59 鉄道の旅
ユーザー motumotumotumotu
提出日時 2014-11-07 14:23:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 1,762 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 77,928 KB
実行使用メモリ 6,996 KB
最終ジャッジ日時 2023-08-26 05:30:23
合計ジャッジ時間 1,473 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,776 KB
testcase_01 AC 4 ms
6,804 KB
testcase_02 AC 3 ms
6,780 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 34 ms
6,672 KB
testcase_05 AC 3 ms
6,764 KB
testcase_06 AC 4 ms
6,744 KB
testcase_07 AC 3 ms
6,876 KB
testcase_08 AC 7 ms
6,740 KB
testcase_09 AC 7 ms
6,996 KB
testcase_10 AC 7 ms
6,772 KB
testcase_11 AC 5 ms
6,876 KB
testcase_12 AC 17 ms
6,880 KB
testcase_13 AC 35 ms
6,820 KB
testcase_14 AC 33 ms
6,900 KB
testcase_15 AC 4 ms
6,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <sstream>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define CLEAR(d) memset((d), 0, (sizeof((d))))
#define ALL(c) (c).begin(), (c).end()
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define SIZE(a) ((int)((a).size()))
#define MAX3(a, b, c) (max(max((a), (b)), (c)))
#define MIN3(a, b, c) (min(min((a), (b)), (c)))
#define MOD 1000000007
#define EPS 1e-5
#define PI  (acos(-1))
#define INF 10000000
struct edge{ int to, cost; };
//===================================================

#define MAX 1000010
// Binary Indexed Trees
template<class T> class BIT {
    vector<int> bit; int sz;
public:
    BIT(int n) : sz(n) { bit.resize(n + 1); }
    T sum(int i) { T s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; }
    T sum(int l, int r) { return sum(r) - sum(l - 1); }
    void add(int i, int x) { while (i <= sz) { bit[i] += x; i += i & -i; } }
};

int main()
{
    static BIT<int> bit(MAX);
    int n, k, w;
    cin >> n >> k;
    REP(i, n) {
        cin >> w;
        if (w > 0) {
            if (bit.sum(w, MAX) >= k) { continue; }
            bit.add(w, 1);
        }
        else {
            w = -w;
            if (bit.sum(w, w) == 0) { continue; }
            bit.add(w, -1);
        }
    }
    printf("%d\n", bit.sum(0, MAX));
    return 0;
}
0