2439 Rainfall
2007 Provincial Team tryouts in Sichuan
time limit: 1 sspace limit: 64000 KBtopic rank: Master MasterTitle Description
Description
We often say this: "X year is the most rainfall since y years." It means that the rainfall in x years does not exceed Y years, and the rainfall for any y<z<x,z year is strictly less than x years. For example, 2002,2003,2004 and 2005 of rainfall were 4920,5901,2832 and 3890 respectively, it can be said that "2005 is the largest since 2003", but it cannot be said that "2005 is the largest since 2002" because of some years of rainfall is unknown, Some of the claims may be correct or incorrect.
Enter a description
Input Description
Enter only one row that contains a positive integer n, which is the known data. The following n lines are two integers yi and riper line, for years and rainfall, arranged by year from small to large, i.e. Yi<yi+1. The next line contains a positive integer m, which is the number of queries. The following m lines contain two numbers y and x for each row, which asks "X year is the most rainfall since y years." "This sentence is true, must be false or" possible ".
Output description
Output Description
For each query, output true,false or maybe.
Sample input
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
Sample Output
False
True
False
Maybe
False
Data range and Tips
Data Size & Hint
100% data satisfies: 1<=n<=50000, 1<=m<=10000, -109<=yi<=109, 1<=ri <=109
Exercises
ST Table maintenance interval + binary search
Code:
1#include <cstdio>2#include <cstdlib>3#include <climits>4#include <algorithm>5 #defineMAXN 1000056 #defineLogn 187 8 using namespacestd;9 Ten intN,ST[LOGN][MAXN],Q,X,Y,D[MAXN],A[MAXN],ANS,LOGN,LOG[MAXN]; One A intQueryintLintR) - { - if(L>r)returnint_min; the intlen=log[r-l+1]; - returnMax (st[len][l],st[len][r-(1<<len) +1]); - } - + voidbuild () - { +logn=Log[n]; A for(intI=0; i<=n;i++) st[0][i]=A[i]; at for(intI=1; i<=logn;i++) - for(intj=1; j<=n-(1<<i) +1; j + +) -St[i][j]=max (st[i-1][j],st[i-1][j+ (1<<i-1)]); - } - - intGetPosintx) {returnLower_bound (d +1, D + n +1, X)-D;} in - intMain () to { + for(intI=1, j=1, k=-1; i<=maxn;i++) - if(I==J) log[i]=++k,j<<=1; the Elselog[i]=K; *scanf"%d",&n); $ for(intI=1; i<=n;++i)Panax Notoginsengscanf"%d%d", d+i,a+i); -scanf"%d",&q); the build (); + while(q--) A { thescanf"%d%d",&x,&y); + intL=getpos (x), r=GetPos (y), M; - BOOLlx=l<=n&&d[l]==x,rx=r<=n&&d[r]==y; $ if(!RX)--R; $ if(LX) - if(RX) - { them = Query (L +1, R-1); - if(A[l]<a[r]) ans=0;Wuyi Else the if(m<A[r]) - if(r-l==y-x) ans=1; Wu Elseans=-1; - Elseans=0; About } $ Else - { -M=query (L +1, R); - if(M<a[l]) ans=-1; A Elseans=0; + } the Else - if(RX) $ { theM=query (l,r-1); the if(M < a[r]) ans=-1; the ElseAns =0; the } - Elseans=-1; in if(ans==1) printf ("true\n"); the Else if(!ans) printf ("false\n"); the Elseprintf"maybe\n"); About } the return 0; the}
C + + Road advanced--st table (rainfall)