Cod sursa(job #2309022)
| Utilizator | Data | 28 decembrie 2018 12:31:02 | |
|---|---|---|---|
| Problema | Range minimum query | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define N 100001
using namespace std;
ifstream in("rmq.in");
ofstream out("rmq.out");
int dp[N][17];
int main(){
int n,m,x,y,i,j;
in>>n>>m;
for(i=1; i<=n; ++i)
in>>dp[i][0];
for(j=1; (1<<j)<=n; ++j)
for(i=1; i+(1<<j)-1<=n; ++i)
dp[i][j]=min(dp[i][j-1], dp[i+(1<<(j-1))][j-1]);
while(m--){
in>>x>>y;
j=log2(y-x+1);
cout<<min(dp[x][j], dp[y-(1<<j)+1][j])<<"\n";
}
return 0;
}
