Cod sursa(job #3289372)
| Utilizator | Data | 26 martie 2025 17:37:24 | |
|---|---|---|---|
| Problema | Range minimum query | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("rmq.in");
ofstream g("rmq.out");
int n,q,x,y,dp[100200][20];
int main()
{
f>>n>>q;
for(int i=1; i<=n; i++)
f>>dp[i][0];
for(int i=1; i<=17; i++)
for(int j=1; j<=n-(1<<i)+1; j++)
dp[j][i]=min(dp[j][i-1],dp[j+(1<<(i-1))][i-1]);
for(int i=1; i<=q; i++)
{
f>>x>>y;
int lung=y-x+1;
int l=log2(lung);
g<<min(dp[x][l],dp[y-(1<<l)+1][l])<<'\n';
}
return 0;
}
