排序+构造+预处理

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn = + ;
int n, m;
int a[maxn], ans[maxn];
int op[maxn], e[maxn];
int pos[maxn];
int first, last;
int flag;
int p;
int tot; bool cmp(const int &a, const int &b)
{
return a>b;
} int main()
{
while (~scanf("%d%d", &n, &m))
{
for (int i = ; i <= n; i++) scanf("%d", &a[i]);
for (int i = ; i <= m; i++) scanf("%d%d", &op[i], &e[i]);
memset(ans, , sizeof ans);
tot = ; memset(pos, -, sizeof pos);
pos[m] = m;
for (int i = m - ; i >= ; i--)
{
pos[i] = pos[i + ];
if (e[i] > e[pos[i + ]]) pos[i] = i;
} p = pos[];
if (op[p] == ){sort(a + , a + + e[p]); flag = ;}
else{sort(a + , a + + e[p], cmp);flag = ;}
first = ; last = e[p];
for (int i = e[p] + ; i <= n; i++) ans[i] = a[i], tot = tot + ;
while (tot<n)
{
p = pos[p + ]; if (p == -) break;
if (first>last)
{
for (int i = last; i <= first - e[p]; i++) ans[n - tot] = a[i], tot = tot + ;
last = first - e[p]+;
}
else
{
for (int i = last; i >= first + e[p]; i--) ans[n - tot] = a[i], tot = tot + ;
last = first + e[p] - ;
}
if (op[p] != flag)
{
swap(first, last);
flag = op[p];
}
}
if (tot < n)
{
if (first <= last) for (int i = last; i >= first; i--) ans[n - tot] = a[i], tot = tot + ;
else for (int i = last; i <= first; i++) ans[n - tot] = a[i], tot = tot + ;
} for (int i = ; i <= n; i++) printf("%d ", ans[i]);
printf("\n");
}
return ;
}

CodeForces 631C Print Check的更多相关文章

  1. Codeforces 631B Print Check (思维)

    题目链接 Print Check 注意到行数加列数最大值只有几千,那么有效的操作数只有几千,那么把这些有效的操作求出来依次模拟就可以了. #include <bits/stdc++.h> ...

  2. CodeForces 631B Print Check

    对于每一个格子,看是行最后画还是列最后画.预处理一下就可以了. #include<stdio.h> #include<string.h> int n,m,k; +]; +]; ...

  3. Codeforces 631B Print Check【模拟】

    题意: 按顺序给定列和行进行涂色,输出最终得到的方格颜色分布. 分析: 记录下涂的次序,如果某个元素的横和列都被涂过,那么就选择次序最大的颜色. 代码: #include<iostream> ...

  4. Codeforces Round #344 (Div. 2) B. Print Check 水题

    B. Print Check 题目连接: http://www.codeforces.com/contest/631/problem/B Description Kris works in a lar ...

  5. Codeforces Round #344 (Div. 2) B. Print Check

    B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. codeforces 631B B. Print Check

    B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #344 (Div. 2) 631 B. Print Check (实现)

    B. Print Check time limit per test1 second memory limit per test256 megabytes inputstandard input ou ...

  8. 存储构造题(Print Check)

    连接:Print Check 题意:n行m列的矩阵,有k次涂色,每一涂一行或者一列,求最后的涂色结果. 从数据的大小看,暴力肯定要TLE: 问题是如何存储数据. 首先:我们只要最后的涂色结果. 其次: ...

  9. Codeforces 631C. Report 模拟

    C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...

随机推荐

  1. linux的学习系列 10---vi

    Linux下的文本编辑器有很多种,vi 是最常用的,也是各版本Linux的标配.注意,vi 仅仅是一个文本编辑器,可以给字符着色,可以自动补全,但是不像 Windows 下的 word 有排版功能. ...

  2. websphere安装

    下午来再输 websphere 配置库中已存在应用程序,异常处理 出现此问题的原因之一:操作界面上没有卸载完成. 进行一下操作: 1.删除 $WAS_HOME/profiles/AppSrv01/co ...

  3. HDU1372:Knight Moves(BFS)

    Knight Moves Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  4. cocos2d-js 帧序列动画

    1.resource.js var res = { playerWalk_plist:"res/playerWalk.plist", playerWalk_png:"re ...

  5. ubuntu server 11.10 mysql 自动备份脚本

    1.下载最新的备份脚本(AutoMySQLBackup) 点这里下载 2.修改脚本配置部分 vi  /root/automysqlbackup-2.5.1-01.sh USERNAME=root PA ...

  6. 查看UDP连接情况

    运行界面,输入"CMD"命令; 在命令提示符界面中,输入"netstat -s -p udp"命令,按回车.即可显示本机所有UDP连接情况.

  7. dotnet core error 0x80070057

    安装补丁KB2533623 https://support.microsoft.com/en-us/kb/2533623

  8. Android如何使用API

    转自:http://www.cnblogs.com/vanezkw/archive/2012/07/03/2574559.html 本文针对Android开发如何使用API文档进行一些经验分享. 1. ...

  9. bat脚本:自动压缩n天前的文件【转载】

    原文如下: bat脚本:自动压缩n天前的文件-中原小伙-ChinaUnix博客http://blog.chinaunix.net/uid-24946452-id-1651762.html     磁盘 ...

  10. jvm attach

    http://ayufox.iteye.com/blog/655761 管道通信