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 事物

    事物 在这里指,将一些关于数据库的一系列操作,打包成一个原子性操作,意思是这一系列操作必须全部执行成功,如果,其中某个操作没有成功,那么这一系列操作都将滚回到之前没执行的状态,包括其中执行成功的某些操 ...

  2. c语言cgi笔记

    直接输出接收的数据 #include <stdio.h>#include <stdlib.h>main(){int i,n;printf ("Content-type ...

  3. 抓取awr、语句级awr、ashrpt

    exec dbms_workload_repository.create_snapshot();--调用MMON进程立即收集快照 生成AWR报告@?/rdbms/admin/awrrpt.sql; 9 ...

  4. shell实现自动部署两台tomcat项目+备份

    就做个记录吧, 其实也没啥好说的. 主机 #!/bin/bash TODAY=$(date -d 'today' +%Y-%m-%d-%S) MIP="192.168.180.24" ...

  5. linux 实时显示网速bash

    执行方法先授权再运行 chmod +x shi.sh脚本+网卡名称 ./shi.sh ens33 #!/bin/bash while [ "1" ] do eth=$1 RXpre ...

  6. Android之RadioButton多行

    RadioGroup设置orientation="vertical"竖向单列显示 RadioGroup设置orientation="horizontal"横向单 ...

  7. Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...

  8. Hacker

    https://hackertarget.com/nikto-website-scanner/

  9. 3.sql2008查询

    根据需要和条件,查看并显示结果集,如果需要,可将结果集生成数据表select:查什么,列筛选,可以用*代表全部列from:在哪个表中查,where:符合什么样的条件,行筛选select:       ...

  10. Python3基础 filter+lambda 筛选出1-20之间的奇数

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...