結果
| 問題 | No.568 じゃんじゃん 落とす 委員会 |
| コンテスト | |
| ユーザー |
TangentDay
|
| 提出日時 | 2017-09-08 23:58:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 72 ms / 1,000 ms |
| コード長 | 2,937 bytes |
| 記録 | |
| コンパイル時間 | 843 ms |
| コンパイル使用メモリ | 91,416 KB |
| 実行使用メモリ | 6,144 KB |
| 最終ジャッジ日時 | 2024-11-30 10:42:05 |
| 合計ジャッジ時間 | 3,209 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:77:19: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
77 | REP(i,n) scanf("%d %d %d", &p[i].second, &p[i].first.first, &p[i].first.second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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;
}
TangentDay