The water problem Time limit:1500/1000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 0 Accepted Submission (s): 0
Problem Description in land waterless, water is a very limited resource. People always fight for the biggest source of water. Given a sequence of water sources with a1,a2,a3,..., anrepresenting the size of the water source. Given a set of queries each containing 2 integers l and R, please find out the biggest water source between Al and AR .
Input First you is given an integer T (t≤10) indicating the number of test cases. For each test case, there was a number n (0≤n≤1000) on a line representing the number of water sources. n integers follow, respectively a1,a2,a3,..., an, and each are in {1,..., 106}. On the next line, there is a number Q (0≤q≤1000) representing the number of queries. After that, there'll be Q lines with-integers l and R (1≤l≤r≤n) indicating the range of which you should find out The biggest water source.
Output for each query, output an integer representing the size of the biggest water source.
Sample Input
3 1 100 1 1 1 5 1 2 3 4 5 5 1 2 1 3 2 4 3 4 3 5 3 1 999999 1 4 1 1 1 2 2 3 3 3
Sample Output
100 2 3 4 4 5 1 999999 999999 1 because of the same topic, water problem
#include <map> #include <set> #include <cmath> #include <ctime> #include <queue> #include & lt;vector> #include <cctype> #include <cstdio> #include <string> #include <cstring> #include <sstream> #include <cstdlib> #include <iostream> #include <algorithm> #include <functional
> Using namespace std; #define PB push_back #define MP Make_pair #define FILLCHAR (A, X) memset (A, X, sizeof (a)) #define copy (A, b) memcpy (A, B, s
Izeof (a)) #define Lson RT << 1, L, MID #define Rson RT << 1|1, Mid + 1, r typedef long long LL;
typedef pair<int, int > PII;
typedef unsigned long long ULL; Template<typename t> void Print (t* p, t* q, String Gap = "") {int d = p < Q?
1:-1;
while (P! = q) {cout << *p;
p + = D;
if (P! = q) cout << Gap;
} cout << Endl; } template<typename t> void print (const T &a, String bes = "") {int LEn = Bes.length ();
if (Len >= 2) cout << bes[0] << a << bes[1] << Endl;
else cout << a << Endl;
} const int INF = 0X3F3F3F3F;
const int MAXM = 2E5;
const int MAXN = 1E3 + 5;
int T, N, SUM[MAXN << 2];
void pushup (int rt) {Sum[rt] = max (sum[rt << 1], sum[rt << 1|1]);}
void build (int rt, int l, int r) {if (L = = r) {cin >> sum[rt];
Return
} int mid = (L + r) >> 1;
Build (Lson);
Build (Rson);
Pushup (RT);
} int query (int l, int r, int rt, int l, int r) {if (L <= l && R <= R) {return SUM[RT];
} int mid = (L + r) >> 1;
int ret = 0;
if (L <= mid) ret = MAX (ret, query (L, R, Lson));
if (R > Mid) ret = MAX (ret, query (L, R, Rson));
return ret;
} int main () {//freopen ("D://imput.txt", "R", stdin);
int L, r, Q;
Cin >> T;
while (T--) {cin >> n;
Build (1, 1, N); CIN ≫> Q;
while (Q-) {cin >> L >> R;
cout << Query (L, R, 1, 1, N) << Endl;
}} return 0; }