Codeforces Round #443 (Div. 2) E. Tournament
来源:互联网 发布:淘宝网络科技有限公司 编辑:程序博客网 时间:2024/05/18 03:19
E. Tournament
Problem Statement
Recently a tournament in k kinds of sports has begun in Berland. Vasya wants to make money on the bets.
The scheme of the tournament is very mysterious and not fully disclosed. Competitions are held back to back, each of them involves two sportsmen who have not left the tournament yet. Each match can be held in any of the k kinds of sport. Loser leaves the tournament. The last remaining sportsman becomes the winner. Apart of this, the scheme can be arbitrary, it is not disclosed in advance.
Vasya knows powers of sportsmen in each kind of sport. He believes that the sportsmen with higher power always wins.
The tournament is held every year, and each year one new participant joins it. In the first tournament, only one sportsman has participated, in the second there were two sportsmen, and so on. Vasya has been watching the tournament for the last n years. Help him to find the number of possible winners for each of the n tournaments.
Input
The first line contains two integers n and k (
1 ≤ n ≤ 5⋅104 , 1 ≤ k ≤ 10) — the number of tournaments and the number of kinds of sport, respectively.
Each of the next n lines contains k integerssi,1, si,2, ..., si,k(1 ≤ si,j ≤ 109) , wheresi,j is the power of the i-th sportsman in the j-th kind of sport. The sportsman with higher powers always wins. It’s guaranteed that for any kind of sport all of these powers are distinct.
Output
For each of the n tournaments output the number of contenders who can win.
Examples
Example 1
Input
3 2
1 5
5 1
10 10
Output
1
2
1
Example 2
Input
3 2
2 2
3 3
1 10
Output
1
1
3
Example 3
Input
3 2
2 3
1 1
3 2
Output
1
1
2
Note
In the first sample:
In the first tournament there is only one sportsman, and he is the winner.
In the second tournament, there are two sportsmen, and everyone can defeat another, depending on kind of sports.
In the third tournament, the third sportsman in the strongest in both kinds of sports, so he is the winner regardless of the scheme.
题意
一共有n个人,每个人有k项技能,给出每个人的每项技能的强度,现在这些人会两两进行比赛,他们会选一个技能进行比较,值高的人获胜,而低的人就淘汰了。问按顺序每次加进来一个人,有可能可以获胜的人数有几个。
思路
假设现在有一群人可以获得冠军,那么必须满足任何一个人,我们都可以找到一个人的一项技能能力小于等于他,也可以找到一项技能能力大于等于他。于是对于这些人,我们可以找到一种特定方案使得这些人中任何一个人都能获胜,那么我们可以用set来维护这个群体,我们可以在set中存入现在这个群体每项值的最大值和最小值和现在这个群体的人数,然后一个一个人与这个set合并就行了。
Code
#include<cstdio>#include<cmath>#include<set>using namespace std;int x,n,k,i,j;struct people{ int mx[15],mi[15],sz; bool operator < (const people&rhs) const {for(j=1;j<=k;j++)if(mx[j]>rhs.mi[j])return 0;return 1;}}tmp;set<people>s;int main() { scanf("%d%d",&n,&k); for(i=1;i<=n;i++) { for(j=1;j<=k;j++) { scanf("%d",&x); tmp.mi[j]=tmp.mx[j]=x; tmp.sz=1; } auto x=s.lower_bound(tmp),y=s.upper_bound(tmp); while(x!=y) { tmp.sz+=x->sz; for(j=1;j<=k;j++) tmp.mi[j]=min(tmp.mi[j],x->mi[j]),tmp.mx[j]=max(tmp.mx[j],x->mx[j]); s.erase(x++); } s.insert(tmp); printf("%d\n",s.rbegin()->sz); } return 0;}
- Codeforces Round #443 (Div. 2) E. Tournament
- Codeforces Round #443 (Div. 1) C. Tournament
- Codeforces Round #443 (Div. 2) D,E
- Codeforces Round #443 (Div. 1) C. Tournament(瞎搞???)
- Codeforces Round #207 (Div. 2) C. Knight Tournament
- Codeforces Round #207 (Div. 2) C. Knight Tournament
- Codeforces Round #207 (Div. 2) C. Knight Tournament
- Codeforces Round #207 (Div. 2) C. Knight Tournament (并查集缩点)
- Codeforces Round #207 (Div. 2)---C. Knight Tournament(set乱搞)
- Codeforces Round #207 (Div. 2) C - Knight Tournament
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces Round #103 (Div. 2) E题
- Codeforces Round #147 (Div. 2) E
- Codeforces Round #184 (Div. 2) D、E
- Codeforces Round #197 (Div. 2) (C~E)
- Codeforces Round #102 (Div. 2) //缺E
- Codeforces Round #104 (Div. 2) //缺E
- Codeforces Round #105 (Div. 2) //缺E
- Android8.0 Email 一个Bug修改方案
- Linux tcpdump命令详解
- javascript:;与javascript:void(0)使用介绍
- jquery表单过滤选择器
- 将Excel数据转换成FlatBuffer数据的方法
- Codeforces Round #443 (Div. 2) E. Tournament
- 反射(提供封装程序集、模块和类型的对象)
- Syabse数据库无法启动的数据恢复案例
- 【Owin 学习系列】2. Owin Startup 类解析
- Redis学习笔记之四:列表类型
- Map转换成Bean对象
- 坐在马桶上看算法:快速排序
- Delphi压缩access数据库
- LVS 三种工作模式原理、以及优缺点比较