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

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

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

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

题目:

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. SQL注入导图

    本图来自信安之路学生渗透小组@辽宁-web-TwoDog, 博主觉得这张图画的很好,所以贴在这里提供参考!

  2. zabbix3.0安装(本文引用51cto博主烂泥行天下的文章,我也是参考他写的文章安装的zabbix)

    但是由于他文章写的时间有点久了,上面的关于安装zabbix之前需要安装的zabbix3.0yum源的链接失效了,所有我找了2个能用的zabbix 3.0yum源,其他的就不再写了 安装zabbix3. ...

  3. 20165101刘天野 2018-2019-2《网络对抗技术》Exp1 逆向与Bof基础

    20165101刘天野 2018-2019-2<网络对抗技术>Exp1 逆向与Bof基础 1. 逆向及Bof基础实践说明 1.1 实践目标 本次实践的对象是一个名为pwn1的linux可执 ...

  4. 解决You have new mail in /var/spool/mail/root提示

    终端远程登陆后经常提示You have new mail in /var/spool/mail/root 这个提示是LINUX会定时查看LINUX各种状态做汇总,每经过一段时间会把汇总的信息发送的ro ...

  5. ubuntu16.04的anacoda内置的spyder不支持中文【学习笔记】

    执行下面的语句:将libfcitxplatforminputcontextplugin.so复制到anaconda2的安装目录下的platforminputcontexts目录重启生效 cp /usr ...

  6. IntelliJ IDEA 2017 创建SpringBoot项目, 及.jar没有主清单属性解决办法

    1. 创建项目:  File >> New >> Spring Initializr  选好 SDK, 及 依赖包(比如 Web >> Web ) .   需要使用 ...

  7. SQL时间戳日期时间转换

    将时间戳转换为日期格式:比如降1455504268→2016-02-15 10:44:28 select device.register_time a,FROM_UNIXTIME(device.reg ...

  8. postgre数据库插入错误:prepared statement “S_1”already exist, 解决办法

    在使用kettle工具(数据迁移软件)在postgre数据库中插入记录时,出现如下错误,解决办法: 在/etc/pgsql/pgbouncer.ini中修改配置,设置 server_reset_que ...

  9. Java 常用正则表达式 - 转载

    只能输入数字:"^[0-9]*$".只能输入n位的数字:"^\d{n}$".只能输入至少n位的数字:"^\d{n,}$".只能输入m~n位的 ...

  10. [日常训练]AekdyCoin的跳棋

    Description $AekdyCoin$正在玩一个游戏,该游戏要用到两副牌和一个数轴和一个棋子. 刚开始的时候棋子位于数轴的$0$位置.然后$AekdyCoin$交替的从两副牌中抽取一张牌,然后 ...