[ZOJ1610]Count the Colors(线段树,区间染色,单点查询)
题目链接:http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=1610
题意:给一个长8000的绳子,向上染色。一共有n段被染色,问染色后共有多少不同的色段。注意假如相邻两个线段同色,那么算作一条线段。
线段树区间更新,不需要pushUP操作,因为查询和非叶节点无关。找长线段的时候首先定位最靠左那根,然后判后面是否与前面的线段颜色相等。注意有可能出现两条线段中间没有染色的情况,这时候查询返回一个无关值,这时候重置p即可。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; #define fr first
#define sc second
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Fread() freopen("in", "r", stdin)
#define Fwrite() freopen("out", "w", stdout)
#define Rep(i, n) for(int i = 0; i < (n); i++)
#define For(i, a, n) for(int i = (a); i < (n); i++)
#define Cls(a) memset((a), (0), sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a)) #define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
const int maxn = ;
int sum[maxn<<];
int vis[maxn];
int n, a, b, c; void pushDOWN(int rt) {
if(sum[rt] != -) {
sum[rt<<] = sum[rt<<|] = sum[rt];
sum[rt] = -;
}
} void update(int L, int R, int c, int l, int r, int rt) {
if(L <= l && r <= R) {
sum[rt] = c;
return;
}
pushDOWN(rt);
int m = (l + r) >> ;
if(L <= m) update(L, R, c, lson);
if(R > m) update(L, R, c, rson);
} int query(int p, int l, int r, int rt) {
if(l == r) {
return sum[rt];
}
pushDOWN(rt);
int m = (l + r) >> ;
if(p <= m) return query(p, lson);
else return query(p, rson);
} int main() {
// Fread();
while(~Rint(n)) {
int lo = 0x7f7f;
Clr(sum, -); Cls(vis);
Rep(i, n) {
Rint(a), Rint(b), Rint(c);
lo = min(lo, a+);
update(a+, b, c, , , );
}
int p = query(lo, , , );
vis[p]++;
For(i, lo+, ) {
int t = query(i, , , );
if(t == -) {
p = -;
continue;
}
if(t != p) {
vis[t]++;
p = t;
} }
Rep(i, ) {
if(vis[i]) printf("%d %d\n", i, vis[i]);
}
printf("\n");
}
return ;
}
[ZOJ1610]Count the Colors(线段树,区间染色,单点查询)的更多相关文章
- 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(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- 【POJ 2777】 Count Color(线段树区间更新与查询)
[POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4094 ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】
任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...
- zoj 1610 Count the Colors 线段树区间更新/暴力
Count the Colors Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- HDU 5861 Road 线段树区间更新单点查询
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...
- HDU 5861 Road(线段树 区间修改 单点查询)
Road Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- D - Mayor's posters POJ - 2528 离散化+线段树 区间修改单点查询
题意 贴海报 最后可以看到多少海报 思路 :离散化大区间 其中[1,4] [5,6]不能离散化成[1,2] [2,3]因为这样破坏了他们的非相邻关系 每次离散化区间 [x,y]时 把y+1点也加入 ...
随机推荐
- switch..case函数的基础使用一
基本作用:switch中的参数与case的值进行比对,相等则进入case. JDK1.7 switch支持int.Integer.String类型 package com.my.test; impor ...
- SVN--VisualSVN server 服务端和 TortoiseSVN客户端的基础使用
前言 在上一文http://www.cnblogs.com/wql025/p/5177699.html中,我们讲到了使用SVN的第一步,即下载.安装SVN的服务端软件--VisualSVN serve ...
- HTML/CSS中常遇到的bug 一些注意事项总结
1.IE6下横向双倍margin bug (触发条件:块属性标签:float:横向margin设置:IE6下.解决办法:css中加入display:inline.) 2.css中公用属性首先声明:如对 ...
- C编程实现2的1000次方(使程序中的n=1000即可)
#include<stdio.h> #include<malloc.h> void double_(int n) { ,j,s,jw=; p=(int *)malloc(siz ...
- Windows 进程通信 之 DDE技术
DDE (Dynamic Data Exchange,DDE)动态数据交换,是一种进程间通信机制,它最早是随着Windows由微软提出的.当前大部分软件仍旧支持DDE,但最近十年里微软已经停止发展DD ...
- uva 10910
简单dp /************************************************************************* > Author: xlc2845 ...
- 设置HTTP header方式
一, Server Code JSP----> <%@ page language="java" contentType="text/html; charse ...
- Cent Os 常用操作
开放端口 编辑iptables文件(/etc/sysconfig/iptables) -A INPUT -m state --state NEW -m tcp -p tcp --dport xx端口号 ...
- Chpater 10: Sorting
Internal Sort: Bubble O(n2) Selection O(n2) Insertion O(n2) Shell O(nlogn) Merge O(nlogn) Heap O(nl ...
- 将集成spring的项目从tomcat上移植到weblogic下存在的问题
当在weblogic下部署时, 1.需要jersey-servlet-xx.jar,jersey-core-xx.jar,jersey-server-xx.jar: 2.在web.xml中全局参数co ...