|
- #include <algorithm>
- #include <iostream>
- #include <cmath>
- #include <cstring>
- #include <map>
- #include <string>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <cstdio>
- #include <cstdlib>
- using namespace std;
- int a[100020],minn[400040],m,n,x,y,t;
- void biuld_xian(int l,int r,int o)
- {
- if(l==r)
- {
- minn[o]=a[l];
- return;
- }
- int mid=(l+r)>>1;
- biuld_xian(l,mid,o*2);
- biuld_xian(mid+1,r,o*2+1);
- minn[o]=min(minn[o*2],minn[o*2+1]);
- }
- int query(int L,int R,int l,int r,int o)
- {
- if(L<=l&&r<=R) return minn[o];
- int mid=(l+r)>>1;
- int a1=0x3f3f3f3f,a2=0x3f3f3f3f;
- if(L<=mid) a1=query(L,R,l,mid,o*2);
- if(R>mid) a2=query(L,R,mid+1,r,o*2+1);
- return min(a1,a2);
- }
- int main()
- {
- scanf("%d%d",&n,&t);
- for(int i=1;i<=n;i++)
- {
- scanf("%d",&a[i]);
- }
- biuld_xian(1,n,1);
- while(t--)
- {
- scanf("%d%d",&x,&y);
- printf("%d ",query(x,y,1,n,1));
- }
- return 0;
- }
复制代码 |
|