NC235569 牛可乐与NCPC
题目
- 原题地址:牛可乐与NCPC
- 题目编号:NC235569
- 题目类型:set、偏序相关
- 时间限制:C/C++ 1秒,其他语言2秒
- 空间限制:C/C++ 262144K,其他语言524288K
1.题目大意
-
\(n\) 支队伍,第 \(i\) 支队伍有 \(a_i\) 和 \(b_i\),如果列表中不存在一支队伍 \(j\) 使得 \(a_j\leq a_i,b_j<b_i\) 或者 \(a_j< a_i,b_j\leq b_i\),则 \(i\) 进入列表
-
不存在的类型如下图红色区域(边界不同时满足):
![]()
-
如果存在 \(j\) 且 \(i\) 也在列表中,则移除 \(j\)
-
求每支队伍进场后列表中有几只队伍
2.题目分析
multiset中按照a从小到大排序,a相同时b小的在前面- 如果大于该队伍的最小值在
set开头或者它的前一个的b要大于当前队(返回值等于end时对应的end--才是最后一个元素)则入队 - 入队后查看是否对其他队有影响,把不符合提题意的都移除
- 最后还是加了加速优化才过,今天的测评机不大行啊
3.题目代码
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
typedef struct te{
int a, b;
bool operator< (const te &p) const{
return a==p.a?b<p.b:a<p.a;
}
}te;
int main() {
IOS;
int t, n, a, b;
cin >> t;
for(int i=1;i<=t;i++) {
cin >> n;
cout << "Case #" << i << ':' << endl;
multiset<te> ms;
for(int j=0;j<n;j++) {
cin >> a >> b; te tt = {a, b};
auto it = ms.lower_bound(tt);
if(it==ms.begin()||(--it)->b>b){
ms.insert(tt);
it = ms.upper_bound(tt);
while(it!=ms.end()&&it->b>=b) ms.erase(it++);
}
cout << ms.size() << endl;
}
cout << endl;
}
}

牛可乐举办了一场名为 NCPC 的比赛,有 n 支队伍前来参赛,每只队伍的能力可以由两个整数 ai,bi 描述。对于一支队伍 i,如果不存在另外一支队伍 j 满足 aj≤ai,bj

浙公网安备 33010602011771号