【思维题】TCO14 Round 2C InverseRMQ
全网好像就只有劼和manchery写了博客的样子……;正解可能是最大流?但是仔细特判也能过
题目描述
RMQ问题即区间最值问题是一个有趣的问题。
在这个问题中,对于一个长度为 n 的排列,query(l,r) 将返回 al,⋯,ar 中的最大值。
如对于 {3,1,4,2,5},query(2,4)=max(1,4,2)=4
现在我们给出 m 次询问的结果,问是否存在至少一个长度为 n 的排列 P 满足所有的条件。
输入格式
第一行 T
每一组数据中,第一行 n,m,接下来 m 行,每行 li,ri,ans
输出格式
T 行 Possible 或 Impossible
数据范围
对于 20% 的数据, n≤10
对于另 10% 的数据,li=ri
对于另 20% 的数据,[li,ri] 两两没有交集
对于另 20% 的数据,ansi 互不相同
对于所有数据,T≤10,n,m≤2000,1≤li≤ri≤n
时间限制 1s
空间限制 256MB
官方题解
先按照值从小到大排序
然后值一样的一起处理 如果交为空 无解
如果交被之前所有的并给完全包含了 无解
如果某一时刻并的大小比数字还大 无解
以上三点就是充要条件
题目分析
manchery的题解是比较详细的,但似乎漏了点什么
比如说这种情况:

就是不可以的。
第一遍做这题的时候有考虑到两个问题:
- 区间最大值不够这个区间用(manchery第三条条件)
- 空余位置不足够填下剩下的数字(以上的反例)
不过由于代码能力不足,并没有打出来……
#include<bits/stdc++.h>
const int maxn = ; struct point
{
int l,r,c;
}a[maxn],b[maxn],t[maxn];
int T,n,m,stb;
bool pot[maxn],fbd[maxn][maxn],insideConflict; int read()
{
char ch = getchar();
int num = ;
bool fl = ;
for (; !isdigit(ch); ch = getchar())
if (ch=='-') fl = ;
for (; isdigit(ch); ch = getchar())
num = (num<<)+(num<<)+ch-;
if (fl) num = -num;
return num;
}
int main()
{
T = read();
while (T--)
{
memset(fbd, , sizeof fbd);
memset(pot, , sizeof pot);
n = read(), m = read(), insideConflict = ;
for (int i=; i<=n; i++) a[i].l = , a[i].r = n, b[i].l = n, b[i].r = ;
for (int i=; i<=m; i++)
{
int l = read(), r = read(), c = read();
t[i].l = l, t[i].r = r, t[i].c = c;
if (c > n||c < ) insideConflict = ;
else{
pot[c] = ;
a[c].l = std::max(l, a[c].l), a[c].r = std::min(r, a[c].r);
b[c].l = std::min(l, b[c].l), b[c].r = std::max(r, b[c].r);
if (a[c].l > a[c].r) insideConflict = ;
}
}
for (int i=; i<=n; i++)
if (b[i].r-b[i].l+ > i){
insideConflict = ;
break;
}
if (insideConflict){
puts("Impossible");
continue;
}
for (int i=; i<=n; i++)
{
for (int j=; j<=n; j++) fbd[i][j] = fbd[i-][j];
if (pot[i-])
for (int j=b[i-].l; j<=b[i-].r; j++)
fbd[i][j] = ;
}
for (int i=; i<=n; i++)
{
stb = ;
for (int j=a[i].l; j<=a[i].r; j++)
if (!fbd[i][j]) stb = ;
if (!stb) break;
stb = ;
for (int j=; j<=n; j++)
if (!fbd[i][j]) stb++;
if (stb < n-i+){
stb = ;
break;
}
}
if (!stb)
puts("Impossible");
else puts("Possible");
}
return ;
}
END
【思维题】TCO14 Round 2C InverseRMQ的更多相关文章
- 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas
题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...
- HDU 5805 NanoApe Loves Sequence (思维题) BestCoder Round #86 1002
题目:传送门. 题意:题目说的是求期望,其实翻译过来意思就是:一个长度为 n 的数列(n>=3),按顺序删除其中每一个数,每次删除都是建立在最原始数列的基础上进行的,算出每次操作后得到的新数列的 ...
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- [CF1244C] The Football Season【数学,思维题,枚举】
Online Judge:Luogu,Codeforces Round #592 (Div. 2) C Label:数学,思维题, 枚举 题目描述 某球队一共打了\(n\)场比赛,总得分为\(p\), ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- cf A. Inna and Pink Pony(思维题)
题目:http://codeforces.com/contest/374/problem/A 题意:求到达边界的最小步数.. 刚开始以为是 bfs,不过数据10^6太大了,肯定不是... 一个思维题, ...
- ZOJ 3829 贪心 思维题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3829 现场做这道题的时候,感觉是思维题.自己智商不够.不敢搞,想着队友智商 ...
- 洛谷P4643 [国家集训队]阿狸和桃子的游戏(思维题+贪心)
思维题,好题 把每条边的边权平分到这条边的两个顶点上,之后就是个sb贪心了 正确性证明: 如果一条边的两个顶点被一个人选了,一整条边的贡献就凑齐了 如果分别被两个人选了,一作差就抵消了,相当于谁都没有 ...
随机推荐
- 笔记-迎难而上之Java基础进阶2
Set集合 import java.util.*; public class HashSetDemo{ public static void main(String[] args){ //Set接口的 ...
- 服务器宕机,mysql无法启动,job for mysql.service failed because the process exited with error code,数据库备份与恢复
[问题现象] 服务器在运行过程中,因人为意外导致电源被拔,服务器宕机,mysql重启不成功,报错如下 根据提示,输入systemctl status mysql.service和journalctl ...
- ffmpeg命令操作音频格式转换
1.转MP3为wav ffmpeg -i input.mp3 -acodec pcm_s16le -ac 2 -ar 44100 output.wav 2.转m4a为wav ffmpeg -i inp ...
- CentOS6.7 i686上安装JDK7
内核版本: [root@heima01 java]# uname -a Linux heima01 2.6.32-573.el6.i686 #1 SMP Thu Jul 23 12:37:35 UTC ...
- 学习笔记之a,b=b,a+b与a=b,b=a+b的区别
兔子序列中用到的常用的计算方法:a,b=b,a+b 当我们真正去运行的时候,会发现它与a=b,b=a+b是有区别的 实例代码如下: def YY(one): a,b,n=0,1,0 while( ...
- ES6新特性使用小结(五)
十二.class 与 extends ①.类的基本定义和生成实例 { class Parent{ constructor(name='Lain'){ //定义构造函数 this.name = name ...
- 用Open Live Writer写博体验
感觉还蛮方便的--openlivewriter第一博!
- NET Core 与 Vue.js 服务端渲染
NET Core 与 Vue.js 服务端渲染 http://mgyongyosi.com/2016/Vuejs-server-side-rendering-with-aspnet-core/原作者: ...
- zabbix agent 配置
http://blog.csdn.net/z644041867/article/details/76618644 https://www.cnblogs.com/miclesvic/p/6144924 ...
- Spark Mllib里如何建立密集向量和稀疏向量(图文详解)
不多说,直接上干货! 具体,见 Spark Mllib机器学习实战的第4章 Mllib基本数据类型和Mllib数理统计