結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー parukiparuki
提出日時 2017-09-11 08:36:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 1,000 ms
コード長 2,135 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 170,104 KB
実行使用メモリ 10,428 KB
最終ジャッジ日時 2023-08-20 09:49:06
合計ジャッジ時間 5,555 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
10,428 KB
testcase_01 AC 143 ms
10,328 KB
testcase_02 AC 58 ms
7,088 KB
testcase_03 AC 57 ms
7,252 KB
testcase_04 AC 55 ms
7,144 KB
testcase_05 AC 65 ms
7,068 KB
testcase_06 AC 55 ms
7,100 KB
testcase_07 AC 58 ms
7,068 KB
testcase_08 AC 9 ms
7,364 KB
testcase_09 AC 64 ms
7,368 KB
testcase_10 AC 66 ms
7,220 KB
testcase_11 AC 59 ms
7,164 KB
testcase_12 AC 125 ms
10,428 KB
testcase_13 AC 135 ms
10,384 KB
testcase_14 AC 130 ms
10,384 KB
testcase_15 AC 120 ms
10,332 KB
testcase_16 AC 130 ms
10,120 KB
testcase_17 AC 123 ms
10,072 KB
testcase_18 AC 128 ms
10,092 KB
testcase_19 AC 134 ms
10,388 KB
testcase_20 AC 126 ms
10,360 KB
testcase_21 AC 126 ms
10,148 KB
testcase_22 AC 128 ms
10,380 KB
testcase_23 AC 55 ms
7,304 KB
testcase_24 AC 65 ms
7,072 KB
testcase_25 AC 65 ms
7,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<class Val>
struct BinaryIndexedTree {
    int n;
    vector<Val> t;
    BinaryIndexedTree() {}
    BinaryIndexedTree(int _n) :n(_n + 1), t(_n + 1) {}
    void add(int k, Val val) {
        k++;
        while (k < n) {
            t[k] += val;
            k += (k&-k);
        }
    }
    void set(int k, Val val) {
        add(k, -sum(k, k + 1));
        add(k, val);
    }
    Val sum(int k) {
        Val r = 0;
        while (k > 0) {
            r += t[k];
            k -= (k&-k);
        }
        return r;
    }
    Val sum(int l, int r) {
        return sum(r) - sum(l);
    }
};

const int R = 100002;
BinaryIndexedTree<int> sum[5];
vi aid[R];

int f(int b, int mi) {
    int res = 0;
    rep(i, 5) {
        if (i >= mi)res += sum[i].sum(0, R);
        else if (i + 1 >= mi)res += sum[i].sum(b, R);
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    rep(i, 5)sum[i] = BinaryIndexedTree<int>(R);

    int N, M;
    cin >> N >> M;

    vi X(N), A(N), B(N);
    rep(i, N) {
        cin >> X[i] >> A[i] >> B[i];
        aid[A[i]].push_back(i);
        sum[X[i]].add(B[i], 1);
    }

    int ans = INT_MAX;
    for (int a = R - 1; a >= 0; --a) {
        each(i, aid[a]) {
            sum[X[i]].add(B[i], -1);
            sum[X[i] + 1].add(B[i], 1);
        }

        if (f(0, 2) < M)continue;
        int ok = 0, ng = R, mid;
        while (ng - ok > 1) {
            mid = (ok + ng) / 2;
            (f(mid, 2) >= M ? ok : ng) = mid;
        }

        smin(ans, f(ok, 3));
    }

    cout << ans << endl;
}
0