RT,本地都RE。。。wzbl
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
inline int Read();
void Build(int, int, int);
inline void PushUp(int);
int GetAns(int, int, int, int, int);
int tree[100001 * 4], in[100001];
int main(int argc, char* argv[])
{
int n, m, f, t;
scanf("%d%d", &n, &m);
for(register int i = 1; i <= n; i++)
{
in[i] = Read();
}
memset(tree, INF, sizeof(tree));
Build(1, n, 1);
for(register int i = 1; i <= m; i++)
{
f = Read(), t = Read();
printf("%d ", GetAns(1, n, f, t, 1));
}
return 0;
}
inline int Read()
{
int data = 0, op = 1;
char chr = getchar();
while(chr < '0' || chr > '9')
{
if(chr == '-')
{
op = -1;
}
chr = getchar();
}
while(chr >= '0' && chr >= '9')
{
data = (data << 3) + (data << 1) + (chr ^ 48);
chr = getchar();
}
return data * op;
}
void Build(int left, int right, int root)
{
if(left == right)
{
tree[root] = in[left];
}
else
{
int mid = (left + right) / 2;
Build(left, mid, root * 2);
Build(mid + 1, right, root * 2 + 1);
PushUp(root);
}
}
inline void PushUp(int root)
{
tree[root] = min(tree[root * 2], tree[root * 2 + 1]);
}
int GetAns(int left, int right, int from, int to, int root)
{
int rst = INF;
if(left >= from && right <= to)
{
rst = tree[root];
}
else
{
int mid = (left + right) / 2;
if(from <= mid)
{
rst = min(GetAns(left, mid, from, to, root * 2), rst);
}
if(to > mid)
{
rst = min(GetAns(mid + 1, right, from, to, root * 2 + 1), rst);
}
}
return rst;
}