codeforces 631C Report(单调栈)
来源:互联网 发布:淘宝互联网生态系统 编辑:程序博客网 时间:2024/06/08 08:59
//题解:如果第j个操作在第i个操作后面且rj>=ri,则第i个操作可视为无效操作,根据操作区间长度//建立一个递减的单调栈,只需改变相差区间的数的排列顺序#include<iostream>#include<algorithm>using namespace std;const int maxn=200005;long long a[maxn],b[maxn];int q[maxn],t[maxn],r[maxn];int main(){int n,m;cin>>n>>m;int i,j;for(i=1;i<=n;i++){cin>>a[i];b[i]=a[i];}for(i=0;i<m;i++){cin>>t[i]>>r[i];}int head=0,tail=0;//队列首尾指针,初始为空q[0]=0;//存储元素的下标,初始时存入首元素的下标0for(i=1;i<m;i++){while(head<=tail&&r[i]>=r[q[tail]])//建立严格单调递减的队列tail--;q[++tail]=i;//存储入队元素下标}int tmp=r[q[0]];//最长的区间sort(b+1,b+1+tmp);//作为参照从小到大排好序的数组int lb=1,rb=tmp;q[++tail]=m,r[m]=0;//最后一组元素要排序(此处注意)for(i=1;i<=tail;i++){for(j=r[q[i-1]];j>r[q[i]];j--){if(t[q[i-1]]==1) { a[j]=b[rb--];}else { a[j]=b[lb++];}}}for(i=1;i<=n;i++)cout<<a[i]<<' ';cout<<endl;return 0;}
0 0
- codeforces 631C Report(单调栈)
- CodeForces 631 C.Report(单调栈)
- CodeForces 631C.Report(单调栈)
- Codeforces 631C Report 【单调栈】
- 【Codeforces 631 C Report】+ 单调栈
- Codeforces Round #344 (Div. 2)-C. Report(单调栈)
- codeforces 631c Report
- Codeforces 631C:Report
- codeforces 631C Report
- Codeforces 631C-Report
- CodeForces 631C Report
- Codeforces 631C Report
- CodeForces 631C Report(找规律)
- cf#344-C - Report-贪心/单调栈
- Codeforces 631C Report【其他】
- codeforces 631C (单调栈+思维)
- Codeforces 631C Report排序+思维
- Codeforces 631C Report【思维脑洞题】
- PHP CURD实现的中$_GET和$_POST用法的小问题
- sort与qsort
- 基于混沌遗传算法的无人机路径规划
- Error inflating class com.facebook.drawee.view.SimpleDraweeView问题的解决
- 重建二叉树
- codeforces 631C Report(单调栈)
- linux 分区格式化挂载 物理卷 逻辑卷
- HDOJ 5750 Dertouzos
- Java多线程研究02-对象锁,synchronized关键字详解
- Scala 类和对象
- C++矩阵类(乘法与快速幂)
- 设计模式---行为类型---观察者
- (HDU 5727)2016 Multi-University Training Contest 1 Necklace(搜索、图论)
- Linux从一般用户切换到root用户