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 ...
随机推荐
- [windows phone] 教你如何使地图动画缩放
原文:[windows phone] 教你如何使地图动画缩放 说明 本篇将介绍如何将地图以动画显示呈现,在以下的范例介绍中可以看到有动画跟没动画的差别,如果你的地图还是很单调的话,不仿加上这个设计,让 ...
- 从最大似然到EM算法浅解
从最大似然到EM算法浅解 zouxy09@qq.com http://blog.csdn.net/zouxy09 机器学习十大算法之中的一个:EM算法.能评得上十大之中的一个,让人听起来认为挺NB的. ...
- 【原创翻译】认识MVC设计模式:web应用开发的基础(实际编码篇)
原文地址:http://www.larryullman.com/2009/10/15/understanding-mvc-part-3/ 全系列INDEX [原创翻译]认识MVC设计模式:web应用开 ...
- Android研究之手PullToRefresh(ListView GridView 下拉刷新)使用具体解释
群里一哥们今天聊天偶然提到这个git hub上的控件:pull-to-refresh ,有兴趣的看下,样例中的功能极其强大,支持非常多控件.本篇博客具体给大家介绍下ListView和GridVi ...
- IE7,8,9兼容性处理
在IE7根据假设高度文本框中设置,则光标将不会被中心的方法如以下: 添加属性,如:style="line-height:32px\9";能够 假设一个页面有多个TAB交换的物品.而 ...
- 关于程序猿怎样降低程序Bug的若干建议
毫无疑问,程序猿是善于思考问题的一族. 一个程序的编写都是通过:思考.设计.编写.调试.測试以及执行这些主要的阶段. 但大部分程序猿都有一个问题就是不太愿意測试自己的代码. 他们草草的调式完毕以后就觉 ...
- 微信小程序开发者工具集合包
开发论坛 http://www.henkuai.com/forum-56-1.html 工具包下载 https://yunpan.cn/ckXFpuzAeVi2s 访问密码 b4cc 开发文档 h ...
- 解决新版Emacs的警告:Warning (initialization): Your load-path...
升级到新版Emacs后出现警告 作为做好用的代码编辑器之一,Emacs绝对在极客世界实用率很高.当然VIM也有很多支持者.但小编是从VIM转到Emacs的,个人觉得Emacs更好用. 小编最近升级了F ...
- 4.锁定--Java的LockSupport.park()实现分析
LockSupport类是Java6(JSR166-JUC)引入的一个类,提供了主要的线程同步原语. LockSupport实际上是调用了Unsafe类里的函数.归结到Unsafe里,仅仅有两个函数: ...
- web压力测试-pylot
我已经写在使用前Web Bench做压力測试.http://blog.csdn.net/jacson_bai/article/details/41143713 但这个測试,測试结果非常好.缺点就是,无 ...