题意:给一段0-8000的线段染色 问最后 颜色x 有几段

题解:标准线段树  但是没有push_up  最后查询是单点按顺序查询每一个点

考虑过使用区间来维护不同的线段有多少种各色的线段  思路是 两个子区间合并:左子区最右边和右子区最左边如果相同,那么就不变,不同就+1  但是不好维护  所以直接单点查还更方便

注意  染色是染区间不是染点 例如   0  3是染  0 1 2 3这4个数中间的空  如果不考虑清楚这一点就会导致 染了  2-3 颜色1  0 2颜色2   3-4颜色3  0 到4颜色分别为   2 2 3 3只有两种颜色 而如果是染区间的话

2 3区间中染了 1 后面的操作都没有覆盖掉 所以要把边映射成点    n个点有n-1个边 那么很自然  把第一条边成1   8000也就是8000了 update就要 符合映射 让 l+1  即可

 #include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=+;
int num[maxn],ans[maxn];
struct Node{
int l,r,lazy,v;
void update(int x){
v=x;
lazy=x;
}
}tree[maxn*];
void push_up(int x){ }
void push_down(int x){
int lazyval=tree[x].lazy;
if(lazyval!=-){
tree[x<<].update(lazyval);
tree[x<<|].update(lazyval);
tree[x].lazy=-;
}
}
void update(int x,int l,int r,int c){
int L=tree[x].l,R=tree[x].r;
if(l<=L&&R<=r){
tree[x].update(c);
}
else{
int mid=L+R>>;
push_down(x);
if(mid>=l)update(x<<,l,r,c);
if(mid<r)update(x<<|,l,r,c);
// push_up(x);
}
}
int lastcolor=-;
int query(int x,int l,int r){
//int L=tree[x].l,R=tree[x].r;
if(l==r){
if(tree[x].v!=-&&tree[x].v!=lastcolor)ans[tree[x].v]++;
lastcolor=tree[x].v;
//if(lastcolor!=-1)cout<<l<<" " <<x<<" "<<tree[x].v<<endl;
}
else {
push_down(x);
int mid=l+r>>;
query(x<<,l,mid);
query(x<<|,mid+,r);
}
}
void build(int x,int l,int r){
tree[x].l=l,tree[x].r=r;
tree[x].lazy=-;
if(l==r){
tree[x].v=-;
//if(l==8000)cout<<" !zzz! "<<x<<endl;
return ;
}
else {
int mid=l+r>>;
build(x<<,l,mid);
build(x<<|,mid+,r);
//push_up(x);
} }
int main(){
int n;
while(scanf("%d",&n)==)
{
lastcolor=-;
build(,,);
memset(ans,,sizeof(ans));
for(int i=;i<=n;i++){
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
update(,x+,y,c);
}
// cout<<tree[8286].v<<"!! "<<endl;
query(,,);
// cout<<tree[8286].v<<" 22222"<<endl;
for(int i=;i<=;i++){
if(ans[i]){
printf("%d %d\n",i,ans[i]);
}
}
cout<<endl;
}
}

F - Count the Colors ZOJ - 1610 线段树染色(染区间映射)的更多相关文章

  1. F - Count the Colors - zoj 1610(区间覆盖)

    有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 1号颜色有几块,2号颜色有几块.... *************** ...

  2. ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】

    任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...

  3. (线段树) Count the Colors --ZOJ --1610

    链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...

  4. kuangbin专题七 ZOJ1610 Count the Colors (灵活线段树)

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

  5. Count the Colors ZOJ - 1610 区间颜色覆盖

    #include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> ...

  6. F - Count the Colors

    F - Count the Colors ZOJ - 1610   思路:调了一个小时,但是发现自己线段树木有写错,颜色统计出了错误.但是不明白自己颜色统计为什么错了. 求大佬指点迷津.思路很简单,就 ...

  7. ZOJ - 1610 经典线段树染色问题

    这个是一个经典线段树染色问题,不过题目给的是左右左右坐标,即[0,3]包含0-1这一段 1-2这一段 2-3这一段,和传统的染色不太一样,不过其实也不用太着急. 我们把左边的坐标+1,即可,那么[0, ...

  8. ZOJ 3279-Ants(线段树)

    传送门:zoj 3279 Ants Ants Time Limit: 2 Seconds      Memory Limit: 32768 KB echo is a curious and cleve ...

  9. AtCoder Regular Contest 069 F Flags 二分,2-sat,线段树优化建图

    AtCoder Regular Contest 069 F Flags 二分,2-sat,线段树优化建图 链接 AtCoder 大意 在数轴上放上n个点,点i可能的位置有\(x_i\)或者\(y_i\ ...

随机推荐

  1. 深入理解Redis高可用方案-Sentinel

    Redis Sentinel是Redis的高可用方案.是Redis 2.8中正式引入的. 在之前的主从复制方案中,如果主节点出现问题,需要手动将一个从节点升级为主节点,然后将其它从节点指向新的主节点, ...

  2. Python股票分析系列——数据整理和绘制.p2

    该系列视频已经搬运至bilibili: 点击查看 欢迎来到Python for Finance教程系列的第2部分. 在本教程中,我们将利用我们的股票数据进一步分解一些基本的数据操作和可视化. 我们将要 ...

  3. python之subprocess模块详解--小白博客

    subprocess模块 subprocess是Python 2.4中新增的一个模块,它允许你生成新的进程,连接到它们的 input/output/error 管道,并获取它们的返回(状态)码.这个模 ...

  4. Python_每日习题_0006_斐波那契数列

    程序设计: 斐波那契数列(Fibonacci sequence),从1,1开始,后面的每一项等于前面两项之和. 图方便就递归实现,图性能就用循环. # for 循环 target = int(inpu ...

  5. Johnson算法

    用于求稀疏图上的全局最短路. 考虑将带负权的图变为不带负权的图,再跑\(n\)次Dijkstra. 方法:新建点S,向所有点连边权为\(0\)的边,然后以S为起点跑SPFA.然后将每条边的权值重新赋为 ...

  6. HDU - 1542 扫描线入门+线段树离散化

    扫描线算法+线段树维护简介: 像这种求面积的并集的题目,就适合用扫描线算法解决,具体来说就是这样 类似这种给出点的矩形的对角的点的坐标,然后求出所有矩形面积的交集的问题,可以采用扫描线算法解决.图如下 ...

  7. Sparse Principal Component Analysis via Rotation and Truncation

    目录 对以往一些SPCA算法复杂度的总结 Notation 论文概述 原始问题 问题的变种 算法 固定\(X\),计算\(R\) 固定\(R\),求解\(X\) (\(Z =VR^{\mathrm{T ...

  8. Linux系统tree工具

    当用户在linux平台中需要需要查看一个非当前目录的目录下有哪些文件和子文件时,最普通的办法就是cd该目录,然后再ls,这个操作令人不舒适,因为查看完以后,用户还需要切换到原来的目录.现在介绍一款非常 ...

  9. CodeForces Round #529 Div.3

    http://codeforces.com/contest/1095 A. Repeating Cipher #include <bits/stdc++.h> using namespac ...

  10. Jenkins系统上的时间不正确问题

    很简单,点击系统管理,选择执行脚本命令: 打开 [系统管理]->[脚本命令行]运行下面的命令 System.setProperty('org.apache.commons.jelly.tags. ...