374D - Inna and Sequence

思路:

树状数组+二分

因为被删的点最多N=1e6个,所以复杂度N*logN*logN

前段时间做过一道一样的题,这类题基本套路二分找没删除前的位置

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int N=1e6+;
int n;
int bit[N];
int a[N];
int ans[N];
bool vis[N];
vector<int>v;
void add(int x,int a){
while(x<=1e6)bit[x]+=a,x+=x&-x;
}
int sum(int x){
int ans=;
while(x)ans+=bit[x],x-=x&-x;
return ans;
}
int srch(int t){
int l=,r=1e6,mid=(l+r)>>;
while(l<r){
if(sum(mid)>=t)r=mid;
else l=mid+;
mid=(l+r)>>;
}
return mid;
}
int main(){
ios::sync_with_stdio(false);
cin.tie();
for(int i=;i<=1e6;i++)add(i,);
int cnt=,t,m;
cin>>n>>m;
for(int i=;i<m;i++)cin>>a[i];
for(int i=;i<n;i++){
cin>>t;
if(t==-){
v.clear();
for(int j=;j<m;j++){
int l=srch(a[j]);
if(l>cnt)break;
v.pb(l);
}
for(int j=;j<v.size();j++){
vis[v[j]]=true;
add(v[j],-);
}
}
else{
ans[++cnt]=t;
}
}
if(sum(cnt)==)cout<<"Poor stack!"<<endl;
else{
for(int i=;i<=cnt;i++)if(!vis[i])cout<<ans[i];
cout<<endl;
}
return ;
}

Codeforces 374D - Inna and Sequence的更多相关文章

  1. codeforces 374D. Inna and Sequence 线段树

    题目链接 给m个数, n个操作, 一个数列, 初始为空.一共有3种操作, 在数列末尾加0, 加1, 或删除位置为a[i]的数, a[i]为初始给的m个数, 如果a[i]大于数列长度, 那么什么也不发生 ...

  2. Codeforces 374D Inna and Sequence 二分法+树状数组

    主题链接:点击打开链接 特定n一个操作,m长序列a 下列n的数量 if(co>=0)向字符串加入一个co (開始是空字符串) else 删除字符串中有a的下标的字符 直接在序列上搞.简单模拟 # ...

  3. Codeforces Round #220 (Div. 2) D - Inna and Sequence

    D - Inna and Sequence 线段数维护区间有几个没有被删除的数,利用线段树的二分找第几个数在哪里,然后模拟更新就好啦. #include<bits/stdc++.h> #d ...

  4. Codeforces 486E LIS of Sequence(线段树+LIS)

    题目链接:Codeforces 486E LIS of Sequence 题目大意:给定一个数组.如今要确定每一个位置上的数属于哪一种类型. 解题思路:先求出每一个位置选的情况下的最长LIS,由于開始 ...

  5. Codefroces 374 B Inna and Sequence (树状数组 || 线段树)

    Inna and Sequence 题意:先给你一个n,一个m, 然后接下来输入m个数,表示每次拳击会掉出数的位置,然后输入n个数,每次输入1或0在数列的末尾加上1或0,如果输入-1,相应m序列的数的 ...

  6. codeforces 374A Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...

  7. CodeForces 670E Correct Bracket Sequence Editor(list和迭代器函数模拟)

    E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes ...

  8. Codeforces GYM 100114 C. Sequence 打表

    C. Sequence Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description ...

  9. Codeforces 374A - Inna and Pink Pony

    原题地址:http://codeforces.com/contest/374/problem/A 好久没写题目总结了,最近状态十分不好,无论是写程序还是写作业还是精神面貌……NOIP挂了之后总觉得缺乏 ...

随机推荐

  1. django模板-if标签和for标签

    在django中,标签写在{%  标签  %}中 if else标签 ①通过if进行条件判断 views.py from django.shortcuts import render def inde ...

  2. FFMPEG编译参数解析

    Standard options: 基本选项参数 --help 显示此帮助信息|print this message --log[=FILE|yes|no] 记录测试并输出到config.err文件| ...

  3. zookeeper各种报错、原因及解决方法汇总(持续更新)

    [root@iZ23nn1p4mjZ zookeeper-3.4.10]# bin/zkCli.sh -server localhost:2181,localhost:2182,localhost:2 ...

  4. Python学习基础(二)——集合 深浅拷贝 函数

    集合 # 集合 ''' 集合是无序不重复的 ''' # 创建列表 l = list((1, 1, 1)) l1 = [1, 1, 1] print(l) print(l1) print("* ...

  5. linux设置代理

    在~/.bashrc或者/etc/profile下,添加下面 http_proxy=http://192.168.105.171:80 https_proxy=$http_proxy export h ...

  6. vue2.0之echarts使用

    1.首先下载echart依赖 npm install echarts --save备注:npm 安装报错时使用cnpm 2.全局注册 在main.js里引入echart并在vue中注册echart / ...

  7. MFC中的CString类使用方法指南

    MFC中的CString类使用方法指南 原文出处:codeproject:CString Management [禾路:这是一篇比较老的资料了,但是对于MFC的程序设计很有帮助.我们在MFC中使用字符 ...

  8. C语言三个结束符:EOF ‘\0’ '\n'

  9. Ubuntu + CUDA9 + CUDNN7 + OpenCV3.4 + contrib +CAFFE-master

    安装ubuntu时赞美Rufus(建议ubuntu16.04.04),过程参考 https://www.cnblogs.com/willnote/p/6725594.html 安 装 前 一 定 要 ...

  10. css的再深入4(更新中···)

    两种居中的方式: Margin:0 auto;和text-align:center; Margin的居中是对自身,text-align对元素内部的文本来说. 隐藏的两种方式: visibility:h ...