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 ...
随机推荐
- testlink于smarty配置和使用
于testlink于,采用smarty首先配置. 一般在过程化的编程中.创建一个smarty.inc.php的文件来配置Smarty的信息,其它文件引入就可以,目的是为了不改动smarty.class ...
- C# WinForm多线程(二)ThreadPool 与 Timer
本文接上文,继续探讨WinForm中的多线程问题,再次主要探讨threadpool 和timer 一 ThreadPool 线程池(ThreadPool)是一种相对较简单的方法,它适应于一些需要多个 ...
- 设计模式 - Abstract Factory模式(abstract factory pattern) 详细说明
Abstract Factory模式(abstract factory pattern) 详细说明 本文地址: http://blog.csdn.net/caroline_wendy/article/ ...
- schedule vs scheduleAtFixedRate
最好的方法是在两者之间区分 timer灵感时间设定过去时间T,scheduleAtFixedRate将从T现在所有的任务中运行,schedule而该任务将只运行从现在开始计时. public clas ...
- [LeetCode328]Odd Even Linked List
题目: Given a singly linked list, group all odd nodes together followed by the even nodes. Please note ...
- ABP-N层架构
ABP理论学习之N层架构 返回总目录 自从写这个系列博客之后,发现很多园友还是希望有个直接运行的demo,其实在github上就有官方的demo,我直接把这demo的链接放到这里吧,另外,我分析, ...
- Everything中文绿色版在Win7/8/10用不了问题的图文教程,只显示盘符
打开Everything后点击菜单上的“工具”——“选项” 勾选 Everything Service 后,点应用 需要用到管理者权限
- 【剑指offer】面试题39:深度二叉树
def TreeDepth1(root): if None == root: return 0 if None == root.left and None == root.right: return ...
- docker 现实---联网多台物理主机,容器桥到物理网络(三)
docker 默认桥接卡docker0 只有当这个单元中的所有容器桥接卡.例如,在主机虚拟网络适配器容器看通常称为veth*** 和docker只要把这些卡桥接在一起,例如下面的附图: waterm ...
- 【Swift】学习笔记(四)——设置(Collection)
Swift和其他语言也提供了两种类型的集合:数组和字典 数组:数组用来按顺序存储同样类型的数据,swift规定它是类型安全的,每个数组都有自己的类型也就是其它语言所说的泛型. 创建数组: 1.var ...