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. Entry point (0x08000000) points to a Thumb instruction but is not a valid Thumb code pointer.

    1.菜单 project-options-linker-misc controls加入 --entry Reset_Handler --first __Vectors 2.导入startup_stm3 ...

  2. DTP协议攻击

    DTP协议 动态中继协议DTP(Dynamic Trunking Protocol)是一种Cisco私有协议.DTP用于两台交换机的直连二层端口探测对端的配置,自动协商出二层端口的链路类型和以太网封装 ...

  3. Python中的部分特殊属性

    __name__ is the class name;   返回类名 __module__ is the module name in which the class was defined;   定 ...

  4. VS Code中Matlab插件安装设置

    Install the extension in VS Code Open the command palette using Ctrl+Shift+P Type ext install Matlab ...

  5. 如何将SVN仓库转换为Git仓库

    按如下步骤操作就可以将SVN仓库完整的转换为Git仓库: 1) 将远程SVN仓库搬到本地(这一步主要是为了提高转换的速度,也可以忽略)     参考这篇文章: http://rongjih.blog. ...

  6. Python3学习笔记20-获取对象信息

    当我们拿到一个对象的引用时,如何知道这个对象是什么类型.有哪些方法呢? 基本类型都可以用type()判断: print(type(123)) print(type('str')) print(type ...

  7. [BZOJ3295] [Cqoi2011]动态逆序对(带修改主席树)

    题目描述 对于序列A,它的逆序对数定义为满足i<j,且Ai>Aj的数对(i,j)的个数.给1到n的一个排列,按照某种顺序依次删除m个元素,你的任务是在每次删除一个元素之前统计整个序列的逆序 ...

  8. 转载:《理解RESTful架构》 阮一峰

    原文:http://www.ruanyifeng.com/blog/2011/09/restful.html 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软件&q ...

  9. adb devices检测不到夜神模拟器

    1.dos下,cd进入到夜神模拟器的bin目录 代码: nox_adb connect 127.0.0.1:62001 2.dos下,进入进Android SDK下的platform-tools目录 ...

  10. [译]bootstrap-select (selectpicker)方法

    方法 .selectpicker('val') 您可以通过调用val元素上的方法来设置所选值. $('.selectpicker').selectpicker('val', 'Mustard'); $ ...