Pagini recente » Cod sursa (job #2938806) | Cod sursa (job #1218328) | Cod sursa (job #157974) | Cod sursa (job #1295568) | Cod sursa (job #2234667)
#include <fstream>
#include <vector>
#include <math.h>
using namespace std;
/********** TEMPLATE STARTS HERE ***********/
#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define test int t; cin >> t; while(t--)
#define skip continue
#define stop break
#define sz(v) v.size()
#define endl '\n'
#define PI 3.1415926535897932384626433832795
#define EPS 1e-9
#define FR(i, l, r) for(int i = (l); i <= (r); i++)
#define gcd __gcd
#define FO(i, a) for(auto & i : a)
#define debug(a) cout << #a << ": " << a << endl
#define debug1(a, l, r) FR(i, l, r) cout << a[i] << " "; cout << endl
#define SET(a, b) memset(a, b, sizeof(a));
#define refresh fflush(stdout);
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <pll> vll;
const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;
template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
//template <typename T> inline void out(T x) { cout << x; }
/*********** TEMPLATE ENDS HERE *************/
ifstream cin ("rmq.in");
ofstream cout("rmq.out");
int a[100007][12];
int n;
void build_table()
{
for(int i = 1; i <= n; i++)
cin >> a[i][0];
int k = 1;
for(int j = 1; j <= log(n) + 1; j++, k *= 2)
for(int i = 1; i <= n - k; i++)
a[i][j] = min(a[i][j - 1], a[i + k][j - 1]);
// for(int i = 1; i <= n; i++ && cout << '\n')
// for(int j = 0; j <= log(n) + 1; j++)
// cout << a[i][j] << ' ';
}
main()
{
int q;
cin >> n >> q;
build_table();
while(q--)
{
int x, y;
cin >> x >> y;
int ans = INF;
int l = x;
while(l <= y)
{
int e = log(y - l + 1);
ans = min(ans, a[l][e]);
l += 1 << e;
}
cout << ans << '\n';
}
}