Codeforces Round #443 (Div. 2) E. Tournament

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 ( 1n5104 , 1 ≤ k ≤ 10) — the number of tournaments and the number of kinds of sport, respectively.
    Each of the next n lines contains k integers si,1,si,2,...,si,k(1si,j109) , where si,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
#include
#include
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;
sets;
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;
}

你可能感兴趣的:(推理结论,STL)