BZOJ4631 : 踩气球
将所有盒子插入链表,每当一个盒子变空时,从链表里删去它。
查一下它的前驱后继$pre,nxt$,那么$[pre+1,nxt-1]$都是空的。
每次对于$[A,B]$这段都为空,对小朋友按$R$维护线段树,维护区间内$L$的最大值,不断询问$[1,B]$内$L$的最大值,如果$\geq A$则拿出来。
时间复杂度$O(m\log m)$。
#include<cstdio>
#include<algorithm>
#define N 100010
int n,m,q,i,j,a[N],pre[N],nxt[N],c[N],v[262150],ans;
struct P{int l,r;}b[N];
inline bool cmp(const P&a,const P&b){return a.r<b.r;}
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
inline int merge(int x,int y){return b[x].l>b[y].l?x:y;}
void build(int x,int a,int b){
if(a==b){v[x]=a;return;}
int mid=(a+b)>>1;
build(x<<1,a,mid),build(x<<1|1,mid+1,b);
v[x]=merge(v[x<<1],v[x<<1|1]);
}
void change(int x,int a,int b,int c){
if(a==b){v[x]=0;return;}
int mid=(a+b)>>1;
if(c<=mid)change(x<<1,a,mid,c);else change(x<<1|1,mid+1,b,c);
v[x]=merge(v[x<<1],v[x<<1|1]);
}
int ask(int x,int a,int b,int d){
if(b<=d)return v[x];
int mid=(a+b)>>1,t=ask(x<<1,a,mid,d);
if(d>mid)t=merge(t,ask(x<<1|1,mid+1,b,d));
return t;
}
inline void del(int x){
a[x]--;
if(a[x])return;
int l=pre[x],r=nxt[x];
nxt[l]=r,pre[r]=l;
r=c[r-1];
if(!r)return;
while(1){
int t=ask(1,1,m,r);
if(b[t].l<=l)return;
ans++;
change(1,1,m,t);
}
}
int main(){
read(n),read(m);
for(i=1;i<=n;i++)read(a[i]),pre[i]=i-1,nxt[i]=i+1;
for(i=1;i<=m;i++)read(b[i].l),read(b[i].r);
std::sort(b+1,b+m+1,cmp);
for(i=1;i<=m;i++)if(b[i].r!=b[i-1].r)for(j=b[i-1].r;j<b[i].r;j++)c[j]=i-1;
for(i=b[m].r;i<=n;i++)c[i]=m;
build(1,1,m);
read(q);
while(q--)read(i),del((i+ans-1)%n+1),printf("%d\n",ans);
return 0;
}
BZOJ4631 : 踩气球的更多相关文章
- bzoj4631踩气球
bzoj4631踩气球 题意: 有一个序列和一个区间集合,每次将序列中的一个数-1,求此时集合里有多少个区间和为0.序列大小≤100000,区间数≤100000,操作数≤100000. 题解: 此题解 ...
- 【BZOJ4631】踩气球 链表+线段树+堆
[BZOJ4631]踩气球 Description 六一儿童节到了, SHUXK 被迫陪着M个熊孩子玩一个无聊的游戏:有N个盒子从左到右排成一排,第i个盒子里装着Ai个气球. SHUXK 要进行Q次操 ...
- 【BZOJ-4631】踩气球 线段树 + STL
4631: 踩气球 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 224 Solved: 114[Submit][Status][Discuss] ...
- noj算法 踩气球 回溯法
描述: 六一儿童节,小朋友们做踩气球游戏,气球的编号是1-100,两位小朋友各踩了一些气球,要求他们报出自己所踩气球的编号的乘积.现在需要你编一个程序来判断他们的胜负,判断的规则是这样的:如果两人都说 ...
- bzoj 4631: 踩气球 线段树合并
4631: 踩气球 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 265 Solved: 136[Submit][Status][Discuss] ...
- 【BZOJ 4631】4631: 踩气球 (线段树)
4631: 踩气球 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 316 Solved: 153 Description 六一儿童节到了, SHUX ...
- [Luogu P4215] 踩气球 (线段树)
题面 传送门:https://www.luogu.org/problemnew/show/P4215 Solution 这题十分有意思. 首先,我们可以先想想离线做法,因为在线做法可以从离线做法推出. ...
- 【bzoj4631】踩气球 线段树
题解: 真是很zz 我都想到线段树分治的思路了... 不过还是一道好题 首先跟线段树分治一样将区间投射到线段树上去 每次修改如果该个区间修改为0,则对他们对应的特定区间-1 这样每个区间会有一次变0, ...
- 【BZOJ4631】踩气球 题解(线段树)
题目链接 ---------------------- 题目大意:给定一个长度为$n$的序列${a_i}$.现在有$m$个区间$[l_i,r_i]$和$q$个操作,每次选取一个$x$使得$a_x--$ ...
随机推荐
- 素数环(dfs+回溯)
题目描述: 输入正整数n,把整数1,2...n组成一个环,使得相邻两个数和为素数.输出时从整数1开始逆时针排列并且不能重复: 例样输入: 6 例样输出: 1 4 3 2 5 6 1 6 5 2 3 4 ...
- DB2 Z/os Load utility 使用
Use the LOAD online utility to load one or more tables of a table space. The LOAD utility loads reco ...
- Mysql获取时间
select now() 当前时间; SELECT curdate() 当天日期; select date_sub(curdate(),interval 1 day) 前一天日期; select ...
- js 删除确定
"<td><a href='shanchu.php?c={$v[0]}' onclick=\"return confirm('确定删除么?')\"> ...
- 防止别人ping自己的服务器
禁止被ping [root@GitLab ~]# echo >/proc/sys/net/ipv4/icmp_echo_ignore_all 无法被ping [root@NB ipv4]# pi ...
- 南阳理工 题目9:posters(离散化+线段树)
posters 时间限制:1000 ms | 内存限制:65535 KB 难度:6 描述 The citizens of Bytetown, AB, could not stand that ...
- sdut 2610:Boring Counting(第四届山东省省赛原题,划分树 + 二分)
Boring Counting Time Limit: 3000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 In this problem you a ...
- Oracle优化 -- 关于Database Buffer Cache相关参数DB_CACHE_SIZE的优化设置
select size_for_estimate, buffers_for_estimate ,ESTD_PHYSICAL_READ_factor,ESTD_PHYSICAL_READS from v ...
- Java Security: Illegal key size or default parameters?
来自:http://stackoverflow.com/questions/6481627/java-security-illegal-key-size-or-default-parameters I ...
- HTML Entity Sets - All
http://www.htmlentities.com/html/entities/ The view below displays the characters used in the offici ...