Pagini recente » Cod sursa (job #672643) | Cod sursa (job #937255) | Cod sursa (job #212914) | Cod sursa (job #2180740) | Cod sursa (job #2419564)
// bril.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <fstream>
using namespace std;
#define min(a,b) (a>b?b:a)
#define max(a,b) (a<b?b:a)
ifstream fin("arbint.in");
ofstream fout("arbint.out");
struct nod {
int ma, left, right;
//nod *leftNod, *rightNod;
};
nod noduri[200010];
int n, m;
void constr(int poz) {
if (noduri[poz].left == noduri[poz].right) {
fin >> noduri[poz].ma;
}
else {
int mid = (noduri[poz].left + noduri[poz].right) / 2;
noduri[2 * poz].left = noduri[poz].left;
noduri[2 * poz].right = mid;
noduri[2 * poz + 1].left = mid+1;
noduri[2 * poz + 1].right = noduri[poz].right;
constr(2*poz);
constr(2 * poz+1);
noduri[poz].ma = max(noduri[2 * poz].ma, noduri[2 * poz + 1].ma);
}
}
void do1(int poz, int a, int b) {
if (noduri[poz].left == a&&noduri[poz].right == a)
noduri[poz].ma = b;
else {
int mid = (noduri[poz].left + noduri[poz].right) / 2;
if (a <= mid)
do1(2*poz, a, b);
else
do1(2*poz+1, a, b);
noduri[poz].ma = max(noduri[2 * poz].ma, noduri[2 * poz + 1].ma);
}
}
int do0(int poz, int a, int b) {
if (noduri[poz].left == a&&noduri[poz].right == b)
return noduri[poz].ma;
int mid = (noduri[poz].left + noduri[poz].right) / 2;
if (b <= mid)
return do0(2*poz, a, b);
if (a <= mid&&b > mid)
return max(do0(2 * poz, a, mid), do0(2 * poz + 1,mid+1,b));
if (a > mid)
return do0(2 * poz+1, a, b);
return 0;
}
int main()
{
fin >> n >> m;
noduri[1].left = 1;
noduri[1].right = n;
constr(1);
int x, y, z;
for (int i = 1; i <= m; ++i) {
fin >> x >> y >> z;
if (x == 0)
fout << do0(1,y,z)<<"\n";
else
do1(1, y, z);
}
fin.close();
fout.close();
return 0;
}