Codeforces Round #344 (Div. 2) C. Report
来源:互联网 发布:sql server 注释代码 编辑:程序博客网 时间:2024/05/16 01:13
题目大意:给一个序列,进行m次操作,每次操作对[1,r]进行升序or降序,输出最终序列。
思路:不难发现,对于每个区间
op[y]=x,表示对区间[1,y]的操作是x;
t[y]=i,表示对区间[1,y]的操作是第i次;
然后假设所有操作r最大为r_max,那么就从r_max开始倒序维护区间。
/* ***********************************************┆ ┏┓ ┏┓ ┆┆┏┛┻━━━┛┻┓ ┆┆┃ ┃ ┆┆┃ ━ ┃ ┆┆┃ ┳┛ ┗┳ ┃ ┆┆┃ ┃ ┆┆┃ ┻ ┃ ┆┆┗━┓ 马 ┏━┛ ┆┆ ┃ 勒 ┃ ┆ ┆ ┃ 戈 ┗━━━┓ ┆┆ ┃ 壁 ┣┓┆┆ ┃ 的草泥马 ┏┛┆┆ ┗┓┓┏━┳┓┏┛ ┆┆ ┃┫┫ ┃┫┫ ┆┆ ┗┻┛ ┗┻┛ ┆************************************************ */#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>using namespace std;#define rep(i,a,b) for (int i=(a),_ed=(b);i<_ed;i++)#define per(i,a,b) for (int i=(b)-1,_ed=(a);i>=_ed;i--)#define inf 0x3f3f3f3f#define mod 1000000007#define ll long long#define ull unsigned long long#define N 200005int t[N],op[N],ans[N];int a[N];int n,m;int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int x,y;scanf("%d%d",&n,&m);for(int i=1;i<=n;i++) { scanf("%d",&a[i]); } for(int i=1;i<=m;i++) { scanf("%d%d",&x,&y); op[y]=x; t[y]=i; } int len=n; for(;len;len--) { if(op[len])break; ans[len]=a[len]; } sort(a+1,a+1+len); int l=1,r=len; int nowtime=0,nowop=0; for(int i=len;i>=1;i--) { if(t[i]>nowtime) { nowtime=t[i]; nowop=op[i]; } if(nowop==1)ans[i]=a[r--]; else ans[i]=a[l++]; } for(int i=1;i<=n;i++) printf("%d ",ans[i]); printf("\n"); return 0;}
0 0
- Codeforces Round #344 (Div. 2) C. Report
- Codeforces Round #344 (Div. 2) C. Report
- Codeforces Round #344 (Div. 2) C. Report
- Codeforces Round #344 (Div. 2)C. Report
- Codeforces Round #344 (Div. 2) C. Report
- Codeforces Round #344 (Div. 2) 631C Report(脑洞+stl)
- Codeforces Round #344 (Div. 2) C. Report【水题】
- Codeforces Round #344 (Div. 2) C. Report (脑洞题)
- Codeforces Round #344 (Div. 2)-C. Report(单调栈)
- Codeforces Round #344 (Div. 2) C. Report (题解)
- Codeforces Round #343 (Div. 2) C. Report (乱搞)
- Codeforces Round #344 (Div. 2) C - Report 遇到排序什么的就是无尽的蛋疼
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #344 (Div. 2)
- Codeforces Round #344 (Div. 2)
- Codeforces Round #200 (Div. 2)344C Rational Resistance(模拟)
- Codeforces Round #105 (Div. 2) C
- Codeforces Round 134 div 2 C题
- android Launcher——启动过程详解
- 第6章 进程的调度
- MUI-页面初始化
- android中的ListView数据量大时如何提高效率。。。。
- 以什么姿势进入DataMining会少走弯路?
- Codeforces Round #344 (Div. 2) C. Report
- MySql数据库查询多级部门及其下的所有用户信息
- android自定义View(2):实现百分比自适应布局
- 数组类
- Spring中ClassPathXmlApplicationContext类的简单使用
- Android Studio 报错原因以及解决办法
- springMVC 与 struts+hibernate+spring优缺点
- 自己写的windows服务 启动时出现1053错误
- 补充阅读程序-2