【线段树区间修改】hdu3577
来源:互联网 发布:北京政务数据资源网 编辑:程序博客网 时间:2024/06/05 08:20
Fast Arrangement
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2228 Accepted Submission(s): 625
Problem Description
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.
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.
Input
The 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.
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.
Output
For 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.
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
13 61 61 63 41 51 22 4
Sample Output
Case 1:1 2 3 5线段树区间修改题。题意:k,q 一辆火车最多乘坐k个人,q个询问,问是否可以满足乘坐区间,可以的话就输出询问序列号// 思路:更新区间,每次累加1,当区间值为k时拒绝累加每次先询问是否满足条件,然后如果满足条件就update线段树进行区间修改。如果开始就考虑是否满足条件,如何在线段树里判断,就会有点烦。和上一道题其实是一样的,只不过这次存储的是区间的最大值。还是用到了懒惰标记。#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define maxn 1000005#define N 1000000int inc[maxn<<2];int sum[maxn<<2];int ans[N+5];void pushup(int rt){sum[rt]=max(sum[rt<<1],sum[rt<<1|1]);} void pushdown(int rt){if(inc[rt]){inc[rt<<1]+=inc[rt];inc[rt<<1|1]+=inc[rt];sum[rt<<1]+=inc[rt];sum[rt<<1|1]+=inc[rt];inc[rt]=0;}}void update(int L,int R,int val,int l,int r,int rt){sum[rt]+=val;if(L<=l && r<=R){inc[rt]+=val;return ;}pushdown(rt);int m=(l+r)>>1;if(L<=m)update(L,R,val,l,m,rt<<1);if(m<R)update(L,R,val,m+1,r,rt<<1|1);pushup(rt);}int query(int L,int R,int l,int r,int rt){if(L<=l && r<=R){return sum[rt];}pushdown(rt);int m=(l+r)>>1,ret=0;if(L<=m) ret=max(ret,query(L,R,l,m,rt<<1));if(m<R)ret=max(ret,query(L,R,m+1,r,rt<<1|1));return ret;}int main(){//freopen("q.in","r",stdin);int i,j;int k,q;int t=1,cas,len;int a,b;scanf("%d",&cas);while(cas--){len=0;memset(inc,0,sizeof(inc));memset(sum,0,sizeof(sum));scanf("%d%d",&k,&q);for(i=1;i<=q;i++){scanf("%d%d",&a,&b);b--;if(a>b)swap(a,b);int tmp=query(a,b,1,N,1);//cout<<tmp<<endl;if(tmp<k){//cout<<i<<endl;update(a,b,1,1,N,1);ans[len++]=i;}}printf("Case %d:\n",t++);for(i=0;i<len;i++)printf("%d ",ans[i]);printf("\n\n");}}
0 0
- 【线段树区间修改】hdu3577
- 线段树区间更新--hdu3577
- hdu3577-Fast Arrangement 线段树区间覆盖
- HDU3577:Fast Arrangement(线段树区间更新+lazy)
- HDU3577 离散化+线段树
- 线段树区间修改
- 线段树区间修改
- 线段树区间修改
- 线段树模板 区间加减 区间修改
- 线段树(区间修改,区间求和)
- 线段树区间修改+区间查询
- 线段树(区间修改,区间查询)
- [模板]-线段树-区间修改 + 区间查询
- codevs1080 线段树(区间修改+区间求和
- 区间修改lazy线段树
- 线段树区间修改hdu1698
- hdu1556 线段树 区间修改
- 【线段树--区间修改】poj3468
- java西天取经之路(三)JSP技术学习要点
- 84_2 构造一个随机发生器
- Scala 基础
- js 获取页面及屏幕大小
- springmvc之Excel文件上传并写入数据库
- 【线段树区间修改】hdu3577
- C 格式化输出问题 %2x与%x,有什么区别
- [原]零基础学习视频解码之安装ffmpeg
- Python之禅 by Tim Peters
- 日本免费Wi-Fi
- 用C++,调用浏览器打开一个网页
- 数据结构:二分查找算法
- js 倒计时示例
- 汇编语言:eax ... edi esp ebp寄存器简介