RT,https://nanti.jisuanke.com/t/T3263
可以证明题意要求我们求序列最小值
可是我明明使用了线段树优化,反而比不加优化还慢,只有20分,你们知道是怎么回事吗?
代码:
#include<bits/stdc++.h>
using namespace std;
#define (long long) int
int p;
long long a[1000007];
struct node{
long long v, m;
}st[4000007];
void bt(int root, int l, int r){
if(l==r){
st[root].v=a[l];
st[root].m=a[l];
}
else{
int m=(l+r)/2;
bt(root*2, l, m);
bt(root*2+1, m+1, r);
st[root].v=st[root*2].v+st[root*2+1].v;
st[root].m=min(st[root*2].m,st[root*2+1].m);
}
return ;
}
long long query(int root, int stdl, int stdr, int l, int r){
if(r<stdl || stdr<l){
return 99999999;
}
if(l<=stdl && stdr<=r){
return st[root].m;
}
int m=(stdl+stdr)/2;
return min(query(root*2, stdl, m, l, r),query(root*2+1, m+1, stdr, l, r));
}
int main(){
freopen("and.in","r",stdin);
freopen("and.out","w",stdout);
int n, m;
scanf("%d%d", &n, &m);
for(int i=1; i<=n; i++){
scanf("%lld", &a[i]);
}
bt(1, 1, n);
while(m--){
int x, y;
scanf("%d%d", &x, &y);
printf("%lld\n", query(1, 1, n, x, y));
}
return 0;
}