题意:

百度。

思路:

如果该查询的R比前面的所有都大,那么前面所有都失效。

那么我先预处理出这些有效的。

那最坏的情况不就是栈里面元素(R)很多

n,n-1,n-2,n-3,n-4而且都是相反排序的。。。

总不能每次都那样循环一下,跟着他变吧。

所以找特性:

如果有序列132456

我的栈是

1 6

2 5

1 3

2 2

那么第一步从sort完:123456,那么这个a[6]=6肯定是确定了对吧。

继续看 2 5:我们能确定 a[5]=1,a[4]=2 对吧

继续看1 3 :我们能确定a[3]=5。

继续看2 2:我们能确定a[2]=3,a[1]=4.

最后输出。这样我觉得仔细自己想想就能瞎搞出来了!自己想出来的方法才有乐趣啊~

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=2e5+10;
struct asd{
int flag;
int R;
}e[N];
stack<asd>q;
int a[N],b[N][2];
int tp[N];
bool cmp(int x,int y)
{
return x>y;
}
int main()
{
asd now,nex;
int n,t;
scanf("%d%d",&n,&t);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=t;i++)
scanf("%d%d",&e[i].flag,&e[i].R);
for(int i=1;i<=t;i++)
{
while(!q.empty()&&q.top().R<e[i].R)
q.pop();
if(!q.empty()&&e[i].flag==q.top().flag)
continue;
q.push(e[i]);
}
int num=0;
while(!q.empty())
{
num++;
b[num][0]=q.top().flag;b[num][1]=q.top().R;
q.pop();
}
if(b[num][0]==1)
sort(a+1,a+b[num][1]+1);
else
sort(a+1,a+b[num][1]+1,cmp);
if(num==1)
{
for(int i=1;i<=n;i++)
printf("%d ",a[i]);
return 0;
}
int ii=n,jj=1,ij=n;
int s=1;
for(;ij>b[num][1];ij--,ii--)
tp[ij]=a[ij];
for(int i=num;i>=2;i--)
{
int cnt=b[i][1]-b[i-1][1];
if(s%2==0)
for(int p=1;p<=cnt;p++,ij--,jj++)
tp[ij]=a[jj];
else
for(int p=1;p<=cnt;p++,ij--,ii--)
tp[ij]=a[ii];
s++;
}
if(s%2==0)
for(int p=1;p<=b[1][1];p++,ij--,jj++)
tp[ij]=a[jj];
else
for(int p=1;p<=b[1][1];p++,ij--,ii--)
tp[ij]=a[ii];
for(int i=1;i<=n;i++)
printf("%d ",tp[i]);
return 0;
}
/*
6 4
1 3 4 5 2 6
1 6
2 5
1 3
2 2
*/

最新文章

  1. React Native 获取网络数据
  2. C4D to Unity3D插件C2U Tool开源发布!简化你的工作流
  3. 金额input框控制只能小数点后有两位的有效数字
  4. PHP实现Web Service(转)
  5. Java实战之02Hibernate-05检索策略、检索方式
  6. [Angular 2] ng-class and Encapsulated Component Styles
  7. 给EcStore商城会员添加推广返利功能
  8. webform登录操作中正则表达式运用
  9. BZOJ 3774: 最优选择( 最小割 )
  10. POJ 3384 Feng Shui 凸包直径 + 半平面交
  11. HTTP基础知识
  12. Assigning Workstations
  13. java 数据格式验证类
  14. 将excel文件内容存储到数据库,并可以实时在前端查看(不必生成文件)
  15. springMVC的controller
  16. [Swift]LeetCode145. 二叉树的后序遍历 | Binary Tree Postorder Traversal
  17. VS2008 编译出错 fatal error C1859: unexpected precompiled header error, simply rerunning the compiler might fix this problem
  18. Monotonic Array LT896
  19. 拓扑排序-有向无环图(DAG, Directed Acyclic Graph)
  20. Lua中的注释

热门文章

  1. 题解 P1001 【A+B Problem】
  2. Macaca,app-inspector安装
  3. 图形绘制处理逻辑VC
  4. Android 7.1 GUI系统-窗口管理WMS-Surface管理(四)
  5. BZOJ 2442 [Usaco2011 Open]修剪草坪:单调队列优化dp
  6. BZOJ 1640 [Usaco2007 Nov]Best Cow Line 队列变换:贪心【字典序最小】
  7. POJ 3744 Scout YYF I:概率dp
  8. linux应用之jdk环境的安装(centos)
  9. NCEE2018游记
  10. bzoj4555: 求和sum 快速傅立叶变换