CF878C Tournament

题意翻译


最近Berland开始了一场有k种运动的比赛。瓦萨亚希望在赌场上赚钱。 比赛的计划非常神秘,并没有完全公开。比赛选手背靠背举行,每场比赛都涉及两名尚未淘汰的运动员。每场比赛都可以举行k种运动里的任意一种,失败者则遭到淘汰。最后剩下的运动员成为冠军。除此之外,该方案可以是任意的,不提前公开。 瓦西亚了解各种运动中的运动员的力量。他认为,拥有更高力量的运动员总能获胜。 比赛每年举行一次,每年都有一名新参赛者加入比赛。在第一场比赛中,只有一名运动员参加,第二场比赛有两名运动员,依此类推。 请你帮助他找到每一年可能获得冠军的人数。


题目描述

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 n n years. Help him to find the number of possible winners for each of the n n n tournaments.
输入格式

The first line contains two integers nand k ( 1<=n<=5⋅10^4 1<=n<=5·10^4 1<=n<=5⋅10^4 , 1<=k<=10 1<=k<=10 1<=k<=10 ) — the number of tournaments and the number of kinds of sport, respectively.

Each of the next n n n lines contains kintegers si1,si2,...,sik s_{i1},s_{i2},...,s_{ik} si1​,si2​,...,sik​ ( 1<=sij<=109 1<=s_{ij}<=10^{9} 1<=sij​<=109 ), where sij s_{ij} sij​ is the power of the i i i -th sportsman in the j j 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.
输出格式

For each of the n n n tournaments output the number of contenders who can win.
输入输出样例
输入 #1

3 2
1 5
5 1
10 10

输出 #1

1
2
1

输入 #2

3 2
2 2
3 3
1 10

输出 #2

1
1
3

输入 #3

3 2
2 3
1 1
3 2

输出 #3

1
1
2

说明/提示

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.


考虑把两个人的比赛连边,如果A可能赢B且B可能赢A,则他们可以互相到达,用强连通分量的方法进行缩点,那么最后整张图一定是一个链,那么第一个强连通分量的大小就是答案。

不过对于强连通分量的处理,这题有一个非常精妙的方法,就是用set,把输赢变成重载运算符,那么如果如果A可能赢B且B可能赢A,则A==B,可以直接用find函数。

#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read() {
    int data=0,w=1;
    char ch=0;
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') {w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {data=data*10+ch-'0';ch=getchar();}
    return data*w;
}
void write(int x) {
    if(x>=10) write(x/10);
    register char ch=x%10+'0';  
    putchar(ch);
}
int n,m,ans,k;
struct node {
    int sz,mx[12],mn[12];
    friend bool operator < (node a,node b) {
        for(int i=1;i<=k;i++)
            if(a.mx[i]>b.mn[i]) return 0;
        return 1;
    }   
} sxd;
set <node> q;
signed main() {
    cin>>n>>k;
    for(int i=1;i<=n;i++) {
        sxd.sz=1;
        for(int j=1;j<=k;j++) {sxd.mn[j]=sxd.mx[j]=read();}
        set <node> :: iterator it=q.find(sxd);
        while(it!=q.end()) {
            sxd.sz+=(*it).sz;
            for(int j=1;j<=k;j++) {
                sxd.mx[j]=max(sxd.mx[j],(*it).mx[j]);
                sxd.mn[j]=min(sxd.mn[j],(*it).mn[j]);
            }
            q.erase(it);
            it=q.find(sxd);
        }
        q.insert(sxd);
        write((*q.rbegin()).sz);
        puts("");
    }
    return 0;
}
全部评论

相关推荐

头像
10-13 18:10
已编辑
东南大学 C++
。收拾收拾心情下一家吧————————————————10.12更新上面不知道怎么的,每次在手机上编辑都会只有最后一行才会显示。原本不想写凉经的,太伤感情了,但过了一天想了想,凉经的拿起来好好整理,就像象棋一样,你进步最快的时候不是你赢棋的时候,而是在输棋的时候。那废话不多说,就做个复盘吧。一面:1,经典自我介绍2,项目盘问,没啥好说的,感觉问的不是很多3,八股问的比较奇怪,他会深挖性地问一些,比如,我知道MMU,那你知不知道QMMU(记得是这个,总之就是MMU前面加一个字母)4,知不知道slab内存分配器-&gt;这个我清楚5,知不知道排序算法,排序算法一般怎么用6,写一道力扣的,最长回文子串反问:1,工作内容2,工作强度3,关于友商的问题-&gt;后面这个问题问HR去了,和中兴有关,数通这个行业和友商相关的不要提,这个行业和别的行业不同,别的行业干同一行的都是竞争关系,数通这个行业的不同企业的关系比较微妙。特别细节的问题我确实不知道,但一面没挂我。接下来是我被挂的二面,先说说我挂在哪里,技术性问题我应该没啥问题,主要是一些解决问题思路上的回答,一方面是这方面我准备的不多,另一方面是这个面试写的是“专业面试二面”,但是感觉问的问题都是一些主管面/综合面才会问的问题,就是不问技术问方法论。我以前形成的思维定式就是专业面会就是会,不会就直说不会,但事实上如果问到方法论性质的问题的话得扯一下皮,不能按照上面这个模式。刚到位置上就看到面试官叹了一口气,有一些不详的预感。我是下午1点45左右面的。1,经典自我介绍2,你是怎么完成这个项目的,分成几个步骤。我大致说了一下。你有没有觉得你的步骤里面缺了一些什么,(这里已经在引导我往他想的那个方向走了),比如你一个人的能力永远是不够的,,,我们平时会有一些组内的会议来沟通我们的所思所想。。。。3,你在项目中遇到的最困难的地方在什么方面4,说一下你知道的TCP/IP协议网络模型中的网络层有关的协议......5,接着4问,你觉得现在的socket有什么样的缺点,有什么样的优化方向?6,中间手撕了一道很简单的快慢指针的问题。大概是在链表的倒数第N个位置插入一个节点。————————————————————————————————————10.13晚更新补充一下一面说的一些奇怪的概念:1,提到了RPC2,提到了fu(第四声)拷贝,我当时说我只知道零拷贝,知道mmap,然后他说mmap是其中的一种方式,然后他问我知不知道DPDK,我说不知道,他说这个是一个高性能的拷贝方式3,MMU这个前面加了一个什么字母我这里没记,别问我了4,后面还提到了LTU,VFIO,孩子真的不会。
走呀走:华子二面可能会有场景题的,是有些开放性的问题了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务