zoj 1610 Count the Colors(线段树延迟更新)
所谓的懒操作模板题。
学好acm,英语很重要。做题的时候看不明白题目的意思,我还拉着队友一块儿帮忙分析题意。最后确定了是线段树延迟更新果题。我就欣欣然上手敲了出来。
然后是漫长的段错误。。。。
第一次看见这种错误,还不知道什么意思,在那儿瞎改了好久也没过。最后看了下别人的代码,才知道这个题不管给的n是几,建树都是按0~8000建树。。。。
亏我第一次提交之前还跟yyf商量说这道题的n很奇怪,怎么又两个意思。。。。
我的zoj第一题。
#include<stdio.h>
#include<string.h>
#define N 8005
struct node
{
int x,y;
int flag;
}a[N*3];
int mark[N];
void CreatTree(int t,int x,int y)
{
a[t].x=x;
a[t].y=y;
a[t].flag=-1;
if(x==y)
return ;
int temp=t*2;
int mid=(x+y)/2;
CreatTree(temp,x,mid);
CreatTree(temp+1,mid+1,y);
return ;
}
void InsertTree(int t,int x,int y,int k)
{
if(a[t].x==x&&a[t].y==y)
{
a[t].flag=k;
return ;
}
int temp=t*2;
int mid=(a[t].x+a[t].y)/2;
if(a[t].flag!=-1)
{
a[temp].flag=a[t].flag;
a[temp+1].flag=a[t].flag;
a[t].flag=-1;
}
if(y<=mid)
InsertTree(temp,x,y,k);
else if(x>mid)
InsertTree(temp+1,x,y,k);
else
{
InsertTree(temp,x,mid,k);
InsertTree(temp+1,mid+1,y,k);
}
return ;
}
int FindTree(int t,int x)
{
if(a[t].x==a[t].y)
return a[t].flag;
int temp=t*2;
int mid=(a[t].x+a[t].y)/2;
if(a[t].flag!=-1)
{
a[temp].flag=a[t].flag;
a[temp+1].flag=a[t].flag;
a[t].flag=-1;
} if(x<=mid)
return FindTree(temp,x);
else
return FindTree(temp+1,x);
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
CreatTree(1,1,8001);
int i;
for(i=1;i<=n;i++)
{
int x,y,k;
scanf("%d%d%d",&x,&y,&k);
int temp;
if(x>y)
{
temp=x;
x=y;
y=temp;
}
x++;
InsertTree(1,x,y,k);
}
memset(mark,0,sizeof(mark));
int t=-1;
for(i=1;i<=8001;i++)
{
int temp;
temp=FindTree(1,i);
if(temp==t)
continue;
else if(temp!=t&&temp!=-1)
mark[temp]++;
t=temp;
}
for(i=0;i<=8001;i++)
{
if(mark[i]!=0)
printf("%d %d\n",i,mark[i]);
}
printf("\n");
}
return 0;
}
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 (线段树成段更新)
题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...
- 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 5023 线段树延迟更新+状态压缩
/* 线段树延迟更新+状态压缩 */ #include<stdio.h> #define N 1100000 struct node { int x,y,yanchi,sum; }a[N* ...
- 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 (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
- ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)
1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...
随机推荐
- 在 CentOS 上安装 Tomcat7
1. 下载 #可以直接在官网下载然后传到服务器上,也可以直接下载#下载地址:http://tomcat.apache.org/download-70.cgi 2. 安装 # tar -xzvf apa ...
- POI导出Excel文档通用工具方法
import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Map; imp ...
- IS2009制作Oracle 静默安装包(一)感谢空白先生特许授权
原文:IS2009制作Oracle 静默安装包(一)感谢空白先生特许授权 上一篇: MyEclipse中消除frame引起的“the file XXX can not be found.Please ...
- userAgent,JS这么屌的用户代理,你造吗?——判断浏览器内核、浏览器、浏览器平台、windows操作系统版本、移动设备、游戏系统
1.识别浏览器呈现引擎 为了不在全局作用域中添加多余变量,这里使用单例模式(什么是单例模式?)来封装检测脚本.检测脚本的基本代码如下所示: var client = function() { var ...
- JavaScript一个类继承中实现
JavaScript类是默认原型对象继承: var Person = function() { this.name = "people"; this.hello = functio ...
- POJ3187 Backward Digit Sums
给出杨辉三角的顶点值,求底边各个数的值.直接DFS就好了 #include<iostream> #include<cstdio> #include<cstring> ...
- 查询在应用程序运行得很慢, 但在SSMS运行得很快的原因探究
原文:查询在应用程序运行得很慢, 但在SSMS运行得很快的原因探究 查询在应用程序运行得很慢, 但在SSMS运行得很快的原因探究 -理解性能疑点 1 引言 内容来自http://www.so ...
- How do I create an IIS application and application pool using InnoSetup script
Create an IIS application. Create a new IIS application pool and set it's .NET version to 4. Set the ...
- Android最新支持包Design简介
Android 5.0 Lollipop是曾经最著名的Android发布之一,这样说很大一部分原因是材料设计的引入,而材料设计则是一种刷新了整个Android体验的设计语言.这个详细说明是开始适应材料 ...
- 使用UpdatePanel控件
使用UpdatePanel控件(二) UpdatePanel可以用来创建丰富的局部更新Web应用程序,它是ASP.NET 2.0 AJAX Extensions中很重要的一个控件,其强大之处在于不用编 ...