所谓的懒操作模板题。

学好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(线段树延迟更新)的更多相关文章

  1. zoj 1610 Count the Colors 线段树区间更新/暴力

    Count the Colors Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/show ...

  2. ZOJ 1610 Count the Color(线段树区间更新)

    描述Painting some colored segments on a line, some previously painted segments may be covered by some ...

  3. ZOJ 1610 Count the Colors (线段树成段更新)

    题意 : 给出 n 个染色操作,问你到最后区间上能看见的各个颜色所拥有的区间块有多少个 分析 : 使用线段树成段更新然后再暴力查询总区间的颜色信息即可,这里需要注意的是给区间染色,而不是给点染色,所以 ...

  4. ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)

    Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on ...

  5. 【POJ 2777】 Count Color(线段树区间更新与查询)

    [POJ 2777] Count Color(线段树区间更新与查询) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4094 ...

  6. hdu 5023 线段树延迟更新+状态压缩

    /* 线段树延迟更新+状态压缩 */ #include<stdio.h> #define N 1100000 struct node { int x,y,yanchi,sum; }a[N* ...

  7. ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】

    任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...

  8. ZOJ 1610 Count the Colors (线段树区间更新)

    题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...

  9. ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)

    1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...

随机推荐

  1. Java项目生成静态页面

    第一次做项目需要生成静态页面,网上很多大牛对将网页生成静态页面有很多异议.说一下我的看法. 不外乎有以下因素: 1.从页面加载时间来看:静态页面不需要与数据库建立连接,尤其是访问数据量较大的页面,这种 ...

  2. Sql Server 存储过程中查询数据无法使用 Union(All)

    原文:Sql Server 存储过程中查询数据无法使用 Union(All) 微软Sql Server数据库中,书写存储过程时,关于查询数据,无法使用Union(All)关联多个查询. 1.先看一段正 ...

  3. fatjar eclipse4.4 java项目的jar包一起打包 net.sf.fjep.fatjar_0.0.32.jar

    1.下载net.sf.fjep.fatjar_0.0.32.jar  http://files.cnblogs.com/files/milanmi/net.sf.fjep.fatjar_0.0.32. ...

  4. CSS学习笔记:transition

    CSS3的transition允许CSS的属性值在一定的时间区间内平滑地过渡.这种效果可以在鼠标单击.获得焦点.被点击或对元素任何改变中触发,并圆滑地以动画效果改变CSS的属性值. 1.transit ...

  5. js 图片点击放大功能

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. Best JavaScript Tools for Developers

    JavaScript solves multiple purposes; it helps you to create interactive websites, web applications, ...

  7. Asp.Net MVC页面静态化功能实现一:利用IHttpModule,摒弃ResultFilter

    上一篇有提到利用IHttpModule和ResultFilter实现页面静态化功能.后来经过一些改动,将ResultFilter中要实现的功能全部转移到IHttpModule中来实现 Asp.Net ...

  8. MVC5入门学习系列④

    添加Model且简单的使用EF 对于EF(EntityFramework)不了解的朋友可以去百度文科或者在园子里搜一些简资源看下,假如和我一样知道EF的概念,那么就知道EF有一个code first的 ...

  9. 学习Python编程的11个精品资源

    本文由 伯乐在线 - atupal 翻译自 Alex Ivanovs.欢迎加入技术翻译小组.转载请参见文章末尾处的要求. 用 Python 写代码并不难,事实上,它一直以来都是被声称为最容易学习的编程 ...

  10. Ninject的项目情况

    Ninject的项目情况 首先,它有很多的项目组成,适合不同的环境,当然它有几个基本的核心库. 为什么它会有这么多的库呢?因为轻量级,易于使用和被扩展是它的目标,代码越是少,你使用代码的可能性越高嘛. ...