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 ...
随机推荐
- 用贪心算法近似求解 Loading Balance 问题(作业调度的负载均衡)
一,Loading Balance 问题描述:有 m 台相同的机器及 n 个作业,其中 m={M(1),M(2),……M(m)}.n = {J(1),J(2),……J(n)}.每个作业都有一个处理时间 ...
- 不同数据库下的web.config中数据库连接字符串
<connectionStrings> <add name="OADBConnectionString" connectionString="Data ...
- centos7之系统优化方案
优化条目: 修改ip地址.网关.主机名.DNS等 关闭selinux,清空iptables 添加普通用户并进行sudo授权管理 更新yum源及必要软件安装 定时自动更新服务器时间 精简开机自启动服务 ...
- Git操作学习笔记
根据廖雪峰老师git教程学习整理 这里需要辨析一下概念.Github是代码托管平台,是协作的工具;而Git是版本控制工具.Git不需要联网,在本机就可以使用 集中式版本控制系统与分布式版本控制系统 S ...
- 列式数据库~clickhouse 场景以及安装
一 简介:列式数据库clickhouse的安装与基本操作二 基本介绍:ClickHouse来自俄罗斯,是一款列式数据库三 适用场景: 简单类型的大数据统计四 限制 1 不支持更新操作,不支持事 ...
- Java打印M图形(二维数组)——(九)
对于平面图形输出集合图形与数字组合的,用二维数组.先在Excel表格中分析一下,找到简单的规律.二维数组的行数为行高,列数为最后一个数大小. 对于减小再增大再减小再增大的,可以用一个boolean标志 ...
- hdu 4348 To the moon (主席树区间更新)
传送门 题意: 一个长度为n的数组,4种操作 : (1)C l r d:区间[l,r]中的数都加1,同时当前的时间戳加1 . (2)Q l r:查询当前时间戳区间[l,r]中所有数的和 . (3)H ...
- nagios系列(七)nagios通过自定义脚本的方式监控mysql主从同步
nagios监控mysql主从同步 起因:nagios可能监控到mysql服务的运行情况,但确不能监控mysql的主从复制是否正常:有时候,同步已经停止,但管理人员却不知道. 登陆mysql从服务器, ...
- SonarQube代码质量管理工具安装与使用(sonarqube5.1.2 + sonar-runner-dist-2.4 + MySQL5.x)
1. SonarQube安装(sonarqube5.1.2 + sonar-runner-dist-2.4) 1.1 前提条件 1) 已安装Java环境(version:1.7+) 2) 已安装MyS ...
- annoy ANN算法 调参
search_k serach_k越大,越准确,但是要在时间和准确率之间取个trade off During the query it will inspect up to search_k node ...