結果
| 問題 |
No.568 じゃんじゃん 落とす 委員会
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-20 17:21:42 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 96 ms / 1,000 ms |
| コード長 | 1,751 bytes |
| コンパイル時間 | 3,403 ms |
| コンパイル使用メモリ | 277,164 KB |
| 実行使用メモリ | 18,176 KB |
| 最終ジャッジ日時 | 2025-05-20 17:21:51 |
| 合計ジャッジ時間 | 7,176 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
/*
* Author: ttq012
* Date: 05/20/2025
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 500010;
const int mod = 1e9 + 7;
vector<int> v[N];
int x[N], a[N], b[N];
struct BIT
{
int tree[N];
BIT()
{
memset(tree, 0, sizeof tree);
}
void add(int x, int v)
{
++x;
for (; x < N; x += (x &- x))
tree[x] += v;
}
int query(int x)
{
++x;
int s = 0;
for (; x; x -= (x &- x))
s += tree[x];
return s;
}
} fwt, fwt2;
signed main()
{
cin.tie(0)->sync_with_stdio(false);
int n, m, res = 1e18;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> x[i] >> a[i] >> b[i];
for (int i = 1; i <= n; ++i)
v[a[i]].emplace_back(i);
int cnt = 0;
for (int i = 1; i <= n; ++i)
if (x[i] == 1)
fwt.add(b[i], 1);
else if (x[i] == 2)
fwt2.add(b[i], 1);
else if (x[i] == 3)
++cnt;
for (int i = 100001; ~i; --i)
{
for (int &j : v[i])
if (x[j] == 1)
fwt.add(b[j], -1), fwt2.add(b[j], 1);
else if (x[j] == 2)
fwt2.add(b[j], -1), ++cnt;
else if (!x[j])
fwt.add(b[j], 1);
int l = 0, r = 100001, best = -1;
while (l <= r)
{
int mid = l + r >> 1;
int oo = cnt + fwt.query(N - 1) + fwt2.query(N - 1) - fwt.query(mid - 1);
if (oo >= m)
l = mid + 1, best = mid;
else
r = mid - 1;
}
if (~best)
res = min(res, cnt + fwt2.query(N - 1) - fwt2.query(best - 1));
}
cout << res << '\n';
return 0;
}