记录编号 |
426817 |
评测结果 |
AAAAAAAAAA |
题目名称 |
延绵的山峰 |
最终得分 |
100 |
用户昵称 |
kZime |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.108 s |
提交时间 |
2017-07-19 11:32:28 |
内存使用 |
22.73 MiB |
显示代码纯文本
# include <bits/stdc++.h>
# define MAXN 1000023
using namespace std;
char buf[1 << 18], *fs, *ft;
char ops[1 << 18], *opt = ops, *const opt_end = ops + (1 << 18);
inline char getc() {
return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}
inline int gn() {
int k = 0, f = 1;
char c = getc();
for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
return k * f;
}
inline void out() {
fwrite(ops, 1, opt - ops, stdout);
opt = ops;
}
inline void out(int x, char c) {
static char *p = new char[21]();
*(++p) = c;
do {
*(++p) = x % 10 | 0x30;
x /= 10;
} while(x);
while(*p) {
*(opt++) = *(p--);
if(opt == opt_end) out();
}
}
inline void out(char c) {
*(opt++) = c;
if(opt == opt_end) out();
}
int a[MAXN], mx[MAXN << 2], M;
inline void build(int n) {
for(M = 1; M + 1 <= n; M <<= 1);
for(int i = M + 1; i <= M + n; i++) {
mx[i] = gn();
}
for(int i = M; i >= 1; i--) {
mx[i] = max(mx[i << 1], mx[i << 1 | 1]);
}
}
inline int que(int l, int r) {
int ans = 0;
for(l += M - 1, r += M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
if(~l & 1) ans = max(ans, mx[l + 1]);
if(r & 1) ans = max(ans, mx[r - 1]);
}
return ans;
}
int main() {
freopen("climb.in","r",stdin);
freopen("climb.out","w",stdout);
int n = gn() + 1;
build(n);
int m = gn();
for(int i = 1; i <= m; i++) {
int l = gn() + 1, r = gn() + 1;
out(que(l, r), '\n');
}
out();
}