比赛 线段数树状数组 评测结果 TTTTTTTTTT
题目名称 求和问题 最终得分 0
用户昵称 jekyll 运行时间 12.000 s
代码语言 C++ 内存使用 46.09 MiB
提交时间 2018-06-18 21:36:02
显示代码纯文本
#include<cstdio>
#include<iostream>
#define lc rt<<1
#define rc rt<<1|1
#define st 0, n, 1
#define ls l, mid, rt<<1
#define rs mid + 1, r, rt<<1|1
#define pushup(rt) tree[rt] = max(tree[lc], tree[rc])

using namespace std;

typedef long long ll;
const int INF = 1e9;
const int maxN = 1000005;

ll n, m;
ll tree[maxN * 4], a[maxN], maxtag[maxN];

void build(ll l, ll r, ll rt)
{
	if (l == r) { tree[rt] = a[l]; return;}
	int mid = (l + r) >> 1;
	build(ls);
	build(rs);
	pushup(rt);
}

ll query(ll L, ll R, ll l, ll r, ll rt)
{
    if (L <= l && r <= R) return tree[rt];
    ll ans = 0, mid = (l + r) >> 1;
    if (L <= mid) ans = max(ans, query(L, R, ls));
    if (mid < R) ans = max(ans, query(L, R, rs));
    return ans;
}

inline ll readll()  
{  
    ll X = 0, w = 0; char ch = 0;  
    while (ch > '9' || ch < '0') w = w | ch == '-', ch = getchar(); 
    while (ch <= '9' && ch >= '0') X = (X<<3) + (X<<1) + (ch^48), ch = getchar();  
    return w ? -X: X;  
}

int main_() 
{
	freopen("climb.in", "r", stdin);
	freopen("climb.out", "w", stdout);
    n = readll();
	for (int i = 0; i <= n; i++)
	    a[i] = readll();
	    build(st);
	int l, r; m = readll();
	for (int i = 1; i <= m; i++) 
	    l = readll(), r = readll(), printf("%lld\n", query(l, r, st));
	return 0;
}
int Main = main_();

int main() { ;}