个人心得:线段树的延迟标志确实是减少了很多时间,思想比较简单,但是实现得时候和建立延迟的时候比较麻烦。

按照我的一些理解,就是更新时找到完全覆盖的区间时,更新延迟标志,不再往下更新,但此时父节点啥的都会更新,但是

递归思想到了这里还是会回去,所以在程序末尾进行往上更新就好了,同时,在查询的时候有延迟标志时要下放,

但是注意此时不会影响父节点的值,因为在更新延迟标志的时候就已经回溯把父节点更新了。

题目:

Chinese always have the railway tickets problem because of its' huge amount of passangers and stations. Now goverment need you to develop a new tickets query system. 
One train can just take k passangers. And each passanger can just buy one ticket from station a to station b. Each train cannot take more passangers any time. The one who buy the ticket earlier which can be sold will always get the ticket. 

InputThe input contains servel test cases. The first line is the case number. In each test case: 
The first line contains just one number k( 1 ≤ k ≤ 1000 ) and Q( 1 ≤ Q ≤ 100000 ) 
The following lines, each line contains two integers a and b, ( 1 ≤ a < b ≤ 1000000 ), indicate a query. 
Huge Input, scanf recommanded.OutputFor each test case, output three lines: 
Output the case number in the first line. 
If the ith query can be satisfied, output i. i starting from 1. output an blank-space after each number. 
Output a blank line after each test case.Sample Input

1
3 6
1 6
1 6
3 4
1 5
1 2
2 4

Sample Output

Case 1:
1 2 3 5
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
#define inf 1<<29
#define nu 4000005
#define maxnum 1000000
int n,k;
int maxelem;
int book[];
int flag=;
typedef struct
{
int left,right;
int sum;
int jf;
int mid(){
return (left+right)/;
} }Tree;
Tree tree[nu];
void buildtree(int root,int l,int r){
tree[root].left=l,tree[root].right=r;
tree[root].sum=tree[root].jf=;
if(l!=r){
buildtree(root*+,l,(l+r)/);
buildtree(root*+,(l+r)/+,r);
}
}
void updown(int root)
{ tree[root*+].jf+=tree[root].jf;
tree[root*+].jf+=tree[root].jf;
tree[root*+].sum+=tree[root].jf;
tree[root*+].sum+=tree[root].jf;
tree[root].jf=;
}
void upset(int root)
{
tree[root].sum=max(tree[root*+].sum,tree[root*+].sum);
}
int checktree(int root,int l,int r)
{
if(tree[root].left==l&&tree[root].right==r)
{
return tree[root].sum;
}
int mid=tree[root].mid();
if(tree[root].jf) updown(root);
if(r<=mid)
return checktree(root*+,l,r);
else if(l>mid)
return checktree(root*+,l,r);
else
{
return max(checktree(root*+,l,mid),checktree(root*+,mid+,r));
}
}
void inserttree(int root,int l,int r){
if(tree[root].left==l&&tree[root].right==r)
{
tree[root].jf+=;
tree[root].sum+=;
return ;
}
int mid=tree[root].mid();
if(tree[root].jf) updown(root);
if(r<=mid)
inserttree(root*+,l,r);
else if(l>mid)
inserttree(root*+,l,r);
else
{
inserttree(root*+,l,mid);
inserttree(root*+,mid+,r);
}
upset(root);
}
int main()
{
int t,j;
scanf("%d",&t);
for(j=;j<=t;j++){
scanf("%d%d",&k,&n);
buildtree(,,maxnum);
flag=;
memset(book,,sizeof(book));
for(int i=;i<=n;i++){
int a,b;
scanf("%d%d",&a,&b);
b--;
if(checktree(,a,b)<k){
book[flag++]=i;
inserttree(,a,b);
}
}
printf("Case %d:\n",j);
for(int p=;p<flag;p++)
{
printf("%d ",book[p]);
}
printf("\n\n");
}
return ;
}
												

Fast Arrangement (线段树,延迟标志)的更多相关文章

  1. HDU - 3577 Fast Arrangement 线段树

    Fast Arrangement Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. HDU 3577 Fast Arrangement (线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3577 题意不好理解,给你数字k表示这里车最多同时坐k个人,然后有q个询问,每个询问是每个人的上车和下车 ...

  3. HDU 3577 Fast Arrangement ( 线段树 成段更新 区间最值 区间最大覆盖次数 )

    线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...

  4. hdu 3577 Fast Arrangement(线段树区间修改,求区间最小值)

    Problem Description Chinese always have the railway tickets problem because of its' huge amount of p ...

  5. zoj 1610 Count the Colors(线段树延迟更新)

    所谓的懒操作模板题. 学好acm,英语很重要.做题的时候看不明白题目的意思,我还拉着队友一块儿帮忙分析题意.最后确定了是线段树延迟更新果题.我就欣欣然上手敲了出来. 然后是漫长的段错误.... 第一次 ...

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

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

  7. HDU 3468:A Simple Problem with Integers(线段树+延迟标记)

    A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... ...

  8. codevs 1690 开关灯 线段树+延迟标记

    1690 开关灯  时间限制: 1 s  空间限制: 128000 KB   题目描述 Description YYX家门前的街上有N(2<=N<=100000)盏路灯,在晚上六点之前,这 ...

  9. Tree(树链剖分+线段树延迟标记)

    Tree http://poj.org/problem?id=3237 Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 12 ...

  10. HDU4893--Wow! Such Sequence! (线段树 延迟标记)

    Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

随机推荐

  1. Linux系统crontab定时调度Python脚本

    Linux系统crontab定时调度Python脚本 一.Python脚本随Linux开机自动运行 #Python脚本:/home/edgar/auto.py #用root权限编辑以下文件:/etc/ ...

  2. Oracle大总结

    maven的常见两个指令说明 mvn install 是将你打好的jar包安装到你的本地库中,一般没有设置过是在 用户目录下的 .m2\下面.mvn package 只是将你的代码打包到输出目录,一般 ...

  3. MongoDB快速入门(十)- Limit(),Skip() 方法

    Limit() 方法 要限制 MongoDB 中的记录,需要使用 limit() 方法. limit() 方法接受一个数字型的参数,这是要显示的文档数. 语法: limit() 方法的基本语法如下 & ...

  4. JAVA基础补漏--内部类

    成员内部类 public class InnerClass { public static void main(String[] args) { System.out.println("++ ...

  5. 多线程-信号量Semaphore

    计数信号量用来控制同时访问某个特定资源的操作数量.Semaphore可以用于实现资源池,例如数据库连接池.我们可以构造一个固定长度的资源池,当资源池为空的时候,请求资源将会阻塞,而不是失败.当资源池非 ...

  6. angular 图片懒加载(延迟加载)

    github 原文 https://github.com/Treri/me-lazyload me-lazyload angular 的图像资源延迟加载指令 例子(Demo) 演示网站(Demo Si ...

  7. Spring:通配符的匹配很全面, 但无法找到元素 XXXXX' 的声明

    问题:配置Spring的时候容易发生如题的这样一个经常性的错误,错误如下(以context为例) org.springframework.beans.factory.xml.XmlBeanDefini ...

  8. 使用mybatis如果类属性名和数据库中的属性名不一样取值就会为null

    使用mybatis时如果类属性名和数据库中的属性名不一样取值就会为null 这是不能再去改变javabean中的属性,只能改变sql语句.语句如下所示: <select id="sel ...

  9. app与后台的token、sessionId、RSA加密登录认证与安全解决方案

    一.登录机制 粗略地分析, 登录机制主要分为登录验证.登录保持.登出三个部分.登录验证是指客户端提供用户名和密码,向服务器提出登录请求,服务器判断客户端是否可以登录并向客户端确认. 登录认保持是指客户 ...

  10. LightOJ - 1341唯一分解定理

    唯一分解定理 先分解面积,然后除2,再减去面积%长度==0的情况,注意毯子不能是正方形 #include<map> #include<set> #include<cmat ...