結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー pekempeypekempey
提出日時 2017-09-09 00:54:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 1,000 ms
コード長 1,588 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 81,868 KB
実行使用メモリ 5,656 KB
最終ジャッジ日時 2023-08-20 09:47:56
合計ジャッジ時間 3,585 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
5,420 KB
testcase_01 AC 72 ms
5,656 KB
testcase_02 AC 45 ms
4,380 KB
testcase_03 AC 41 ms
4,380 KB
testcase_04 AC 42 ms
4,376 KB
testcase_05 AC 24 ms
4,376 KB
testcase_06 AC 43 ms
4,380 KB
testcase_07 AC 45 ms
4,380 KB
testcase_08 AC 41 ms
4,380 KB
testcase_09 AC 25 ms
4,376 KB
testcase_10 AC 25 ms
4,380 KB
testcase_11 AC 44 ms
4,376 KB
testcase_12 AC 69 ms
5,524 KB
testcase_13 AC 77 ms
5,528 KB
testcase_14 AC 73 ms
5,516 KB
testcase_15 AC 81 ms
5,396 KB
testcase_16 AC 72 ms
5,076 KB
testcase_17 AC 68 ms
5,524 KB
testcase_18 AC 72 ms
5,252 KB
testcase_19 AC 74 ms
5,468 KB
testcase_20 AC 69 ms
5,544 KB
testcase_21 AC 77 ms
5,080 KB
testcase_22 AC 71 ms
5,348 KB
testcase_23 AC 43 ms
4,380 KB
testcase_24 AC 25 ms
4,380 KB
testcase_25 AC 24 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

template<class T>
struct FenwickTree {
  vector<T> dat;

  FenwickTree(int n) : dat(n + 1) {}

  void add(int k, T v) {
    for (k++; k > 0; k &= k - 1) {
      dat[k] += v;
    }
  }

  T sum(int k) {
    T ret = 0;
    for (k++; k < dat.size(); k += k & -k) {
      ret += dat[k];
    }
    return ret;
  }
};

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

  vector<int> p(n);
  vector<int> x(n), a(n), b(n);

  FenwickTree<int> ft1(1e5 + 10);
  FenwickTree<int> ft2(1e5 + 10);

  int two = 0;
  int three = 0;
  for (int i = 0; i < n; i++) {
    p[i] = i;
    scanf("%d %d %d", &x[i], &a[i], &b[i]);
    if (x[i] == 1) ft1.add(b[i], 1);
    if (x[i] == 2) ft2.add(b[i], 1);
    two += x[i] >= 2;
    three += x[i] == 3;
  }

  sort(p.begin(), p.end(), [&](int i, int j) {
    return a[i] > a[j];
  });

  int ans = 1e9;
  int k = 0;
  for (int i = 100001; i >= 0; i--) {
    while (k < n && a[p[k]] >= i) {
      int ii = p[k];
      x[ii]++;
      if (x[ii] == 3) {
        ft2.add(b[ii], -1);
        three++;
      } else if (x[ii] == 2) {
        ft2.add(b[ii], 1);
        ft1.add(b[ii], -1);
        two++;
      } else if (x[ii] == 1) {
        ft1.add(b[ii], 1);
      }
      k++;
    }
    int ok = 0;
    int ng = 1e5 + 2;
    while (ng - ok > 1) {
      int mid = (ok + ng) / 2;
      if (ft1.sum(mid) + two >= m) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    if (ft1.sum(ok) + two >= m) {
      ans = min(ans, ft2.sum(ok) + three);
    }
  }

  cout << ans << endl;
}
0