排序+构造+预处理

#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. Java的引用c++的引用和C指针的区别

    Java的引用本质上就是C中的指针,而c++的引用则完全不同:有一个类 class Point { int x; int y;} 同样的一个Point p; 在Java中p表示一个引用,它等同于C语言 ...

  2. C++调用C#之C# COM控件

    C#做界面真的是比C++方便多了,所以尝试了一下,使用C++做核心功能(例如绘图),然后用C#来做节目(例如对话框),考虑到以后可能不能使用.net,使用DLL做一个隔离层,隔离C++和C#,方便以后 ...

  3. linux下环境变量PS1设置

    PS1变量中提示符各项含义:   \d :代表日期,格式为weekday month date,例如:Wed Dec 12 \H :完整的主机名称.例如:hostname是debian.linux \ ...

  4. Linux学习 -- Shell基础 -- Bash变量

    变量 默认是字符串型,数值型需要显示指定 等号两侧都不能有空格 单引号:原始字符串  双引号:保留转义 命令结果作为值:反引号 或 $() 环境变量一般用大写 自定义变量 变量定义    name=& ...

  5. linux 用户管理维护 清缓存

    #echo 1 > /proc/sys/ vm/drop_caches 2013.10.10 其实一直user group一直都没去弄清楚 只是没去归类,@@一种是对用户/组直接修改(同时也更改 ...

  6. 第13章 Swing程序设计----标签组件与图标

    在Swing中显示文本或提示信息的方法是使用标签.本节将探讨Swing标签的用法.如何创建标签,以及如何在标签上放置文本和图标. 1.标签的使用 标签可以显示一行只读文本.一个图像或带图像的文本,它并 ...

  7. cookies和session的优缺点

    具体来说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案. Cookie的优缺点: 优点:极高的扩展性和可用性通过良好的编程,控制保存在cookie ...

  8. mysql show processlist详解

    SHOW PROCESSLIST显示哪些线程正在运行.您也可以使用mysqladmin processlist语句得到此信息.如果您有SUPER权限,您可以看到所有线程.否则,您只能看到您自己的线程( ...

  9. 看懂gradle

    http://blog.csdn.net/zxhoo/article/details/29570685

  10. islands打炉石传说<DP>

    islands最近在完一款游戏"炉石传说",又名"魔兽英雄传".炉石传说是一款卡牌类对战的游戏.游戏是2人对战,总的来说,里面的卡牌分成2类,一类是法术牌,另一 ...