結果

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

テストケース

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

ソースコード

diff #

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

using namespace std;

constexpr int N = 1e5 + 10;
int dat[N];

void add(int k, int v) {
  for (k++; k < N; k += k & -k) {
    dat[k] += v;
  }
}

int sum(int k) {
  int ret = 0;
  for (k++; k > 0; 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);

  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] >= 2) two++;
    if (x[i] >= 3) three++;
    if (x[i] == 2) {
      add(b[i], 1);
    }
  }

  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 = 1e5;
    int ng = -1;
    while (ok - ng > 1) {
      int mid = (ok + ng) / 2;
      if (sum(mid) + two >= m) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    ans = min(ans, sum(ok) + three);

    if (i == n) break;
    
    int j = i;
    while (i < n && a[p[i]] == a[p[j]]) {
      x[p[i]]++;
      if (x[p[i]] == 3) {
        add(b[p[i]], 1);
      } else if (x[p[i]] == 2) {
        add(b[p[i]], -1);
      }
      i++;
    }
  }

  cout << ans << endl;
}
0