ZOJ - 1610 Count the Colors(线段树区间更新)
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(线段树区间更新)的更多相关文章
- zoj 1610 Count the Colors 线段树区间更新/暴力
Count the Colors Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- ZOJ 1610 Count the Color(线段树区间更新)
描述Painting some colored segments on a line, some previously painted segments may be covered by some ...
- ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- ZOJ 1610 Count the Colors (线段树成段更新)
题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...
- 【POJ 2777】 Count Color(线段树区间更新与查询)
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4094 ...
- ZOJ 1610.Count the Colors-线段树(区间染色、区间更新、单点查询)-有点小坑(染色片段)
ZOJ Problem Set - 1610 Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting s ...
- ZOJ 5638——Prime Query——————【线段树区间更新,区间查询,单点更新】
Prime Query Time Limit: 1 Second Memory Limit: 196608 KB You are given a simple task. Given a s ...
- poj 2777 Count Color(线段树 区间更新)
题目:http://poj.org/problem?id=2777 区间更新,比点更新多一点内容, 详见注释, 参考了一下别人的博客.... 参考博客:http://www.2cto.com/kf/ ...
- ZOJ1610 Count the Colors —— 线段树 区间染色
题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...
- ZOJ 1610 Count the Colors (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
随机推荐
- 【XSY1602】安全网络 树形DP 数学
题目大意 有一颗树,要为每个节点赋一个值\(l_i\leq a_i\leq r_i\),使得任意相邻的节点互素.然后对每个节点统计\(a_i\)在所有可能的情况中的和. \(n\leq 50,1\le ...
- zabbix python 微信告警脚本
测试zabbix的微信告警耗费了大量时间,使用了开源工具(OneOaaS weixin-alert).shell脚本工具(手动执行正常,服务器调用失败),均没有实现相关功能以下是自己优化过的Pytho ...
- CS Academy Gcd on a Circle(dp + 线段树)
题意 给你一个长为 \(n\) 的环,你可以把它断成任意 \(k\) 段 \((1 < k \le n)\) ,使得每一段的 \(\gcd\) 都 \(>1\) . 问总共有多少种方案,对 ...
- 【HDU3032】Nim or not Nim?(博弈论)
[HDU3032]Nim or not Nim?(博弈论) 题面 HDU 题解 \(Multi-SG\)模板题 #include<iostream> #include<cstdio& ...
- ELK部署详解--kibana
kibana.yml # Kibana is served by a back end server. This setting specifies the port to use.#端口server ...
- Linux及Windows查看占用端口的进程
想必大家在部署环境启动服务的时候,会遇到服务起不起来的问题,看日志,说是端口被占用了. 有的时候,我们不想改端口,那么,就需要去查看到底是哪个应用把这个端口给占用了,然后干掉它即可. 下面分别列举li ...
- 小白眼中的AI之~Numpy基础
周末码一文,明天见矩阵- 其实Numpy之类的单讲特别没意思,但不稍微说下后面说实际应用又不行,所以大家就练练手吧 代码裤子: https://github.com/lotapp/BaseCode ...
- 跟着underscore学防抖
前言 在前端开发中会遇到一些频繁的事件触发,比如: window 的 resize.scroll mousedown.mousemove keyup.keydown -- 为此,我们举个示例代码来了解 ...
- JavaScript深入系列(一)--原型和原型链详解
构造函数创建对象 首先我们先使用构造函数创建一个对象: function Person(){} var person = new Person(); person.name = 'tom'; cons ...
- java面试——jvm
背景:用来总结java面试过程中与jvm相关的问题. 垃圾回收以及优化总结 <JVM 垃圾回收器工作原理及使用实例介绍> 介绍常用的垃圾回收算法,垃圾收集器,垃圾收集器相关的调试参数. J ...