bzoj 1067 分情况讨论
这道题考察人的严谨,各种情况分类讨论。
#include <cstdio>
#include <algorithm>
#include <map>
#define maxn 50010
#define maxq 17
#define P(i) (1<<(i))
#define yes 0
#define no 1
#define maybe 2
using namespace std; int n, q;
int year[maxn];
int st[maxn][maxq]; int ind( int y ) {
return (lower_bound( year+, year+n+, y ) - year);
}
void makest() {
for( int q=; q<maxq; q++ )
for( int i=; i<=(n-P(q)+); i++ )
st[i][q] = max( st[i][q-], st[i+P(q-)][q-] );
}
int fmax( int lf, int rg ) {
int len = rg-lf+;
if( len<= ) return -;
for( int q=maxq-; q>=; q-- )
if( len>P(q) ) {
return max( st[lf][q], st[rg-P(q)+][q] );
} else if( len==P(q) ) {
return st[lf][q];
}
return -;
}
int main() {
scanf( "%d", &n );
year[n+] = 0x7FFFFFFF;
for( int i=; i<=n; i++ )
scanf( "%d%d", year+i, &st[i][] );
makest();
sort( year+, year++n );
scanf( "%d", &q );
while( q-- ) {
int a, b, ia, ib;
scanf( "%d%d", &a, &b );
ia = ind(a), ib = ind(b);
if( year[ia]==a && year[ib]==b && b-a==ib-ia && st[ia][]>=st[ib][] && fmax(ia+,ib-)<st[ib][] ) {
printf( "true\n" );
continue;
}
if( year[ia]==a && year[ib]==b && b-a>ib-ia && st[ia][]>=st[ib][] && fmax(ia+(year[ia]==a),ib-)<st[ib][] ) {
printf( "maybe\n" );
continue;
}
if( ((year[ia]==a)^(year[ib]==b)) && fmax(ia+(year[ia]==a),ib-)< (year[ia]==a ? st[ia][] : st[ib][]) ) {
printf( "maybe\n" );
continue;
}
if( year[ia]!=a && year[ib]!=b ) {
printf( "maybe\n" );
continue;
}
printf( "false\n" );
}
}
bzoj 1067 分情况讨论的更多相关文章
- UESTC 1034 AC Milan VS Juventus 分情况讨论
AC Milan VS Juventus Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Oth ...
- HNU 12833 Omar’s Bug(分情况讨论)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12833&courseid=268 解题报告:有个11个 ...
- Valid Number——分情况讨论最经典的题(没细看)——这题必须静下心来好好看看
Validate if a given string is numeric. Some examples: "0" => true " 0.1 " =&g ...
- bzoj 1067: [SCOI2007]降雨量
题目链接: bzoj 1067: [SCOI2007]降雨量 题解: 很简单的一道题,但代码里有许多细节需要注意,切容易出错,调了三个小时OTZ 做一个st表维护区间最大值就 在获得年份在序列中的po ...
- bzoj2756: [SCOI2012]奇怪的游戏(网络流+分情况)
2756: [SCOI2012]奇怪的游戏 题目:传送门 题解: 发现做不出来的大难题一点一个网络流 %大佬 首先黑白染色(原来是套路...)染色之后就可以保证每次操作都一定会使黑白各一个各自的值加1 ...
- BZOJ 1067 降雨量(RMQ-ST+有毒的分类讨论)
1067: [SCOI2007]降雨量 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 4399 Solved: 1182 [Submit][Stat ...
- HDU6444(子段和、分情况比较)
要点 不难想到gcd一下然后枚举每个开头走一圈,并记录一下数值. 最终答案是分情况的:1.能走几圈走几圈然后加上最后剩余的最大子段和:2.也可能是最后一圈后面的拖后腿了,所以最后一圈没走完就停,即长度 ...
- bzoj 1067: [SCOI2007]降雨量 模擬
1067: [SCOI2007]降雨量 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2010 Solved: 503[Submit][Status] ...
- CONTINUE...?模拟分情况
CONTINUE...? DreamGrid has classmates numbered from to . Some of them are boys and the others are ...
随机推荐
- zedboard学习记录.1.纯PL流水灯
环境:vivado 217.4 开发板: zedboard ver.d xc7z020clg484-1 1.打开Vivado新建一个RTL工程. 2.add source->add/create ...
- tp修改的写法
- C语言回调函数总结
/* Main program ---calls--> Library function ---calls--> Callback funtion */ #include <stdi ...
- IE6-IE9不支持table.innerHTML的解决方法--终极解决办法
一.把要转译的内容放到其他属性中,例如“tt” <p class="feedback_answer_content" tt='${feedInfo.feedback_answ ...
- LeetCode862. Shortest Subarray with Sum at Least K
Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there ...
- PHP 执行系统外部命令的函数- system() exec() passthru()
PHP 执行系统外部命令的函数: system() exec() passthru()区别:system() 输出并返回最后一行shell结果.exec() 不输出结果,返回最后一行shell结果,所 ...
- IEEEXtreme 10.0 - Ellipse Art
这是 meelo 原创的 IEEEXtreme极限编程大赛题解 Xtreme 10.0 - Ellipse Art 题目来源 第10届IEEE极限编程大赛 https://www.hackerrank ...
- GUC-1 volatile
/* * 一.volatile 关键字:当多个线程进行操作共享数据时,可以保证内存中的数据可见. * 相较于 synchronized 是一种较为轻量级的同步策略. * * 注意: * 1. vola ...
- spring_150902_hibernatedaosupport
实体类: package com.spring.model; import javax.persistence.Entity; import javax.persistence.Id; import ...
- Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths
F - Berland and the Shortest Paths 思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦. #include<bits/stdc++.h> #defi ...