CodeForces 631C Print Check
排序+构造+预处理
#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的更多相关文章
- Codeforces 631B  Print Check (思维)
		题目链接 Print Check 注意到行数加列数最大值只有几千,那么有效的操作数只有几千,那么把这些有效的操作求出来依次模拟就可以了. #include <bits/stdc++.h> ... 
- CodeForces 631B Print Check
		对于每一个格子,看是行最后画还是列最后画.预处理一下就可以了. #include<stdio.h> #include<string.h> int n,m,k; +]; +]; ... 
- Codeforces 631B Print Check【模拟】
		题意: 按顺序给定列和行进行涂色,输出最终得到的方格颜色分布. 分析: 记录下涂的次序,如果某个元素的横和列都被涂过,那么就选择次序最大的颜色. 代码: #include<iostream> ... 
- 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 ... 
- 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 ... 
- codeforces 631B B. Print Check
		B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ... 
- 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 ... 
- 存储构造题(Print Check)
		连接:Print Check 题意:n行m列的矩阵,有k次涂色,每一涂一行或者一列,求最后的涂色结果. 从数据的大小看,暴力肯定要TLE: 问题是如何存储数据. 首先:我们只要最后的涂色结果. 其次: ... 
- Codeforces 631C. Report 模拟
		C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ... 
随机推荐
- 会话管理---Cookie与Session
			会话可简单理解为:用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话. 保存会话数据的两种技术:Cookie,Session Cookie是客户端技术, ... 
- linux系统定时重启tomcat
			#touch auto-start.sh [root@Linux opt]# echo $LANGen_US.UTF-8 #vim auto-start.sh #!/bin/sh export LAN ... 
- JS-DOM元素灵活查找
			用className选择元素 封装成函数 <title>无标题文档</title> <script> /* window.onload=function () { ... 
- RMQ 详解
			RMQ(Range Minimum/Maximum Query)问题:RMQ问题是给定一个区间,求这个区间中的最大或最小值的问题 RMQ采用动态规划的思想来求解:(st算法:Square Table) ... 
- UVA - 437 The Tower of Babylon(dp-最长递增子序列)
			每一个长方形都有六种放置形态,其实可以是三种,但是判断有点麻烦直接用六种了,然后按照底面积给这些形态排序,排序后就完全变成了LIS的问题.代码如下: #include<iostream> ... 
- Bootstrap学习 - 组件
			下拉菜单 注意:需要先引入jQuery.js再引入bootstrap.js(依赖前者) <div class="dropdown pull-right"> //默认就是 ... 
- Hibernate锁机制
			业务逻辑的实现过程中,往往需要保证数据访问的排他性.因此,我们就需要通过一些机制来保证这些数据在某个操作过程中不会被外界修改,这样的机制,在这里,也就是所谓的“锁”,即给我们选定的目标数据上锁,使其无 ... 
- int与string转换
			参考: http://greatverve.cnblogs.com/archive/2012/10/24/cpp-int-string.html 
- SPOJ Count on a tree
			Count on a tree Time Limit:129MS Memory Limit:1572864KB 64bit IO Format:%lld & %llu Subm ... 
- 使用GDB调试Android NDK native(C/C++)程序-转
			最 近写了些需要跨平台兼容的C++库,Android是其中需要兼容的平台之一.区别于Windows,Mac中功能强大的IDE环境,官方并没有为 Android ndk提供太多的支持.因此,尝试了下通过 ... 
