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 8 应用开发 - 应用栏
原文:Windows 8 应用开发 - 应用栏 通过应用栏(AppBar)可以在需要时向用户显示各种应用命令.应用栏提供与用户当前页面或当前选定的内容相关的各种命令.默认情况下,应用栏处于隐 ...
- Cocos2d-x3.0 lua捆绑C++分类
我知道这个纪录Lua结合整个过程. 原文地址:http://blog.csdn.net/qqmcy/article/details/26099859 准备工作: 1.创一个一个Lua的2dxproje ...
- UBUNTU12.04下安装配置体验gnome3
年. ubuntu12.04默认采用unity界面,但是自己更加喜欢gnome3的操作方式. 安装gnome3: sudo apt-get install gnome-shell 其实安装成功后,注 ...
- CentOS 5 安装Oracle10g
原创作品.离 "深蓝的blog" 博客.欢迎转载.转载时请务必注明下面出处,否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlon ...
- Android-管理Activity生命周期 -暂停和恢复一个Activity
在正常的使用app时,前台的activity有时候会被可见的组件阻塞导致activity暂停.比如,当打开一个半透明的activity(就像打开了一个对话框),之前的activity就会暂停.只要ac ...
- 轻松搭建Windows8云平台开发环境
原文:轻松搭建Windows8云平台开发环境 Windows Store应用是基于Windows 8操作系统的新一代Windows应用程序,其开发平台以及运行模式和以往传统平台略有不同.为了帮助更多开 ...
- 【Android基础】listview控件的使用(4)-----自定义布局的listview的使用
前面我介绍了listview控件的不同用法,但是这些用法在实际的开发项目中是不足以满足需求的,因为前面的几种用法只能简单的显示文本信息,而且布局都比较单一,很难做出复杂的结果,在实际的开发项目中,90 ...
- ListView 实现多选/无线电
ListView本身与无线电.多选模式.由listview.setChoiceMode设置: listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE) ...
- Apache 2.4虚拟主机配置
托管它指的是多个站点的执行一台机器上 (例如 company1.example.com 和 company2.example.com) . 机能够"基于 IP",即每一个 IP 一 ...
- 如何对 GIT 分支进行规划? (转)
项目背景: 该项目是在2011年11月份使用Asp.net三层帮荷兰某个客户开发的机票预定系统 该客户主要是做中国与欧洲的旅行社业务,特别是最近两年由于中国的发展因此客户也越来越重视机票业务 于是他们 ...