結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー TangentDayTangentDay
提出日時 2017-09-08 23:58:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 73 ms / 1,000 ms
コード長 2,937 bytes
コンパイル時間 1,280 ms
コンパイル使用メモリ 86,776 KB
実行使用メモリ 5,868 KB
最終ジャッジ日時 2023-08-20 09:13:15
合計ジャッジ時間 3,928 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
5,744 KB
testcase_01 AC 73 ms
5,736 KB
testcase_02 AC 23 ms
4,668 KB
testcase_03 AC 23 ms
4,664 KB
testcase_04 AC 23 ms
4,712 KB
testcase_05 AC 29 ms
4,668 KB
testcase_06 AC 23 ms
4,676 KB
testcase_07 AC 23 ms
4,684 KB
testcase_08 AC 3 ms
4,680 KB
testcase_09 AC 30 ms
4,676 KB
testcase_10 AC 29 ms
4,692 KB
testcase_11 AC 24 ms
4,660 KB
testcase_12 AC 71 ms
5,740 KB
testcase_13 AC 73 ms
5,664 KB
testcase_14 AC 71 ms
5,724 KB
testcase_15 AC 66 ms
5,736 KB
testcase_16 AC 71 ms
5,736 KB
testcase_17 AC 70 ms
5,812 KB
testcase_18 AC 72 ms
5,728 KB
testcase_19 AC 71 ms
5,724 KB
testcase_20 AC 71 ms
5,668 KB
testcase_21 AC 70 ms
5,868 KB
testcase_22 AC 72 ms
5,736 KB
testcase_23 AC 23 ms
4,672 KB
testcase_24 AC 29 ms
4,680 KB
testcase_25 AC 29 ms
4,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int INF = 1e9;
const int M = 1e5 + 10;

struct BIT{
    int n;
    VL bit;

    BIT(){}
    BIT(int x){
        n = x;
        bit.resize(x+1);
    }

    void init(int x){
        n = x;
        bit.resize(x+1);
    }

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

    // [0, i]
    ll sum(int i){
        i++;
        ll ret = 0;
        while (i > 0){
            ret += bit[i];
            i -= i & -i;
        }
        return ret;
    }

    // [l, r)
    ll sum(int l, int r){
        if (l >= r) return 0;
        return sum(r-1) - sum(l-1);
    }
};

int main(){
    int n, m;
    cin >> n >> m;

    vector<pair<P, int> > p(n);
    REP(i,n) scanf("%d %d %d", &p[i].second, &p[i].first.first, &p[i].first.second);

    sort(ALL(p));
    reverse(ALL(p));

    int solve[5] = {};
    REP(i,n) solve[p[i].second]++;

    BIT one_BIT(M), two_BIT(M);

    REP(i,n){
        if (p[i].second == 1){
            one_BIT.add(p[i].first.second, 1);
        }
        if (p[i].second == 2){
            two_BIT.add(p[i].first.second, 1);
        }
    }

    // cout << endl;
    // REP(i,n) cout << p[i].second << " " << p[i].first.first << " " << p[i].first.second << endl;

    int ans = INF;
    int j = 0;
    FORR(a,M-1,0){
        while (j < n && p[j].first.first >= a){
            int b = p[j].first.second;
            int x = p[j].second;
            if (x == 0){
                one_BIT.add(b, 1);
            }
            if (x == 1){
                one_BIT.add(b, -1);
                two_BIT.add(b, 1);
            }
            if (x == 2){
                two_BIT.add(b, -1);
            }
            if (x < 3){
                solve[x]--;
                solve[x+1]++;
            }
            j++;
        }
        // cout << a << endl;
        // REP(i,4) cout << solve[i] << " ";
        // cout << endl;
        if (solve[3] + solve[2] + solve[1] < m) continue;
        int ok = 0, ng = M-1;
        while (ng - ok > 1){
            int mi = (ok + ng) / 2;
            if (solve[3] + solve[2] + one_BIT.sum(mi, M) >= m) ok = mi;
            else ng = mi;
        }
        // cout << ok << "  three " << solve[3] + two_BIT.sum(ok, M) << endl;
        ans = min(ans, solve[3] + (int)two_BIT.sum(ok, M));
    }
    cout << ans << endl;

    return 0;
}
0