1067: [scoi2007] Rainfall Time Limit: 1 sec memory limit: 162 MB
Submit: 2010 solved: 503
[Submit] [Status] Description
We often say this: "X years have the most rainfall since y years ". It means that the rainfall in X years cannot exceed y years, and the rainfall in any Y <z <X, Z years is strictly less than X years. For example, if the rainfall in 2004, 2832, and 3890 is, and respectively, it can be said that "is the most since ", however, it cannot be said that "2005 is the most popular since 2002", because the rainfall in some years is unknown, some statements may be correct or incorrect.
Input
The input line contains only one positive integer N, which is known data. The following n rows have two integers Yi and RI in each row, which are year and rainfall, arranged in ascending order of year, that is, Yi <yi + 1. The next row contains a positive integer m, which is the number of inquiries. Each row in the following m rows contains two numbers y and X, that is, "X years have the most rainfall since y years ." Is this sentence true, false, or "possible ".
Output
Output True, false, or maybe for each query.
Sample input6
2002 4920
2003 5901
2004 2832
2005 3890
2007 5609
2008 3024
5
2002 2005
2003 2005
2002 2007
2003 2007
2005 2008 sample outputfalse
True
False
Maybe
Falsehint
100% of the data meets the requirements: 1 <= n <= 50000, 1 <= m <= 10000,-10 ^ 9 <= Yi <= 10 ^ 9, 1 <= RI <= 10 ^ 9
Source
Poj 2637 worstweather ever
The online bidding process is not reliable. About the query that exceeds the given year boundary, 80% of online programs can all be hack.
Note that the question is stuck with an int and I am not familiar with lower_bound. (Lower_bound is open before and after being closed)
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<ctime>#include<cmath>#include<algorithm>#include<set>#include<map>#include<vector>#include<string>#include<queue>using namespace std;#ifdef WIN32#define LL "%I64d"#else#define LL "%lld"#endif#define MAXN 51100#define MAXV MAXN*2#define MAXE MAXV*2#define INF 0x3f3f3f3f#define INFL 0x3f3f3f3f3f3f3f3fLL#define yes {printf("true\n");continue;}#define no {printf("false\n");continue;}#define maybe {printf("maybe\n");continue;}typedef long long qword;inline int nextInt(){ char ch; int x=0; bool flag=false; do ch=(char)getchar(),flag=(ch==‘-‘)?true:flag; while(ch<‘0‘||ch>‘9‘); do x=x*10+ch-‘0‘; while (ch=(char)getchar(),ch<=‘9‘ && ch>=‘0‘); return x*(flag?-1:1);}int n,m;struct aaa{ int y,t;}l[MAXN];bool operator <(aaa a1,aaa a2){ return a1.y<a2.y;}int a[20][MAXN],b[20][MAXN];void init_rmq(){ int i,j; for (i=0;i<=n;i++) { a[0][i]=l[i].t; b[0][i]=l[i].t; } for (j=1;j<20;j++) { for (i=0;i+(1<<j)-1<=n;i++) { a[j][i]=min(a[j-1][i],a[j-1][i+(1<<j>>1)]); b[j][i]=max(b[j-1][i],b[j-1][i+(1<<j>>1)]); } }}int ff[MAXN];int get_max(int l,int r){ if (l>r)return -INF; return max(b[ff[r-l]][l],b[ff[r-l]][r-(1<<ff[r-l])+1]);}int main(){ freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int i,j,k; int x,y,z; scanf("%d",&n); memset(ff,-1,sizeof(ff)); for (i=0;i<19;i++) if ((1<<i)<=n)ff[(1<<i)]=i; ff[0]=0; for (i=1;i<=n;i++) { if (ff[i]==-1)ff[i]=ff[i-1]; } for (i=1;i<=n;i++) { scanf("%d%d",&l[i].y,&l[i].t); if (i>1 && l[i].y<l[i-1].y) throw 1; } l[0].y=-INF; scanf("%d",&m); int d1,d2; aaa t1,t2; init_rmq(); for (i=0;i<m;i++) { scanf("%d%d",&x,&y); // if (x>y)no; t1.y=x; t2.y=y; d1=lower_bound(l,l+n+1,t1)-l; d2=lower_bound(l,l+n+1,t2)-l; if (l[d2].y==y)//已知今年 { if (l[d1].y==x)//已知開始年份 { if (l[d1].t<l[d2].t)no; if (get_max(d1+1,d2-1)>=l[d2].t)no; if ((qword)d2-d1+1==(qword)y-x+1)yes; maybe;//中間年份缺失 }else { d1--; if (get_max(d1+1,d2-1)>=l[d2].t)no; maybe; } }else { if (l[d1].y==x) { if (l[d1].t<=get_max(d1+1,d2-1))no; maybe; }else { maybe; } } } return 0;}
Bzoj 1067: [scoi2007] rainfall Model