题目名称:忠诚
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int a[N],tr[N]; //存管理区间范围内的所有值的最小值
int n,t;
int lowbit(int x)
{
return x & (-x);
}
void update(int a,int b)
{
for(int i = a;i <= N;i += lowbit(i))
{
tr[i] = min(tr[i],b);
}
}
int main()
{
cin >> n >> t;
memset(tr,0x3f,sizeof tr);
for(int i = 1;i <= n;i ++)
{
cin >> a[i];
update(i,a[i]);
}
while(t --)
{
int l,r;
cin >> l >> r;
int minn = 1e9;
int idx = r;
while(idx >= l)
{
if(idx - lowbit(idx) > l)
{
minn = min(minn,tr[idx]);
idx -= lowbit(idx);
}
else
{
minn = min(minn,a[idx]);
idx --;
}
}
cout << minn << ' ';
}
return 0;
}