题意:给定一些操作,不断更新一些区间的颜色,求最后间断每种颜色的个数,直接线段树处理,每次更新,加上lazy标记,注意如何处理区间的端点是这题的关键;

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<cstring>
#define INF 0x3f3f3f3f
#define N 8005
using namespace std;
typedef struct node{int x;int y;int date;
}node;
node a[N*4];
int b[N*4];
int p[N*4];
void built(int root,int first,int end){if(first==end){a[root].date=-1;a[root].x=first;a[root].y=end;return ;}int mid=(first+end)/2;built(root*2,first,mid);built(root*2+1,mid+1,end);a[root].x=a[root*2].x;a[root].y=a[root*2+1].y;a[root].date=-1;
}
void U(int root,int first,int end,int l,int r,int e){if(l<=first&&end<=r){a[root].date=e;return ;}if(a[root].date!=-1){a[root*2].date=a[root].date;a[root*2+1].date=a[root].date;a[root].date=-1;}int mid=(first+end)/2;if(l<=mid) U(root*2,first,mid,l,r,e);if(r>mid)  U(root*2+1,mid+1,end,l,r,e);
}
void Q(int root,int first,int end){if(first==end){b[first]=a[root].date;return ;}if(a[root].date!=-1){a[root*2].date=a[root].date;a[root*2+1].date=a[root].date;a[root].date=-1;}int mid=(first+end)/2;Q(root*2,first,mid);Q(root*2+1,mid+1,end);
}
int main(){int m;while(scanf("%d",&m)==1){int sum=-INF;int ans=-INF;built(1,0,N);memset(b,-1,sizeof(b));int c,d,e;for(int i=1;i<=m;i++){scanf("%d %d %d",&c,&d,&e);sum=max(sum,d-1);ans=max(ans,e);U(1,0,N,c,d-1,e);}Q(1,0,N);memset(p,0,sizeof(p));for(int i=0;i<=sum;i++){if(i==0){if(b[i]!=-1){p[b[i]]++;}}else{if(b[i]!=b[i-1]&&b[i]!=-1){p[b[i]]++;}}}for(int i=0;i<=ans;i++){if(p[i]!=0){printf("%d %d\n",i,p[i]);}}printf("\n");}return 0;
}

转载于:https://www.cnblogs.com/wang9897/p/7624398.html

ZOJ 1610Count the Colors相关推荐

  1. ZOJ 1610 Count the Colors

    段树:延迟标志+暴力更新 我记得刚学段树做的时候这个话题WA一个版本.....如今,每分钟获得.... Count the Colors Time Limit: 2 Seconds      Memo ...

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

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

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

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

  4. Count the Colors ZOJ - 1610

    GO 题意:给一个区间,有n次染色操作,每次将[x1, x2]染为c,求最后每种颜色各有多少线段可以看到. #include<cstdio> #include<iostream> ...

  5. ZOJ 1610 Count the Colors 【线段树】

    <题目链接> 题目大意: 在[0,8000]这个区间内,不断进行一些操作,将其中的一些区间染成特定颜色,如果区间重复的话,后面染的色块会覆盖前面染的色块,问最终[0,8000]这个区间内每 ...

  6. 【转载】图论 500题——主要为hdu/poj/zoj

    转自--http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  7. ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!

    两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...

  8. zoj 1204 Additive equations

    ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题.所以我很是天 ...

  9. 【HDU/POJ/ZOJ】Calling Extraterrestrial Intelligence Again (素数打表模板)

    http://poj.org/problem?id=1411  POJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=168 ...

  10. Python在Seaborn中手动指定调色板颜色进行数据可视化颜色自定义实战(Manually Specify Palette Colors in Seaborn)

    Python在Seaborn中手动指定调色板颜色进行数据可视化颜色自定义实战(Manually Specify Palette Colors in Seaborn) 目录

最新文章

  1. gradle挂接到构建生命周期(七)
  2. 3 帮助命令、用户管理、压缩
  3. 使用DBCA创建数据库
  4. ai可以滚轮缩放吗_AI侵入艺术天堂!艺术也可以“量产”了吗?
  5. java okhttp设置超时_Java OkHttpClient.setWriteTimeout方法代码示例
  6. SlideSwitch仿iphone滑动开关组件,仿百度魔图滑动开关组件Android
  7. python贪心算法几个经典例子_贪心算法及几个经典例子
  8. 【SVM回归预测】基于matlab布谷鸟算法优化SVM回归预测【含Matlab源码 1422期】
  9. fds文件的处理方法
  10. Stream Editor 流编辑器命令
  11. Android基站定位详解
  12. 成本管理-输入、输出、工具和技术
  13. Beta发布——美工+文案
  14. 计算机专业就业推荐表中求职意愿,毕业生推荐表的求职意愿怎么填啊?
  15. 51单片机的应用——利用定时器控制输出对称方波
  16. 非科班出身程序员,如何超越科班程序员?
  17. 什么是人工神经网络控制,什么是人工神经网络?
  18. 《DeepLung: Deep 3D Dual Path Nets for Automated Pulmonary Nodule Detection and Classification》网络模型解读
  19. 聚观早报|王慧文要做「中国版 OpenAI」;Temu斥资近亿元赞助超级碗
  20. HDFS分布式文件系统的常用命令行操作

热门文章

  1. 2012.4.17内存相关
  2. python爬虫正则表达式爬取网页标签_Python爬虫实例(4)-用urllib、re和正则表达式爬取网页图片...
  3. 企业微信应用设置可信域名_企业微信更新版本 全平台内容可设置成英文
  4. 2020研究生数学建模获奖名单_赞!浙商大研究生在全国研究生数学建模竞赛中喜获41个奖项...
  5. 【知识索引】【数据结构(C语言)】
  6. PAT (Basic Level) Practice1023 组个最小数
  7. 图的存储结构之邻接表
  8. maven 阿里云仓库
  9. Linux系统 UDP 丢包问题分析思路和修改网卡缓存
  10. content 控件(24)