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

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

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

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

题目:

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. Python3:Django根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete'

    Python3:Django根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete' 一.分析 在 ...

  2. zabbix监控nginx的性能

    1.nginx配置 需要使用zabbix监控nginx,首先nginx需要配置ngx_status,在nginx的配置文件中加入红框中的配置,然后重启nginx如下图所示: location /ngx ...

  3. [BZOJ1018]堵塞的交通traffic

    Description 有一天,由于某种穿越现象作用,你来到了传说中的小人国.小人国的布局非常奇特,整个国家的交通系统可以被看成是一个2行C列的矩形网格,网格上的每个点代表一个城市,相邻的城市之间有一 ...

  4. Quartz(1)--框架简介

    一.概述 Quartz是一个完全由Java编写的开源任务调度的框架,通过触发器设置作业定时运行规则,控制作业的运行时间.主要用来执行定时任务,如:定时发送信息.定时生成报表等等. 二.为什么会选择Qu ...

  5. PAT1037. Magic Coupon (25)

    #include <iostream> #include <algorithm> #include <vector> using namespace std; in ...

  6. skynet之伪取消定时器

    1.截至目前群里的成员已经对skynet中的timeout提出了更多的要求.目前skynet提供的定时器是倒计时形式,且定时器一旦设置后,便不能撤销(至少目前的实现是这样),然后调用 cb 最近有人提 ...

  7. Ceph 纠删码介绍

    http://ceph.org.cn/2016/08/01/ceph-%E7%BA%A0%E5%88%A0%E7%A0%81%E4%BB%8B%E7%BB%8D/

  8. LeetCode第[26]题(Java):Remove Duplicates from Sorted Array 标签:Array

    题目难度:Easy 题目: Given a sorted array, remove the duplicates in-place such that each element appear onl ...

  9. linux sed使用(转)

    sed入门详解教程 sed 是一个比较古老的,功能十分强大的用于文本处理的流编辑器,加上正则表达式的支持,可以进行大量的复杂的文本编辑操作.sed 本身是一个非常复杂的工具,有专门的书籍讲解 sed ...

  10. easyui datagrid 行编辑功能

    datagrid现在具有行编辑能力了,使用时只须在columns中为需要编辑的列添加一个editor属性,编辑保存时同时具有数据校验能力. 看一个例子效果图: 代码如下: $('#tt').datag ...