Pagini recente » Cod sursa (job #2341854) | Cod sursa (job #1715139) | Cod sursa (job #2286770) | Cod sursa (job #3228714) | Cod sursa (job #1097951)
#include <fstream>
#include <cassert>
using namespace std;
ifstream fin ("arbint.in");
ofstream fout ("arbint.out");
int N; int M; int max_value;
class Arbore {
static const int NMAX = (1 << 18);
private: int Arb[NMAX];
public :
int max(int X, int Y){ if(X > Y) return X; else return Y;}
int left(const int &nod) {
return nod * 2;
}
int right(const int &nod){
return nod * 2 + 1;
}
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(left(nod), st, mid, pos, value);
else
update(right(nod), mid + 1, dr, pos, value);
Arb[nod] = max(Arb[left(nod)], Arb[right(nod)]);
}
}
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(left(nod), st, mid, pos_st, pos_dr);
if(mid < pos_dr) query(right(nod), 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;
}