結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー pekempeypekempey
提出日時 2017-09-08 23:21:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,650 bytes
コンパイル時間 938 ms
コンパイル使用メモリ 84,792 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-24 21:29:11
合計ジャッジ時間 2,875 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
5,632 KB
testcase_01 AC 61 ms
5,632 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 59 ms
5,632 KB
testcase_13 AC 63 ms
5,760 KB
testcase_14 AC 62 ms
5,760 KB
testcase_15 WA -
testcase_16 AC 59 ms
5,632 KB
testcase_17 AC 56 ms
5,760 KB
testcase_18 AC 60 ms
5,760 KB
testcase_19 AC 62 ms
5,632 KB
testcase_20 AC 56 ms
5,760 KB
testcase_21 AC 62 ms
5,632 KB
testcase_22 AC 61 ms
5,632 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

template<class T>
struct FenwickTree {
  std::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) {
      two++;
      ft2.add(b[i], 1);
    }
    if (x[i] == 3) {
      two++;
      three++;
    }
  }

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

  int ans = 1e9;
  int i = 0;
  while (i <= n) {
    int ok = 0;
    int ng = 1e5 + 5;
    while (ng - ok > 1) {
      int mid = (ok + ng) / 2;
      if (ft1.sum(mid) + two >= m) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    ans = min(ans, ft2.sum(ok) + three);

    if (i == n) break;
    
    int j = i;
    while (i < n && a[p[i]] == a[p[j]]) {
      int ii = p[i];
      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);
      }
      i++;
    }
  }

  cout << ans << endl;
}
0