Cod sursa(job #2644240)

Utilizator emberlustAlbuica Lucian Ionut emberlust Data 24 august 2020 00:08:52
Problema Range minimum query Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
	long int N, M, a[100000], nr, i = 1, x, y, t, k = 1;

	ifstream f("rmq.in");
	ofstream g("rmq.out");

	f >> N >> M;
	
	while (i<=N)
	{
		f >> nr;
		a[i] = nr;
		i++;
	}

	while (k<=M)
	{
		f >> x >> y;
		 t = a[x];
		while (x <= y)
		{
			if (a[x] < t)
				t = a[x];

			x++;
		}
		g << t<<" ";
		k++;
	}
	f.close();
	g.close();
	return 0;
}