https://cn.vjudge.net/problem/ZOJ-1610

题意

给一个n,代表n次操作,接下来每次操作表示把[l,r]区间的线段涂成k的颜色其中,l,r,k的范围都是0到8000。

分析

把区间看作点,即[3,4]看作点4。查询时进行前序遍历,记录上一段的颜色,不连续的就+1。注意区间的范围可达8000

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
#define pi acos(-1)
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int maxn = + ;
const int maxm = + ;
const int mod = ;
int n;
struct ND{
int l,r;
// ll sum,lazy;
int col;
}tree[maxn<<];
int pre;
int ans[maxn];
//void pushup(int rt){
//
// tree[rt].sum=tree[rt<<1].sum+tree[rt<<1|1].sum;
//}
void pushdown(int rt){
if(tree[rt].col!=-){
tree[rt<<].col=tree[rt<<|].col=tree[rt].col;
tree[rt].col=-;
}
}
void build(int rt,int l,int r){
tree[rt].l=l,tree[rt].r=r;
tree[rt].col=-;
// tree[rt].lazy=0;
if(l==r){
return;
}
int mid=(l+r)>>;
build(rt<<,l,mid);
build(rt<<|,mid+,r);
// pushup(rt);
}
void update(int rt,int L,int R,int val){
if(L<=tree[rt].l&&tree[rt].r<=R){
tree[rt].col=val;
return;
}
pushdown(rt);
int mid=(tree[rt].l+tree[rt].r)>>;
if(mid>=L) update(rt<<,L,R,val);
if(mid<R) update(rt<<|,L,R,val);
// pushup(rt);
} void query(int rt){
if(tree[rt].l==tree[rt].r){
if(tree[rt].col!=-&&tree[rt].col!=pre){
ans[tree[rt].col]++;
}
pre=tree[rt].col;
return;
}
pushdown(rt);
query(rt<<);
query(rt<<|);
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t,cas=;
// scanf("%d",&t);
while(~scanf("%d",&n)){
pre=-;
memset(ans,,sizeof(ans));
build(,,);
while(n--){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
if(x<y) update(,x+,y,z);
}
query();
for(int i=;i<=;i++){
if(ans[i]) printf("%d %d\n",i,ans[i]);
}
puts("");
}
return ;
}

ZOJ - 1610 Count the Colors(线段树区间更新)的更多相关文章

  1. zoj 1610 Count the Colors 线段树区间更新/暴力

    Count the Colors Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...

  2. ZOJ 1610 Count the Color(线段树区间更新)

    描述Painting some colored segments on a line, some previously painted segments may be covered by some ...

  3. ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  4. ZOJ 1610 Count the Colors (线段树成段更新)

    题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...

  5. 【POJ 2777】 Count Color(线段树区间更新与查询)

    [POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4094 ...

  6. ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)

    ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting s ...

  7. ZOJ 5638——Prime Query——————【线段树区间更新,区间查询,单点更新】

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  8. poj 2777 Count Color(线段树 区间更新)

    题目:http://poj.org/problem?id=2777 区间更新,比点更新多一点内容, 详见注释,  参考了一下别人的博客.... 参考博客:http://www.2cto.com/kf/ ...

  9. ZOJ1610 Count the Colors —— 线段树 区间染色

    题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...

  10. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

随机推荐

  1. 【XSY2750】Mythological V 2-sat

    题目描述 有一棵\(n\)个点的树,还有\(m\)个物品. 你要把每个物品放在树上的一个点上(两个物品可以放在同一个点). 有\(q\)个限制:\(a,b\)两个物品在路上的最短路经过\(c\). 要 ...

  2. 【XSY2779】最小表示串 KMP DP polya定理

    题目描述 给你一个字符串\(s\),问你有多少个串是最小表示串且字典序\(\leq s\) \(|s|\leq 1000\) 题解 先把\(s\)变成比\(s\)小的最大的最小表示串.方法是从后枚举每 ...

  3. 自学Python之路-django

    自学Python之路-django 自学Python之路[第一回]:1.11.2 1.3

  4. CDQ分治与整体二分学习笔记

     CDQ分治部分 CDQ分治是用分治的方法解决一系列类似偏序问题的分治方法,一般可以用KD-tree.树套树或权值线段树代替. 三维偏序,是一种类似LIS的东西,但是LIS的关键字只有两个,数组下标和 ...

  5. 树状数组入门 hdu1541 Stars

    树状数组 树状数组(Binary Indexed Tree(B.I.T), Fenwick Tree)是一个查询和修改复杂度都为log(n)的数据结构.主要用于查询任意两位之间的所有元素之和,但是每次 ...

  6. SQL查询语句的进阶使用

    MySQL的进阶使用 sql语句一些功能的使用 导入现有大量数据文件步骤 1) 把*.sql文件拷贝到Linux某一位置(例如Desktop) 2) Linux命令行进入该位置 cd ~/Deskto ...

  7. 洛谷P2831 愤怒的小鸟 + 篮球比赛1 2

    这三道题一起做,有一点心得吧. 愤怒的小鸟,一眼看上去是爆搜,但是实现起来有困难(我打了0分出来). 还有一种解法是状压DP. 抛物线一共只有那么多条,我们枚举抛物线(枚举两个点),这样就能够预处理出 ...

  8. Django 路由

    创建好项目后在项目文件下的urls.py为设置路由 Django 有两种路由方式一种的精确路由 另一个为模糊路由 """mysite URL Configuration ...

  9. render_template 网页模板

    模板简单介绍: 视图函数:视图函数就是装饰器所装饰的方法,视图函数的主要作用是生成请求的响应,这是最简单的请求.实际上,视图函数有两个作用:处理业务逻辑和返回响应内容.在大型应用中,把业务逻辑和表现内 ...

  10. 64位win8.1系统 运行 32位程序,文件夹路径是中文遇到问题

    今天有一位用户向我反应软件使用遇到问题. 用户使用的是64位win8.1系统,之前有很多用户使用64位的win8.1系统没遇到过问题. 远程协助了一下,差不多15分钟我试了几个办法没解决问题. 最后我 ...