Codeforces Round #207 (Div. 1) A:http://codeforces.com/problemset/problem/356/A

题意:给你n匹马,然后有m场比赛。每场比赛有一个l,r,x,表示编号从l,r之间的马都被x给打败了,但是这里如果之前已经败了,那么这里的区间就不会包括了。

题解:题解,直接用一个set搞定。

思维过程:首先,想到,对于一场比赛来说,如果之前已经败了的话,这里就不用在考虑了,但是如何判断这个区间里面的马已经败了,朴素的想法,就是查询还是在这个区间,但是我把之前的已经败的马打上表示,然后再在这个区间内逐个进行判断,这样判断的话,区间内的每个元素都会被判断一次,可想而知,这样的想法是不对。时间复杂度hold不住。如何对于那些已经败的马不用判断。这里,可以用一个set来搞,把所有的元素放进set,当要删除一个区间的时候,只要用lower_bound找到第一个不小于l的数,然后往后找,直到到达右端点。然后把找到的点,从set中删除即可。这样,每次查询只在没有删除的马中进行,所以减少了许多不必要的判断。现在考虑复杂度。每个数,会被放进set和从set中删除一次,所以复杂度是n(logn).一定要利用题目中的各种信息,然后利用好自己的思维信息,寻找突破口,一点一滴的,总会有解决的方法。

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
const int N=3e5+;
int ans[N],temp[N],top;
int n,m,l,r,x;
int main(){
while(~scanf("%d%d",&n,&m)){
set<int>Q;
for(int i=;i<=n;i++){
Q.insert(i);
}
for(int i=;i<=m;i++){
scanf("%d%d%d",&l,&r,&x);
top=;
set<int>::iterator it=Q.lower_bound(l);
for(;it!=Q.end();it++){
if((*it)>r)break;
if((*it)==x){
ans[x]=x;
}
else{
ans[(*it)]=x;
temp[++top]=(*it);
}
}
for(int i=;i<=top;i++){
Q.erase(temp[i]);
}
top=;
}
for(int i=;i<n;i++){
if(ans[i]==i)printf("0 ");
else
printf("%d ",ans[i]);
}
if(ans[n]==n)printf("0\n");
else
printf("%d\n",ans[n]);
} }

Knight Tournament的更多相关文章

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

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

  2. Knight Tournament 合并区间

    Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the me ...

  3. Knight Tournament (set)

    Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the me ...

  4. CodeForces - 357C Knight Tournament 伪并查集(区间合并)

    Knight Tournament Hooray! Berl II, the king of Berland is making a knight tournament. The king has a ...

  5. D - Knight Tournament(set)

    Problem description Hooray! Berl II, the king of Berland is making a knight tournament. The king has ...

  6. codeforces 357C Knight Tournament(set)

    Description Hooray! Berl II, the king of Berland is making a knight tournament. The king has already ...

  7. Codeforces Round #207 (Div. 1) A. Knight Tournament(STL)

    脑子又卡了...来一发set的,STL真心不熟. #include <stdio.h> #include <string.h> #include <iostream> ...

  8. cf C. Knight Tournament

    http://codeforces.com/contest/357/problem/C #include <cstdio> #include <cstring> #includ ...

  9. Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)

    题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...

随机推荐

  1. /var/log目录下的20个Linux日志文件功能详解 分类: 服务器搭建 linux内核 Raspberry Pi 2015-03-27 19:15 80人阅读 评论(0) 收藏

    如果愿意在Linux环境方面花费些时间,首先就应该知道日志文件的所在位置以及它们包含的内容.在系统运行正常的情况下学习了解这些不同的日志文件有助于你在遇到紧急情况时从容找出问题并加以解决. 以下介绍的 ...

  2. admob广告开始个人资料网址

    最近植入广告,数据收集,简单易学. ios http://www.rover12421.com/2013/05/08/ios-add-admob-ads-test-xcode-project-test ...

  3. Oracle修改被占用的临时表结构

    这两天在修改临时表的类型时,提示”attempt to create,alter or drop an index on temporary table already in use“的错误,由于临时 ...

  4. ZOJ 3903 Ant(公式推导)

    这个公式推导过程是看的这位大牛的http://blog.csdn.net/bigbigship/article/details/49123643 扩展欧几里德求模的逆元方法: #include < ...

  5. java返回参数中几种常见的方法

    1.有参数有返回值 public class text_1 {    1)创建add方法 public int add(int i, int j) {        int res = i + j;  ...

  6. 过滤掉html 标签

    /// <summary> /// 过滤掉html标签 /// </summary> /// <param name="Htmlstring"> ...

  7. Weex 学习教程

    一.环境搭建 1.安装Node,官网下载(http://nodejs.org/) 2.查看npm安装版本,终端输入:npm -v版本不能低于2.15.1 3.安装weex-toolkit,终端输入:n ...

  8. android Services注意地方

    使用service前需要在manifest声明: <manifest ... > ... <application ... > <service android:name ...

  9. SQL Server 表字段值转换成字段名称(二)

    上次写了个比较简单的只有两个字段的例子,经要求在写个  3 个字段的示例 ,贴上来与大家共勉一下   如果你们有更好的方法,提供一下, 感激不尽. 示例如下: /*--drop table temp_ ...

  10. PageMapAdapter MapAdapter (续webServices)

    public class PageMapAdapter extends XmlAdapter<PageMapConverter, IPage<Map<String, Object&g ...