Count the Colors ZOJ - 1610 区间颜色覆盖
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int MAXN=;
struct Node
{
int l,r;
int color;
}tr[MAXN*];
int color[MAXN];
int temp;
void build(int i,int l,int r)
{
tr[i].l=l;
tr[i].r=r;
//-1表示没有颜色
tr[i].color=-;
if(l+==r)
return;
int mid=((l+r)>>);
build(i<<,l,mid);
build((i<<)|,mid,r);
}
void insert(int i,int l,int r,int c)
{
if(l==r)
return;
if(tr[i].color==c)
return;
if(l<=tr[i].l&&r>=tr[i].r)
{
tr[i].color=c;
return;
}
//存在颜色,往下更新
if(tr[i].color>=)
{
tr[i<<].color=tr[i].color;
tr[(i<<)|].color=tr[i].color;
//表示有多种颜色
tr[i].color=-;
}
int mid=((tr[i].l+tr[i].r)>>);
if(r<=mid)
insert(i<<,l,r,c);
else if(l>=mid)
insert((i<<)|,l,r,c);
else
{
insert(i<<,l,mid,c);
insert((i<<)|,mid,r,c);
}
tr[i].color=-;
}
//统计各颜色的段数
void query(int i)
{
if(tr[i].color==-)
{
temp=-;
return;
}
if(tr[i].color!=-)
{
//temp存的是前一段的颜色
if(tr[i].color!=temp)
{
color[tr[i].color]++;
temp=tr[i].color;
}
return;
}
if(tr[i].l+!=tr[i].r)
{
query(i<<);
query((i<<)|);
}
}
int main()
{
int n,a,b,c;
int Max;
while(scanf("%d",&n)!=EOF)
{
build(,,);
Max=;
while(n--)
{
scanf("%d%d%d",&a,&b,&c);
insert(,a,b,c);
if(c>Max)
Max=c;
}
temp=-;
memset(color,,sizeof(color));
query();
for(int i=;i<=Max;i++)
if(color[i])
printf("%d %d\n",i,color[i]);
printf("\n");
}
return ;
}
Count the Colors ZOJ - 1610 区间颜色覆盖的更多相关文章
- F - Count the Colors - zoj 1610(区间覆盖)
有一块很长的画布,现在想在这块画布上画一些颜色,不过后面画的颜色会把前面画的颜色覆盖掉,现在想知道画完后这块画布的颜色分布,比如 1号颜色有几块,2号颜色有几块.... *************** ...
- (线段树) Count the Colors --ZOJ --1610
链接: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82832#problem/F http://acm.zju.edu.cn/onli ...
- F - Count the Colors ZOJ - 1610 线段树染色(染区间映射)
题意:给一段0-8000的线段染色 问最后 颜色x 有几段 题解:标准线段树 但是没有push_up 最后查询是单点按顺序查询每一个点 考虑过使用区间来维护不同的线段有多少种各色的线段 思路是 ...
- 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 线段树区间更新/暴力
Count the Colors Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...
- 线段树专题—ZOJ1610 Count the Colors(涂区间,直接tag标记)
Painting some colored segments on a line, some previously painted segments may be covered by some th ...
- 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 ZOJ - 1610 传送门 线段树区间染色求染色的片段数 #include <cstdio> #include <iostream> #in ...
- F - Count the Colors
F - Count the Colors ZOJ - 1610 思路:调了一个小时,但是发现自己线段树木有写错,颜色统计出了错误.但是不明白自己颜色统计为什么错了. 求大佬指点迷津.思路很简单,就 ...
随机推荐
- 非常NB的一款快捷启动软件--Merry
Merry 被设计为了能将日常重复性操作简化为一个快捷键或者命令.Merry 采用完全开放的体系, 可以使用 Lua 或者外部程序来扩展 Merry 的功能. 另附一个自己扩展的LUA脚本: --启动 ...
- Pycharm2019.1.1永久破解
声明:不做商业用途,电脑系统win10专业版,亲测有效. 1,下载新版破解补丁+安装包 网盘链接 提取码:hn0u 下载补丁文件 jetbrains-agent.jar 并将它放置到 pycharm安 ...
- Codeforces_814
A.b序列从大到小填a序列中的0,在判断. #include<bits/stdc++.h> using namespace std; ],b[]; int main() { ios::sy ...
- [Python源码剖析]获取Python小整数集合范围
#!/usr/bin/env python #-*- coding=utf-8 -*- small_ints = dict() for i in range(-10000,10000): small_ ...
- ELK:收集Docker容器日志
简介 之前写过一篇博客 ELK:日志收集分析平台,介绍了在Centos7系统上部署配置使用ELK的方法,随着容器化时代的到来,容器化部署成为一种很方便的部署方式,收集容器日志也成为刚需.本篇文档从 容 ...
- java jni 调用c语言函数
今日在hibernate源代码中遇到了native关键词,甚是陌生,就查了点资料,对native是什么东西有了那么一点了解,并做一小记. native关键字说明其修饰的方法是一个原生态方法,方法对应的 ...
- False注入,以及SQL注入技巧总结
title: False注入,以及SQL注入技巧总结 date: 2017-04-25 00:23:31 tags: ['SQL注入'] --- 利用False我们可以绕过一些特定的WAF以及一些未来 ...
- mysql8.0编译安装
#下载依赖 yum install -y ncurses ncurses-devel cmake bison bison-devel openssl openssl-libs openssl-deve ...
- 《自拍教程24》在Windows上配置环境变量
我们说的环境变量,一般是指的是Path环境变量. 第一步:点击"我的电脑",右键,"属性" 第二步:点击"高级系统设置",弹出的窗口选&qu ...
- 如何使用Xcode调试Shader代码Bug导致的渲染问题
我最近发现了一个与Unity中的表面着色器有关的小Bug. 你可以看到如下所示的渲染瑕疵. 有时人们会将相似的渲染瑕疵归因于同时使用HDR和Bloom效果,但实际上,表面着色器是错误的,至少在本文中所 ...