排序+构造+预处理

#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. c++运行时类型识别(rtti)

    一个简单运行时类型识别 namespace rtti_ex { /* * 类型信息基类 */ class i_type_info { public: // 判断是否是指定类型 bool is(cons ...

  2. php 四种基础的算法 ---- 冒泡排序法

    1. 冒泡排序法  *     思路分析:法如其名,就是像冒泡一样,每次从数组当中 冒一个最大的数出来.  *     比如:2,4,1    // 第一次 冒出的泡是4  *             ...

  3. android Button获取焦点

    有时直接使用requestFocus()不能给button设置焦点,经网上查找得到如下结论: 先setFocus,再requestFocus.                 btn.setFocus ...

  4. linux系统tomcat项目部署和tomcat访问日志

    一.只用ip地址访问 先把端口号改成80,然后用 <Host name="localhost"  appBase="webapps"    137     ...

  5. hadoop yarn 易理解

    Hadoop 和 MRv1 简单介绍 Hadoop 集群可从单一节点(其中所有 Hadoop 实体都在同一个节点上运行)扩展到数千个节点(其中的功能分散在各个节点之间,以增加并行处理活动).图 1 演 ...

  6. IOS小工具以及精彩的博客

    IOS小工具以及精彩的博客 工具 Log Guru是一个收集Log的小工具, 可以在 Mac 上查看 iOS 设备的实时系统日志. 现在可以直接高亮显示在 FIR.im 上安装 app 失败的原因.后 ...

  7. FragmentTabHost使用注意

    FragmentTabHost使用时每次切换回Fragment时,都会再走一遍onCreateView,解决办法是缓存View,具体如下 private View rootView;//缓存Fragm ...

  8. AngularJs: Reload page

    <a ng-click="reloadRoute()" class="navbar-brand" title="home" data- ...

  9. 配置Eclipse支持java和xml文件的代码补全功能

    百度经验:jingyan.baidu.com 本文介绍如何配置Eclipse,使得在编写代码时无论是*.java还是*.xml文件都能够通过使用ALT+/快捷键实现代码不全的功能. 本文实验环境为:W ...

  10. aspx 文件上传和下载,多文件上传

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultiFileUpload. ...