Pagini recente » Cod sursa (job #26004) | Cod sursa (job #522671) | Cod sursa (job #2083771) | Cod sursa (job #1712524) | Cod sursa (job #1097874)
#include <fstream>
#include <cassert>
using namespace std;
ifstream fin ("arbint.in");
ofstream fout ("arbint.out");
const int NMAX = 100009;
int N; int M; int max_value;
class Arbore {
static const int NMAX = 100009;
private: int Arb[NMAX * 4];
public :
int max(int X, int Y){ if(X > Y) return X; else return Y;}
void update(int nod, int st, int dr, const int &pos, const int &value) {
if(st == dr) {Arb[nod] = value; }
else {
int mid = (st + dr) / 2;
if(pos <= mid)
update(nod * 2, st, mid, pos, value);
else
update(nod * 2 + 1, mid + 1, dr, pos, value);
Arb[nod] = max(Arb[nod * 2], Arb[nod * 2 + 1]);
}
}
void query(int nod, int st, int dr, const int &pos_st, const int &pos_dr) {
if(pos_st <= st && dr <= pos_dr)
max_value = max(max_value, Arb[nod]);
else {
int mid = (st + dr) / 2;
if(pos_st <= mid) query(nod * 2, st, mid, pos_st, pos_dr);
if(mid < pos_dr) query(nod * 2 + 1, mid + 1, dr, pos_st, pos_dr);
}
}
} A;
int main() {
fin >> N >> M;
assert(N <= 100000 && M <= 100000);
for(int i = 1; i <= N; ++i) {
int value; fin >> value;
A.update(1, 1, N, i, value);
}
while( M-- ) {
int type;int a; int b ; fin >> type; fin >> a >> b;
if(type == 1) A.update(1 , 1 , N, a , b);
if(type == 0) {max_value = 0; A.query(1 , 1, N, a, b); fout << max_value <<'\n';}
}
return 0;
}