Codeforces 374D Inna and Sequence 二分法+树状数组
主题链接:点击打开链接
特定n一个操作,m长序列a
下列n的数量
if(co>=0)向字符串加入一个co (開始是空字符串)
else 删除字符串中有a的下标的字符
直接在序列上搞。简单模拟
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<set>
#include<vector>
#include<map>
#include<math.h>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;
#define N 1000005
bool use[N], b[N];
int top;
int n, m;
int a[N];
int c[N], maxn;
inline int lowbit(int x){return x&(-x);}
void change(int pos, int val){
while(pos<=maxn){
c[pos]+=val;
pos+=lowbit(pos);
}
}
int sum(int pos){
int ans = 0;
while(pos)ans+=c[pos], pos-=lowbit(pos);
return ans;
}
set<int>myset;
set<int>::iterator p;
void Erase(int pos, int r){
int l = 1;
while(l<=r) {
int mid = (l+r)>>1;
int tmp = sum(mid);
if(tmp==pos) {
p = myset.upper_bound(mid);
p--;
mid = *p;
change(mid, -1);
use[mid] = 1;
myset.erase(p);
return ;
}
if(tmp>pos) r = mid-1;
else l = mid+1;
}
}
void init(){myset.clear(); memset(c, 0, sizeof c); maxn = n+10; top = 0;}
int main(){
int i,j,co;
while(~scanf("%d %d",&n,&m)){
init();
for(i=0;i<m;i++)scanf("%d",&a[i]);
int len = 0;
for(i = 1; i <= n; i++) {
scanf("%d",&co);
if(co>=0)
use[i] = 0, b[i] = co, change(i,1), len++, myset.insert(i);
else {
use[i] = 1;
int j = lower_bound(a, a+m, len) - a;
if(j==0 && len<a[0])continue;
if(len!=a[j])j--;
while(j>=0) {
Erase(a[j], i);
j--;
len--;
}
}
} if(!len)puts("Poor stack!");
else {
for(i = 1; i <= n; i++) if(!use[i])
printf("%d",b[i]);
puts("");
}
}
return 0;
}
Codeforces 374D Inna and Sequence 二分法+树状数组的更多相关文章
- codeforces 374D. Inna and Sequence 线段树
题目链接 给m个数, n个操作, 一个数列, 初始为空.一共有3种操作, 在数列末尾加0, 加1, 或删除位置为a[i]的数, a[i]为初始给的m个数, 如果a[i]大于数列长度, 那么什么也不发生 ...
- Codeforces 374D - Inna and Sequence
374D - Inna and Sequence 思路: 树状数组+二分 因为被删的点最多N=1e6个,所以复杂度N*logN*logN 前段时间做过一道一样的题,这类题基本套路二分找没删除前的位置 ...
- 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 Gym 100114 H. Milestones 离线树状数组
H. Milestones Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descripti ...
- Codeforces - 828E DNA Evolution —— 很多棵树状数组
题目链接:http://codeforces.com/contest/828/problem/E E. DNA Evolution time limit per test 2 seconds memo ...
- Codeforces Round #365 (Div. 2) D 树状数组+离线处理
D. Mishka and Interesting sum time limit per test 3.5 seconds memory limit per test 256 megabytes in ...
- Educational Codeforces Round 10 D. Nested Segments (树状数组)
题目链接:http://codeforces.com/problemset/problem/652/D 给你n个不同的区间,L或者R不会出现相同的数字,问你每一个区间包含多少个区间. 我是先把每个区间 ...
- CodeForces - 314C Sereja and Subsequences (树状数组+dp)
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...
- Codeforces Gym 100269F Flight Boarding Optimization 树状数组维护dp
Flight Boarding Optimization 题目连接: http://codeforces.com/gym/100269/attachments Description Peter is ...
随机推荐
- 创建Material Design风格Android应用--自定义阴影和裁剪视图
之前已经写过通过应用主题和使用ListView, CardView,应用Material Design样式,同一时候都都能够通过support library向下兼容.今天要写的阴影和视图裁剪.无法向 ...
- A ResourcePool could not acquire a resource from its primary factory or source
出处:http://aaron81939097.iteye.com/blog/1144642 原配置: <bean id="dataSource" class="c ...
- Android UI法宝的设计资源的开发
UI再次推荐设计资源.纯干,没有水~ 各种背景资源库 http://subtlepatterns.com/ ICON资源 https://www.iconfinder.com/ watermark/2 ...
- java提高篇(五)-----使用序列化实现对象的拷贝
我们知道在Java中存在这个接口Cloneable,实现该接口的类都会具备被拷贝的能力,同时拷贝是在内存中进行,在性能方面比我们直接通过new生成对象来的快,特别是在大对象的生成上,使得性 ...
- 《Pro Android Graphics》读第三季度票据
Android Frame Animation: XML, Concepts and Optimization Frame Animation Concepts: Cels, Framerate, a ...
- cocos2d-x 3.1.1 学习笔记[17] 关于这些活动功能
供cocos2d-x通常使用的方法,我有一个好脸色.这项研究真的奖励. 向导首先,定义,实施一系列连续动作. 对于我们的行动能回调函数,我们必须申报并加以实施. void callBack(); vo ...
- Python 获得Facebook用户有一个共同的兴趣Friends
CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-8-13 @author: guaguastd @name: c ...
- Tuple
Tuple(组元)是C# 4.0引入的一个新特性,编写的时候需要基于.NET Framework 4.0或者更高版本. 在以前编程中,当需要返回多个值得方法中,常常需要将这些值放置到一个结构体或者对象 ...
- Android开发之合并文件的几种方式
以下介绍合并文件的几种方式,并通过合并amr文件来举例介绍合并文件的详细流程.amr格式的文件头是6字节,所以在进行文件合并的时候要减去除第一个文件以外的其它文件的文件头. 注意:不同文件的文件头是不 ...
- 一起写2048(160行python代码)
前言: Life is short ,you need python. --Bruce Eckel 我与2048的缘,不是缘于一个玩家.而是一次,一次,重新的ACM比赛.四月份校赛初赛,第一次碰到20 ...