Cod sursa(job #189986)

Utilizator stefysStefan stefys Data 19 mai 2008 16:14:09
Problema Arbori de intervale Scor 0
Compilator c Status done
Runda Arhiva educationala Marime 0.86 kb
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (void)
{
	unsigned int *minInt, intSize, N, i, x, op, a, b, st, en, crt;
	freopen("arbint.in", "r", stdin);
	freopen("arbint.out", "w+", stdout);
	
	scanf("%u\n", &N);
	intSize = sqrt(N);
	minInt = malloc(sizeof(unsigned int)*N);
	
	for (i=0; i<N; ++i) {
		scanf("%u", &crt);
		x = i/intSize;
		if (i%intSize == 0) minInt[x] = crt;
		else if (crt < minInt[x])
			minInt[x] = crt;
	} scanf("\n");
	while (scanf("%u %u %u\n", &op, &a, &b)) {
		switch (op) {
		case 0:
			st = a/intSize;
			en = b/intSize;
			crt = minInt[st];
			for (i=st+1; i<=en; ++i) if (minInt[i] < crt) crt = minInt[i];
			printf("%u\n",crt);
			break;
		case 1:
			st = a/intSize;
			if (b < minInt[st]) minInt[st] = b;
			break;
		}
	}
	free(minInt);	
	fclose(stdin);
	fclose(stdout);
	return 0;
}