Codeforces878C. Tournament
$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的更多相关文章
- 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 ...
- Rock-Paper-Scissors Tournament[HDU1148]
Rock-Paper-Scissors TournamentTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- CF 628A --- Tennis Tournament --- 水题
CF 628A 题目大意:给定n,b,p,其中n为进行比赛的人数,b为每场进行比赛的每一位运动员需要的水的数量, p为整个赛程提供给每位运动员的毛巾数量, 每次在剩余的n人数中,挑选2^k=m(m & ...
- 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 ...
- 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 ...
- Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压
题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabyte ...
- CodeForce 356A Knight Tournament(set应用)
Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- 遗传算法selection总结-[Fitness, Tournament, Rank Selection]
假设个体(individual)用\(h_i\)表示,该个体的适应度(fitness)为\(Fitness(h_i)\),被选择的概率为\(P(h_i)\). 另外假设种群(population)的个 ...
- 【CF913F】Strongly Connected Tournament 概率神题
[CF913F]Strongly Connected Tournament 题意:有n个人进行如下锦标赛: 1.所有人都和所有其他的人进行一场比赛,其中标号为i的人打赢标号为j的人(i<j)的概 ...
随机推荐
- c3p0,dbcp和proxool
关于c3p0.dbcp和proxool,之类的比较,配置在网上有很多的文章,我这边就不浪费大家的时间了,主要讲下我用过这三个之后的体会. dbcp:框架以前使用的是dbcp,网上说,有很多BUG,至少 ...
- MySQL索引类型及优化
索引是快速搜索的关键.MySQL索引的建立对于MySQL的高效运行是很重要的.下面介绍几种常见的MySQL索引类型. 在数据库表中,对字段建立索引可以大大提高查询速度.假如我们创建了一个 mytabl ...
- Java面向对象基础 ——面试题
1面向对象基础 JAVA基础语法自行掌握. 三大特性: 一 封装:★★★★★ 概念:是指隐藏对象的属性和实现细节,仅对外提供公共访问方式. 好处:将变化隔离:便于使用:提高重用性:安全性. 封装原则: ...
- js函数式编程(一)-纯函数
我将写的第一个主题是js的函数式编程,这一系列都是mostly adequate guide这本书的读书总结.原书在gitbook上,有中文版.由于原作者性格活泼,书中夹杂很多俚语,并且行文洒脱.中文 ...
- Java微信公众号开发----定时获取access_token并保存到redis中
本人原本是想做微信公众号菜单的创建修改删除等操作的,但是发现需要access_token,通过阅读文档,发现文档要求有以下几点: 1.access_token 获取后有效期是2小时 2.access_ ...
- 【转】MFC右键显示菜单之LoadMenu()
如何在界面内单击右键弹出自己设置的菜单选项? 步骤如下: 1.在资源MENU里添加一个菜单资源,命名为IDR_POP_MENU. 2.在自己添加的菜单中添加事件,如事件1,事件2,事件3,分别添加响应 ...
- dev gridview columns代码管理
进入run designer界面.我们将在代码中设置columns的属性. 类: ViewTriAtt : DevExpress.XtraEditors.XtraUserControl 在类里面设置g ...
- angular5 HttpInterceptor使用
HttpInterceptor接口是ng的http请求拦截器,当需要拦截http请求,可以实现该接口. 1.创建HttpInterceptor 的实现类,并使用@Injectable()注解 @Inj ...
- 使用 Python 编写登陆接口
# 使用 Python 编写登陆接口# Create Date: 2017.10.31 Tuesday# Author: Eric Zhao# -*- coding:utf-8 -*-'''编写登陆接 ...
- (转).gitignore详解
本文转自http://sentsin.com/web/666.html 今天讲讲Git中非常重要的一个文件——.gitignore. 首先要强调一点,这个文件的完整文件名就是“.gitignore”, ...