Codeforces Round #220 (Div. 2) 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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #220 (Div. 2)
链接 毒瘤场..... A题:,真码农题,直接干爆,枚举,注意越界问题,wa37的看这组数据1 10 1 5 2 2,应该是no //#pragma comment(linker, "/st ...
- 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 ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟
题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)
题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...
- 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 ...
随机推荐
- ICS Hack Tools
参考链接:http://icstraining.org/en/security-tools/configurations ICS-Security-Tool: https://github.com/I ...
- 使用flask_socketio实现服务端向客户端定时推送
websocket连接是客户端与服务器之间永久的双向通信通道,直到某方断开连接. 双向通道意味着在连接时,服务端随时可以发送消息给客户端,反之亦然,这在一些需要即时通讯的场景比如多人聊天室非常重要. ...
- mysql 案例~select引起的性能问题
案例1 背景:测试环境下发现大量select查询,而且负载飙升到90+ 排查思路: 1 老规则,按照排错脚本走一圈,规划出几个元素(1 针对库访问的统计 2针对具体语句类型的统计),发现有大量的sel ...
- django学习~第四篇
django表单 1 今天继续来学学django的表单 首先介绍下http的方法,这是最基本的 GET 方法 GET一般用于获取/查询 资源信息,以?分割URL和传输数据 ...
- TIdHTTP get参数带中文解决方法--请求报文
Post 看起来稍微复杂先,暂不讨论.post 目前按照一般方法有中文名也可以. 拼接时:pointname=九记餐厅&begintime=2017-03-01 00:00:00& 有 ...
- 以前的 Delphi版本
Delphi 1 Delphi 2 Delphi 3 Delphi 4 Delphi 5 Delphi 6 Delphi 7 Delphi 8 Delphi 2005
- js中获取时间new date()的用法和获取时间戳
获取时间: 1 var myDate = new Date();//获取系统当前时间 获取特定格式的时间: 1 myDate.getYear(); //获取当前年份(2位) 2 myDate.getF ...
- BFGS算法(转载)
转载链接:http://blog.csdn.net/itplus/article/details/21897443 这里,式(2.38)暂时不知如何证出来,有哪位知道麻烦给个思路.
- 【vim】自动补全 Ctrl+n
Vim 默认有自动补全的功能.的确这个功能是很基本的,并且可以通过插件来增强,但它也很有帮助.方法很简单. Vim 尝试通过已经输入的单词来预测单词的结尾. 比如当你在同一个文件中第二次输入 &quo ...
- Linux的capability深入分析(2)【转】
转自:https://blog.csdn.net/wangpengqi/article/details/9821231 rpm -ql libcap-2.16-5.2.el6.i686 /lib/l ...