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

题意

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

分析

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

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <string>
  6. #include <algorithm>
  7. #include <cmath>
  8. #include <ctime>
  9. #include <vector>
  10. #include <queue>
  11. #include <map>
  12. #include <stack>
  13. #include <set>
  14. #include <bitset>
  15. using namespace std;
  16. typedef long long ll;
  17. typedef unsigned long long ull;
  18. #define ms(a, b) memset(a, b, sizeof(a))
  19. #define pb push_back
  20. #define mp make_pair
  21. #define pii pair<int, int>
  22. #define eps 0.0000000001
  23. #define IOS ios::sync_with_stdio(0);cin.tie(0);
  24. #define random(a, b) rand()*rand()%(b-a+1)+a
  25. #define pi acos(-1)
  26. const ll INF = 0x3f3f3f3f3f3f3f3fll;
  27. const int inf = 0x3f3f3f3f;
  28. const int maxn = + ;
  29. const int maxm = + ;
  30. const int mod = ;
  31. int n;
  32. struct ND{
  33. int l,r;
  34. // ll sum,lazy;
  35. int col;
  36. }tree[maxn<<];
  37. int pre;
  38. int ans[maxn];
  39. //void pushup(int rt){
  40. //
  41. // tree[rt].sum=tree[rt<<1].sum+tree[rt<<1|1].sum;
  42. //}
  43. void pushdown(int rt){
  44. if(tree[rt].col!=-){
  45. tree[rt<<].col=tree[rt<<|].col=tree[rt].col;
  46. tree[rt].col=-;
  47. }
  48. }
  49. void build(int rt,int l,int r){
  50. tree[rt].l=l,tree[rt].r=r;
  51. tree[rt].col=-;
  52. // tree[rt].lazy=0;
  53. if(l==r){
  54. return;
  55. }
  56. int mid=(l+r)>>;
  57. build(rt<<,l,mid);
  58. build(rt<<|,mid+,r);
  59. // pushup(rt);
  60. }
  61. void update(int rt,int L,int R,int val){
  62. if(L<=tree[rt].l&&tree[rt].r<=R){
  63. tree[rt].col=val;
  64. return;
  65. }
  66. pushdown(rt);
  67. int mid=(tree[rt].l+tree[rt].r)>>;
  68. if(mid>=L) update(rt<<,L,R,val);
  69. if(mid<R) update(rt<<|,L,R,val);
  70. // pushup(rt);
  71. }
  72.  
  73. void query(int rt){
  74. if(tree[rt].l==tree[rt].r){
  75. if(tree[rt].col!=-&&tree[rt].col!=pre){
  76. ans[tree[rt].col]++;
  77. }
  78. pre=tree[rt].col;
  79. return;
  80. }
  81. pushdown(rt);
  82. query(rt<<);
  83. query(rt<<|);
  84. }
  85. int main() {
  86. #ifdef LOCAL
  87. freopen("in.txt", "r", stdin);
  88. // freopen("output.txt", "w", stdout);
  89. #endif
  90. int t,cas=;
  91. // scanf("%d",&t);
  92. while(~scanf("%d",&n)){
  93. pre=-;
  94. memset(ans,,sizeof(ans));
  95. build(,,);
  96. while(n--){
  97. int x,y,z;
  98. scanf("%d%d%d",&x,&y,&z);
  99. if(x<y) update(,x+,y,z);
  100. }
  101. query();
  102. for(int i=;i<=;i++){
  103. if(ans[i]) printf("%d %d\n",i,ans[i]);
  104. }
  105. puts("");
  106. }
  107. return ;
  108. }

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. 【XSY1602】安全网络 树形DP 数学

    题目大意 有一颗树,要为每个节点赋一个值\(l_i\leq a_i\leq r_i\),使得任意相邻的节点互素.然后对每个节点统计\(a_i\)在所有可能的情况中的和. \(n\leq 50,1\le ...

  2. zabbix python 微信告警脚本

    测试zabbix的微信告警耗费了大量时间,使用了开源工具(OneOaaS weixin-alert).shell脚本工具(手动执行正常,服务器调用失败),均没有实现相关功能以下是自己优化过的Pytho ...

  3. CS Academy Gcd on a Circle(dp + 线段树)

    题意 给你一个长为 \(n\) 的环,你可以把它断成任意 \(k\) 段 \((1 < k \le n)\) ,使得每一段的 \(\gcd\) 都 \(>1\) . 问总共有多少种方案,对 ...

  4. 【HDU3032】Nim or not Nim?(博弈论)

    [HDU3032]Nim or not Nim?(博弈论) 题面 HDU 题解 \(Multi-SG\)模板题 #include<iostream> #include<cstdio& ...

  5. ELK部署详解--kibana

    kibana.yml # Kibana is served by a back end server. This setting specifies the port to use.#端口server ...

  6. Linux及Windows查看占用端口的进程

    想必大家在部署环境启动服务的时候,会遇到服务起不起来的问题,看日志,说是端口被占用了. 有的时候,我们不想改端口,那么,就需要去查看到底是哪个应用把这个端口给占用了,然后干掉它即可. 下面分别列举li ...

  7. 小白眼中的AI之~Numpy基础

      周末码一文,明天见矩阵- 其实Numpy之类的单讲特别没意思,但不稍微说下后面说实际应用又不行,所以大家就练练手吧 代码裤子: https://github.com/lotapp/BaseCode ...

  8. 跟着underscore学防抖

    前言 在前端开发中会遇到一些频繁的事件触发,比如: window 的 resize.scroll mousedown.mousemove keyup.keydown -- 为此,我们举个示例代码来了解 ...

  9. JavaScript深入系列(一)--原型和原型链详解

    构造函数创建对象 首先我们先使用构造函数创建一个对象: function Person(){} var person = new Person(); person.name = 'tom'; cons ...

  10. java面试——jvm

    背景:用来总结java面试过程中与jvm相关的问题. 垃圾回收以及优化总结 <JVM 垃圾回收器工作原理及使用实例介绍> 介绍常用的垃圾回收算法,垃圾收集器,垃圾收集器相关的调试参数. J ...