Untitled
raw download clone
TEXT
views 14
,
size 608 b
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
int n,q,M[21][maxn],a[maxn];
int rmq(int u, int v)
{
    int k=log2(v-u+1);
    return min(M[k][u],M[k][v-(1<<k)+1]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)   cin>>a[i],M[0][i]=a[i];
    for(int i=1;(1<<i)<=n;i++)   for(int j=1;j+(1<<i)-1<=n;j++)
    M[i][j]=min(M[i-1][j],M[i-1][j+(1<<(i-1))]);
    while(q--)
    {
        int u,v;
        cin>>u>>v;
        cout<<rmq(u+1,v)<<"\n";
    }
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.