[BZOJ1067] [SCOI2007] Rainfall
Question 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 for any
Y It can be said that "2005 is the largest since 2003", but it cannot be said that "2005 is the largest since 2002" due to the rainfall in some years is not
Know that some of the claims may be correct or incorrect.
Input
Enter only one row that contains a positive integer n, which is the known data. The following n lines are two integers per line Yi and ri, for year and rainfall, by year from small
To a large arrangement, namely yi The most rainfall since y years. "This sentence is true, must be false or" possible ".
Output
For each query, output true,false or maybe.
Input example
6 2002 4920 2003 5901 2004 2832 2005 3890 2007 5609 2008 3024 5 2002 2005 2003 2005 2002 2007 2003 2007 2005 2008
Output example
false true false maybe false
Data size and conventions
100% data satisfies: 1<=n<=50000, 1<=m<=10000, -10^9<=yi<=10^9, 1<=ri<=10^9
Exercises
category Big discussion.
Was Lower_bound pit, lower_bound looking for is greater than or equal to the minimum value of x, I give the maximum value of the memory is less than or equal to X .....
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include < algorithm> #include <stack> #include <vector> #include <queue> #include <cstdlib>using namespace Std;const int buffersize = 1 << 16;char buffer[buffersize], *head, *tail;inline char Getchar () {if (Hea D = = tail) {int L = fread (buffer, 1, buffersize, stdin); Tail = (Head = buffer) + L; } return *head++;} int read () {int x = 0, F = 1, char c = Getchar (), while (!isdigit (c)) {if (c = = '-') f =-1; c = Getchar ();} while (IsDigit (c)) {x = x * + C-' 0 '; c = Getchar ();} return x * f;} #define MAXN 50010int N, Q, YEAR[MAXN], Rain[maxn];int maxv[maxn<<2], mxy[maxn<<2], Mny[maxn<<2];bool iss[maxn<<2];void Build (int L, int R, int o) {if (L = = R) Maxv[o] = Rain[l], mxy[o] = mny[o] = Year[l], iss[o] = 1;el se {int M = L + R >> 1, LC = O << 1, rc = LC | 1;build (L, M, LC); Build (M+1, R, RC); Maxv[o] = max (MAXV[LC), MAXV[RC]); Iss[o] = ISS[LC] & ISS[RC] & (MXY[LC]-MNY[RC] = =-1); Mny[o] = MNY[LC]; Mxy[o] = MXY[RC];} return;} int _o[maxn<<2], cnt;int query (int L, int R, int o, int ql, int qr) {if (QL > QR) return-1;if (QL <= L &&am P R <= qr) {_o[++cnt] = O;return maxv[o];} int M = L + R >> 1, LC = O << 1, rc = LC | 1, ans = 0;if (ql <= m) ans = max (ans, query (L, M, LC, QL, QR)); if (qr > m) ans = max (ans, query (m+1, R, RC, QL, QR)); return ans;} BOOL QQ () {bool OK = 1;for (int i = 1; I <= cnt; i++) OK &= iss[_o[i]];for (int i = 1; i < cnt; i++) OK &= (mx Y[_o[i]]-mny[_o[i+1]] = =-1); return OK;} int main () {n = read (), for (int i = 1; I <= n; i++) Year[i] = Read (), rain[i] = read (), build (1, N, 1), q = Read (), and while (q --) {int yl = read (), yr = Read (), QL = Lower_bound (year + 1, year + n + 1, yl)-YEAR,QR = Lower_bound (year + 1, year + N + 1, yr)-year;if (YEAR[QL]! = yl) ql--;if (YEAR[QR]! = yr) qr--;int ans; CNT = 0;if (yl > yr) {puts ("false"); conTinue; }if (yl = = yr) {puts ("true"); continue;} if (yl >= Year[n]) {puts ("maybe"); continue;} if (yr <= year[1]) {puts ("maybe"); continue;} if (YL < year[1] && yr > Year[n]) {puts ("maybe"); continue;} if (year[ql] = = yl && yr > Year[n] && query (1, N, 1, ql+1, N) >= Rain[ql]) {puts ("false"); continue; }if (YEAR[QL]! = yl && yr > Year[n]) {puts ("maybe"); continue;} if (year[qr] = = yr && yl < year[1] && query (1, N, 1, 1, qr-1) >= RAIN[QR]) {puts ("false"); continue; }if (YEAR[QR]! = yr && yl < year[1]) {puts ("maybe"); continue;} if (yl = = yr-1) {if (year[ql] = yl && YEAR[QR] = = yr) {if (RAIN[QL] >= RAIN[QR]) puts ("true"); else puts ("false" );} Else puts ("maybe"); continue;} if (year[ql] = = yl && YEAR[QR] = = yr && rain[ql] >= RAIN[QR] && query (1, N, 1, ql+1, qr-1) < RAIN[QR]) {cnt = 0; query (1, N, 1, QL, QR), if (QQ ()) {puts ("true"); continue;}} if (year[ql] = = YL && YEAR[QR] = = yr) {if (RAIN[QL] < RAIN[QR]) {puts ("false"); continue;} if (query (1, N, 1, ql+1, qr-1) >= RAIN[QR]) {puts ("false"); continue;}} if (year[ql] = = yl && query (1, N, 1, ql+1, QR) >= rain[ql]) {puts ("false"); continue;} if (year[qr] = = yr && query (1, N, 1, ql+1, qr-1) >= RAIN[QR]) {puts ("false"); continue;} Puts ("maybe");} return 0;}
[BZOJ1067] [SCOI2007] Rainfall