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. (cx_Oracle.DatabaseError) DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No such file or directory"

    打开https://oracle.github.io/odpi/doc/installation.html 官方相关如下 Oracle Instant Client RPM¶ To run ODPI- ...

  2. Maven 手动添加第三方依赖包及编译打包和java命令行编译JAVA文件并使用jar命令打包

    一,实例:新建了一个Maven项目,在eclipse中通过 build path –> configure path-.将依赖包添加到工程中后,eclipse不报错了.但是用Maven命令 mv ...

  3. ;(function ($, undefined){ })(jQuery); 的使用及说明

    对于很多初学者来说很难明白这表示什么,下边我将为大家介绍其相应的作用. 1.代码最前面的分号,可以防止多个文件压缩合并以为其他文件最后一行语句没加分号,而引起合并后的语法错误. 2.匿名函数(func ...

  4. Ansi与Unicode编码

    视频教程:Ansi与Unicode编码 大家在编程时经常遇到的数据类型: ● Ansi: char   代表一个字符  (CHAR) char *  代表一个字符串指针   (PCHAR    PST ...

  5. [JSOI2008]球形空间产生器 (高斯消元)

    [JSOI2008]球形空间产生器 \(solution:\) 非常明显的一道高斯消元.给了你n+1个球上的位置,我们知道球上任何一点到球心的距离是相等,所以我们 可以利用这一个性质.我们用n+1个球 ...

  6. mongodb系列~mongo常用命令

    mongodb常用命令大全1 索引相关命令 db.chenfeng.ensureIndex({"riqi":1}) 添加索引会阻塞nohup mongo --eval " ...

  7. Eclipse文件路径

    经常我们需要读取某个文件,一般情况下,在Eclipse工程中,路径为./src/....

  8. Django配置图片上传

    本文首先实现django中上传图片的过程,然后解决富文本编辑器文件上传的问题. 一. 上传图片 1.在 settings.py 中配置MEDIA_URL  和 MEDIA_ROOT 在 D:\blog ...

  9. platform_get_resource的分析

    阅读platformdriver的代码时,发现在probe函数直接调用platform_get_resource从pdev中获取io内存,但却没有判断传给probe的pdev是否属于这个驱动 ! 后来 ...

  10. FarBox--另类有趣的网站服务【转】

    FarBox--另类有趣的网站服务 转自:http://mosir.org/html/y2012/the-interesting-web-service-serve-by-FarBox.html 作者 ...