$n \leq 50000$个人,每个人有$K \leq 10$个属性,现对每一个前缀问:进行比赛,每次任意两人比任意属性,小的淘汰(保证同一属性不会出现两个相同的数),最终有几个人有可能获胜。

明显是一个竞赛图了,缩完点就是求拓扑序最高那个强连通分量的大小。现在要一个一个把人加入。

可以观察到,缩完点之后,两个分量之间一定有边,表示一个分量“完胜”另一个,就是不管比哪个属性这个分量里的人都能赢另外一个。所以把分量按某个属性的最小值排序的话,任意一个属性与此同时都是按最小值排序的,同时也是按任意属性最大值排序的。

加入一个人,他可能战胜一些分量(某个属性大于这个分量的最小值),可能被一些分量战胜(某个属性小于这个分量的最大值),因此可能合并一些分量。需要把分量值按从小到大一直维持有序,并插入删除点,用set即可。一个分量的信息可以存在数组中,找分量中的一个“代表”存,会使代码简洁。

 //#include<iostream>
#include<cstring>
#include<cstdio>
//#include<math.h>
#include<set>
//#include<queue>
//#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std; #define LL long long
int qread()
{
char c; int s=,f=; while ((c=getchar())<'' || c>'') (c=='-') && (f=-);
do s=s*+c-''; while ((c=getchar())>='' && c<=''); return s*f;
} //Pay attention to '-' , LL and double of qread!!!! int n,K;
#define maxn 50011
int a[maxn][],b[maxn][],size[maxn];
struct snode
{
int id,v;
bool operator < (const snode &b) const {return v<b.v;}
};
set<snode> s; bool Win(int x,int y)
{
for (int i=;i<=K;i++) if (b[x][i]>a[y][i]) return ;
return ;
} int main()
{
n=qread(); K=qread();
for (int i=;i<=n;i++)
for (int j=;j<=K;j++)
a[i][j]=b[i][j]=qread();
for (int i=;i<=n;i++)
{
size[i]=;
set<snode>::iterator it;
while (!s.empty())
{
it=s.lower_bound((snode){,a[i][]});
if (it==s.end()) break;
int u=(*it).id;
if (Win(i,u))
{
size[i]+=size[u];
for (int j=;j<=K;j++)
a[i][j]=min(a[i][j],a[u][j]),b[i][j]=max(b[i][j],b[u][j]);
s.erase(it);
}
else break;
}
while (!s.empty())
{
it=s.lower_bound((snode){,a[i][]});
if (it==s.begin()) break;
it--; int u=(*it).id;
if (Win(u,i))
{
size[i]+=size[u];
for (int j=;j<=K;j++)
a[i][j]=min(a[i][j],a[u][j]),b[i][j]=max(b[i][j],b[u][j]);
s.erase(it);
}
else break;
}
s.insert((snode){i,a[i][]});
printf("%d\n",size[(*--s.end()).id]);
}
return ;
}

Codeforces878C. Tournament的更多相关文章

  1. Codeforces CF#628 Education 8 A. Tennis Tournament

    A. Tennis Tournament time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Rock-Paper-Scissors Tournament[HDU1148]

    Rock-Paper-Scissors TournamentTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  3. CF 628A --- Tennis Tournament --- 水题

    CF 628A 题目大意:给定n,b,p,其中n为进行比赛的人数,b为每场进行比赛的每一位运动员需要的水的数量, p为整个赛程提供给每位运动员的毛巾数量, 每次在剩余的n人数中,挑选2^k=m(m & ...

  4. ural 1218. Episode N-th: The Jedi Tournament

    1218. Episode N-th: The Jedi Tournament Time limit: 1.0 secondMemory limit: 64 MB Decided several Je ...

  5. URAL 1218 Episode N-th: The Jedi Tournament(强连通分量)(缩点)

    Episode N-th: The Jedi Tournament Time limit: 1.0 secondMemory limit: 64 MB Decided several Jedi Kni ...

  6. Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压

    题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabyte ...

  7. CodeForce 356A Knight Tournament(set应用)

     Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  8. 遗传算法selection总结-[Fitness, Tournament, Rank Selection]

    假设个体(individual)用\(h_i\)表示,该个体的适应度(fitness)为\(Fitness(h_i)\),被选择的概率为\(P(h_i)\). 另外假设种群(population)的个 ...

  9. 【CF913F】Strongly Connected Tournament 概率神题

    [CF913F]Strongly Connected Tournament 题意:有n个人进行如下锦标赛: 1.所有人都和所有其他的人进行一场比赛,其中标号为i的人打赢标号为j的人(i<j)的概 ...

随机推荐

  1. Bootstrap历练实例:面板的标题

    面板标题 我们可以通过以下两种方式来添加面板标题: 使用 .panel-heading class 可以很简单地向面板添加标题容器.to easily add a heading container ...

  2. SQL Server数据库字段类型说明

    SQL Server数据库字段类型说明 目前Sql Server 数据库一共有X个字段类型,大体分为9类,分别是字符串类型.二进制码字符串数据类型.Unincode字符串数据.整数类型.精确数据类型. ...

  3. 01_13_Struts_默认Action

    01_13_Struts_默认Action 1. 配置struts默认Action <package name="default" namespace="/&quo ...

  4. Python学习笔记:wxPython(GUI图形用户界面)

    wxPython是一套基于Python的第三方GUI插件,可用Python制作丰富的图形化界面程序. 安装:pip install wxPython 或者 网站下载安装https://pypi.org ...

  5. 嵌入式入门学习笔记3:[转]编译linux

    摘自:https://blog.csdn.net/baidu_24256693/article/details/80115354 编译Linux是什么意思? Linux内核是Linux操作系统的核心, ...

  6. BFS:UVa1590-IP Networks (子网掩码相关知识)

    IP Networks Alex is administrator of IP networks. His clients have a bunch of individual IP addresse ...

  7. Python中的属性访问与描述符

    Python中的属性访问与描述符 请给作者点赞--> 原文链接 在Python中,对于一个对象的属性访问,我们一般采用的是点(.)属性运算符进行操作.例如,有一个类实例对象foo,它有一个nam ...

  8. debian右键添加在终端中打开

    sudo apt-get install nautilus-open-terminal -y 注销,重启

  9. Hive学习笔记(二)

    Hive内部表跟外部表之间的区别 创建外部表 先删除上面创建的表,指定location 此时在hdfs根目录下就有一个hivedata文件夹 上传文本数据到hivedata目录下 查询表中数据 删除上 ...

  10. 一个Work Stealing Pool线程池的实现

    一.一般来说实现一个线程池主要包括以下几个组成部分: 1)线程管理器 :用于创建并管理线程池 . 2)工作线程 :线程池中实际执行任务的线程 . 在初始化线程时会预先创建好固定数目的线程在池中 ,这些 ...