D - Inna and Sequence

线段数维护区间有几个没有被删除的数,利用线段树的二分找第几个数在哪里,然后模拟更新就好啦。

#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii make_pair
#define ll long long
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std;
const int inf=0x3f3f3f3f;
const int N=2e6+;
int n,m,a[N],dfn;
struct seg_tree
{
struct node
{
int l,r,sum,v;
}a[N<<];
void Build(int l,int r,int rt)
{
a[rt].l=l; a[rt].r=r;
a[rt].sum=a[rt].v=;
if(l==r) return;
int mid=(l+r)>>;
Build(l,mid,rt<<);
Build(mid+,r,rt<<|);
}
void Modify(int pos,int rt,int v)
{
int l=a[rt].l,r=a[rt].r;
if(l==r && l==pos)
{
a[rt].v=v;
a[rt].sum=;
return;
}
int mid=(l+r)>>;
if(pos<=mid) Modify(pos,rt<<,v);
else Modify(pos,rt<<|,v);
a[rt].sum=a[rt<<].sum+a[rt<<|].sum;
}
void Delete(int pos,int rt)
{
int l=a[rt].l, r=a[rt].r;
if(l==r)
{
a[rt].sum=;
a[rt].v=;
return;
}
if(pos<=a[rt<<].sum)
Delete(pos,rt<<);
else
Delete(pos-a[rt<<].sum,rt<<|);
a[rt].sum=a[rt<<].sum+a[rt<<|].sum;
}
void Print(int rt)
{
int l=a[rt].l,r=a[rt].r;
if(l==r)
{
printf("%d",a[rt].v);
return;
}
if(a[rt<<].sum)
Print(rt<<);
if(a[rt<<|].sum)
Print(rt<<|);
}
}seg;
int main()
{
read(n),read(m);
for(int i=;i<m;i++)
read(a[i]);
seg.Build(,n+,);
while(n--)
{
int op; read(op);
if(op==-)
{
for(int i=;i<m;i++)
{
if(seg.a[].sum<a[i]-i)
break;
seg.Delete(a[i]-i,);
}
}
else seg.Modify(++dfn,,op);
}
if(!seg.a[].sum)
puts("Poor stack!");
else
seg.Print();
return ;
}

Codeforces Round #220 (Div. 2) D - Inna and Sequence的更多相关文章

  1. Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s

    C. Inna and Candy Boxes   Inna loves sweets very much. She has n closed present boxes lines up in a ...

  2. Codeforces Round #234 (Div. 2) B. Inna and New Matrix of Candies

    B. Inna and New Matrix of Candies time limit per test 1 second memory limit per test 256 megabytes i ...

  3. Codeforces Round #234 (Div. 2) B. Inna and New Matrix of Candies SET的妙用

    B. Inna and New Matrix of Candies time limit per test 1 second memory limit per test 256 megabytes i ...

  4. Codeforces Round #234 (Div. 2) A. Inna and Choose Options 模拟题

    A. Inna and Choose Options time limit per test 1 second memory limit per test 256 megabytes input st ...

  5. Codeforces Round #220 (Div. 2)

    链接 毒瘤场..... A题:,真码农题,直接干爆,枚举,注意越界问题,wa37的看这组数据1 10 1 5 2 2,应该是no //#pragma comment(linker, "/st ...

  6. Codeforces Round #234 (Div. 2) A. Inna and Choose Options

    A. Inna and Choose Options time limit per test 1 second memory limit per test 256 megabytes input st ...

  7. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟

    题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...

  8. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)

    题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...

  9. Codeforces Round #277 (Div. 2) E. LIS of Sequence DP

    E. LIS of Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/pr ...

随机推荐

  1. Bootstrap -- 文件上传插件File Input的使用

    BootstrapFileInput下载参考:http://www.jq22.com/jquery-info5231 网友经验参见:http://www.cnblogs.com/wuhuacong/p ...

  2. 20155228 2016-2017-2 《Java程序设计》第7周学习总结

    20155228 2016-2017-2 <Java程序设计>第7周学习总结 教材学习内容总结 Lambda 方法参考的特性,在重用现有的API上扮演了重要的角色.重用现有方法操作,可以避 ...

  3. requsets模块和beautifulsoup模块

    2.requests模块方法 requests是基于Python开发的HTTP库,使用Requests可以轻而易举的完成浏览器可有的任何操作. request.get() request.post() ...

  4. C++:error 1189(转)

    在VS 2013中编译程序时出现错误: 错误提示1: error C1189: #error : Building MFC application with /MD[d] (CRT dll versi ...

  5. android 加载图片

    package mydemo.mycom.demo2; import android.graphics.Bitmap; import android.graphics.BitmapFactory; i ...

  6. POJ3635 Full Tank?【Dijkstra+DP】

    题意: n个城市之间有m条双向路.每条路要耗费一定的油量.每个城市的油价是固定并且已经给出的.有q个询问,表示从城市s走到e,油箱的容量为c,求最便宜的方案. 思路: 用Dijkstra+Heap即可 ...

  7. Ubuntu 14.04 apt-get更换阿里云源

    https://blog.csdn.net/satomic/article/details/78997611

  8. C++学习5-面向对象编程基础(构造函数、转换构造、静态数据成员、静态成员函数、友元)

    知识点学习 类 const作用 C语言的const限定符的含义为"一个不能改变值的变量",C++的const限定符的含义为"一个有类型描述的常量": const ...

  9. Python 优雅获取本机 IP 方法【转】

    转自:https://www.cnblogs.com/lfxiao/p/9672975.html 见过很多获取服务器本地IP的代码,个人觉得都不是很好,例如以下这些 不推荐:靠猜测去获取本地IP方法 ...

  10. (记录合并)union和union all的区别

    SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION内部的SELECT语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每条SE ...