主要还是细节分析;线段树作为工具

Description

  我们常常会说这样的话:“X年是自Y年以来降雨量最多的”。它的含义是X年的降雨量不超过Y年,且对于任意
Y<Z<X,Z年的降雨量严格小于X年。例如2002,2003,2004和2005年的降雨量分别为4920,5901,2832和3890,
则可以说“2005年是自2003年以来最多的”,但不能说“2005年是自2002年以来最多的”由于有些年份的降雨量未
知,有的说法是可能正确也可以不正确的。

Input

  输入仅一行包含一个正整数n,为已知的数据。以下n行每行两个整数yi和ri,为年份和降雨量,按照年份从小
到大排列,即yi<yi+1。下一行包含一个正整数m,为询问的次数。以下m行每行包含两个数Y和X,即询问“X年是
自Y年以来降雨量最多的。”这句话是必真、必假还是“有可能”。

Output

  对于每一个询问,输出true,false或者maybe。

Sample Input

6
2002 4920
2003 5901
2004 2832
2005 3890
2007 5609
2008 3024
5
2002 2005
2003 2005
2002 2007
2003 2007
2005 2008

Sample Output

false
true
false
maybe
false

HINT

100%的数据满足:1<=n<=50000, 1<=m<=10000, -10^9<=yi<=10^9, 1<=ri<=10^9


题目分析

题意很简单,但是一道需要细细思考的细节题。

具体的思路,挂一个很详细的博客好了题解 P2471 【[SCOI2007]降雨量】

至于具体实现我用了离散化,然后用线段树查询(x,y)区间内的最值。

 #include<bits/stdc++.h>
const int maxn = ; struct QRs
{
int x,y;
}qr[];
struct node
{
int x,val;
}a[maxn];
int n,m;
int tot[],t[],cnt;
int val[],f[]; 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;
}
void pushup(int x)
{
f[x] = std::max(f[x<<], f[x<<|]);
}
void build(int rt, int l, int r)
{
if (l==r){
f[rt] = val[l];
return;
}
int mid = (l+r)>>;
build(rt<<, l, mid), build(rt<<|, mid+, r);
pushup(rt);
}
int query(int rt, int L, int R, int l, int r)
{
if (L > R) return ;
if (L <= l&&r <= R) return f[rt];
int mid = (l+r)>>, ret = ;
if (L <= mid) ret = query(rt<<, L, R, l, mid);
if (R > mid)
ret = std::max(ret, query(rt<<|, L, R, mid+, r));
return ret;
}
int main()
{
n = read();
for (int i=; i<=n; i++)
t[++cnt] = a[i].x = read(), a[i].val = read();
m = read();
for (int i=; i<=m; i++)
t[++cnt] = qr[i].x = read(), t[++cnt] = qr[i].y = read(), t[++cnt] = qr[i].y-, t[++cnt] = qr[i].x+;
std::sort(t+, t+cnt+);
cnt = std::unique(t+, t+cnt+)-t-;
int pre = ;
for (int i=; i<=n; i++)
{
int tt = std::lower_bound(t+, t+cnt+, a[i].x)-t;
val[tt] = a[i].val, tot[tt] = tot[pre]+, pre = tt;
}
build(, , cnt);
for (int i=; i<=m; i++)
{
int x = std::lower_bound(t+, t+cnt+, qr[i].x)-t;
int y = std::lower_bound(t+, t+cnt+, qr[i].y)-t;
int dex = std::lower_bound(t+, t+cnt+, qr[i].x+)-t;
int dey = std::lower_bound(t+, t+cnt+, qr[i].y-)-t;
if (val[x]&&val[y]){
if (val[x] < val[y]) puts("false");
else{
bool exCheck = query(, dex, dey, , cnt)<val[y];
if (!exCheck) puts("false");
else{
exCheck = exCheck&&((tot[y]-tot[x])==(qr[i].y-qr[i].x));
if (!exCheck) puts("maybe");
else puts("true");
}
}
continue;
}
if ((!val[x])&&(!val[y])) puts("maybe");
else{
int secMx = query(, dex, dey, , cnt);
if (!secMx){
puts("maybe");
continue;
}
if (val[x]){
if (secMx >= val[x]) puts("false");
else puts("maybe");        //注意这里是maybe而不是true因为中间值未知
}
if (val[y]){
if (secMx >= val[y]) puts("false");
else puts("maybe");
}
}
}
return ;
}

END

【线段树 细节题】bzoj1067: [SCOI2007]降雨量的更多相关文章

  1. 【2019.10.7 CCF-CSP-2019模拟赛 T2】绝对值(abs)(线段树细节题)

    找规律 设\(p_i=a_{i+1}-a_i\),则答案就是\(\sum_{i=1}^{n-1}p_i\). 考虑若将\(a_i\)加上\(x\)(边界情况特殊考虑),就相当于是将\(p_{i-1}\ ...

  2. hdu-5023线段树刷题

    title: hdu-5023线段树刷题 date: 2018-10-18 13:32:13 tags: acm 刷题 categories: ACM-线段树 概述 这道题和上次做的那道染色问题一样, ...

  3. poj-2777线段树刷题

    title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,, ...

  4. [AHOI 2009] 维护序列(线段树模板题)

    1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec  Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...

  5. [BZOJ1067][SCOI2007]降雨量

    [BZOJ1067][SCOI2007]降雨量 试题描述 我们常常会说这样的话:“X年是自Y年以来降雨量最多的”.它的含义是X年的降雨量不超过Y年,且对于任意 Y<Z<X,Z年的降雨量严格 ...

  6. POJ 3468 线段树裸题

    这些天一直在看线段树,因为临近期末,所以看得断断续续,弄得有些知识点没能理解得很透切,但我也知道不能钻牛角尖,所以配合着刷题来加深理解. 然后,这是线段树裸题,而且是最简单的区间增加与查询,我参考了A ...

  7. hdu-1540线段树刷题

    title: hdu-1540线段树刷题 date: 2018-10-18 19:55:21 tags: acm 刷题 categories: ACM-线段树 概述 哇,,,这道线段树的题可以说是到目 ...

  8. zoj-1610线段树刷题

    title: zoj-1610线段树刷题 date: 2018-10-16 16:49:47 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道简单的线段树区间染色问 ...

  9. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and stack 线段树好题

    http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...

随机推荐

  1. windows 系统 GitBook生成PDF、epub报错Error during ebook generation: 'ebook-convert' 乱码

    解决方法 1. 根据你的系统下载calibre并安装 2. 右键属性打开桌面图标位置 3 .复制该路径: 4. 打开我的电脑-属性-系统-高级系统设置-环境变量,配置环境. 5. 编辑"PA ...

  2. C#连接Sybase数据库,Anywhere 8

    数据库版本是Adaptive Server Anywhere 8 1.添加引用,程序集 iAnywhere.Data.AsaClient.dll文件在数据库的安装目录下,例如:C:\Program F ...

  3. Flutter中的可滚动列表组件-PageView

    PageVIew,可滚动的视图列表组件,而且每一个子组件的大小都和视图窗口大小一样. 属性: controller -> PageController 用于控制视图页面滚动到的位置 childr ...

  4. java 阻塞队列(转)

    转自 http://ifeve.com/java-blocking-queue/ 1. 什么是阻塞队列? 阻塞队列(BlockingQueue)是一个支持两个附加操作的队列.这两个附加的操作是:在队列 ...

  5. 设置DataTable行属性

    dt.Columns["ColumnName"].DataType=Type.GetType("System.bool");

  6. jieba gensim 最好别分家之最简单的相似度实现

    简单的问答已经实现了,那么问题也跟着出现了,我不能确定问题一定是"你叫什么名字",也有可能是"你是谁","你叫啥"之类的,这就引出了人工智能 ...

  7. Tourists Codeforces - 487E

    https://codeforces.com/contest/487/problem/E http://uoj.ac/problem/30 显然割点走过去就走不回来了...可以看出题目跟点双有关 有一 ...

  8. 转:在linux中vi 文件里行尾奇怪的^M及解决

    Linux编辑器vim中删除行尾的^M 有时候,在 Linux 中使用打开曾在 Windows 中编辑过的文件时,会在行尾看到 ^M 字符.看起来总是感觉很别扭. 删除方法如下: 在 Vim 的命令模 ...

  9. 097 Interleaving String 交错字符串

    给定三个字符串 s1, s2, s3, 验证 s3 是否是由 s1 和 s2 交错组成的.例如,给定:s1 = "aabcc",s2 = "dbbca",当 s ...

  10. [已读]你不知道的JavaScript(上卷)

    就在前幾天,我在看完第一部分的時候,說它在我心中要超過蝴蝶書了,好吧,現在要收回這句話.第二部分的內容著重在ecma5,6對象的新特性的介紹,深度上就一般啦,沒什麼收穫.總體來說,這本書詞法作用域,作 ...