Count the Colors ZOJ - 1610
GO
题意:给一个区间,有n次染色操作,每次将[x1, x2]染为c,求最后每种颜色各有多少线段可以看到。
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<cstdlib> #include<queue> #include<set> #include<vector>using namespace std; #define INF 0x3f3f3f3f #define eps 1e-10 typedef long long LL; const int MAXN = 1e5+5; const int mod = 998244353;LL st[MAXN << 2]; int vis[MAXN]; void pushdown(int o) {if(st[o] != -1){st[o << 1] = st[o];st[o << 1 | 1] = st[o];st[o] = -1;return;} } void update(int o,int l,int r,int ql,int qr,int c) {if(ql <= l && r <= qr) {st[o] = c;return;}else {if(st[o] != c){pushdown(o);int m = (l + r) >> 1;if(ql <= m) update(o << 1,l,m,ql,qr,c);if(m + 1 <= qr) update(o << 1 | 1,m + 1,r,ql,qr,c);}else return;}} int last; void query(int o,int l,int r) {if(l == r){if(st[o] != -1 && st[o] != last)vis[st[o]]++;last = st[o];return;}pushdown(o);int m = (l + r) >> 1;query(o << 1,l,m);query(o << 1 | 1,m + 1,r); } int main() {int n;while(~scanf("%d",&n)){memset(st,-1,sizeof st);while(n--){int x,y,c;scanf("%d %d %d",&x,&y,&c);update(1,1,8000,x + 1,y,c);}memset(vis,0,sizeof vis);last = -1;query(1,1,8000);for(int i = 0; i <= 8000; i++)if(vis[i])printf("%d %d\n",i,vis[i]);printf("\n");} }
View Code
转载于:https://www.cnblogs.com/smallhester/p/11318534.html
Count the Colors ZOJ - 1610相关推荐
- F - Count the Colors - zoj 1610(区间覆盖)
有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 1号颜色有几块,2号颜色有几块.... *************** ...
- ZOJ 1610 Count the Colors
段树:延迟标志+暴力更新 我记得刚学段树做的时候这个话题WA一个版本.....如今,每分钟获得.... Count the Colors Time Limit: 2 Seconds Memo ...
- ZOJ 1610 Count the Colors (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
- ZOJ 1610 Count the Colors 【线段树】
<题目链接> 题目大意: 在[0,8000]这个区间内,不断进行一些操作,将其中的一些区间染成特定颜色,如果区间重复的话,后面染的色块会覆盖前面染的色块,问最终[0,8000]这个区间内每 ...
- POJ 2777 ZOJ 1610 HDU 1698 --线段树--区间更新
直接将这3题 放一起了 今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 ...
- HDU 1566 Count the Colors 树状树组 区间更新 单点求值
#include<bits/stdc++.h> using namespace std; const int lim = 100010; int n,c[lim];// 记录差分变化 vo ...
- java 泛型 class t_java 泛型中classT 和T的区别是什么?
public boolean edit(T entity) 和public T get(Class c, Serializable id)中这两种参数的定义和调用有什么区别? public boole ...
- kuangbin带你飞专题合集
题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...
- 算法学习经典例题整理
陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...
最新文章
- Javascript 的addEventListener()及attachEvent()区别分析
- FIFOQueue '_4_batch_processing/batch_join/fifo_queue' is closed and has insu
- .NET(C#):警惕PLINQ结果的无序性
- Node.js 多版本安装方式
- 配置MySQL8.0 环境变量
- 【图像处理】——opencv常用函数
- P3591 [POI2015]ODW(分块)
- python函数的使用方法_Python函数使用
- 重庆市南川隆化职业学校计算机,重庆市第十三届中等职业学校职业技能大赛“web前端开发”赛项在南川隆化职中举行...
- 利用栈将html源码解析为节点树
- CFS调度主要代码分析一
- visio2010最新密钥
- 数组、链表、哈希表(数据结构)-代码随想录
- testbed软件测试技巧,基于LDRA Testbed 软件的单元测试
- GPS经纬度坐标与XY坐标相互转换的python程序
- 物联网终端安全系列(之一) -- 物联网终端安全风险简析
- win7 设置 快速启动栏
- 蒟蒻的笔记本二、tarjan
- 中国慕课moocpython答案_中国大学慕课mooc2020用Python玩转数据题目答案
- 智慧城市行业领军企业一览表