Pagini recente » Cod sursa (job #2332058) | Cod sursa (job #1228850) | Cod sursa (job #1895632) | Cod sursa (job #1140709) | Cod sursa (job #2853900)
#include <fstream>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <algorithm>
#include <cstring>
#include <climits>
#define MOD 1000000007
using namespace std ;
ifstream cin ("arbint.in") ;
ofstream cout ("arbint.out") ;
struct nod
{
int st, dr, mid, val = 0 ;
nod *fiust, *fiudr ;
};
int query(nod *tatal, int st, int dr)
{
if(tatal -> st == st && tatal -> dr == dr)return tatal -> val ;
if(dr <= tatal -> mid)
return query(tatal -> fiust, st, dr) ;
if(st >= tatal -> mid + 1)
return query(tatal -> fiudr, st, dr) ;
return max(query(tatal -> fiust, st, tatal -> mid), query(tatal -> fiudr, tatal -> mid + 1, dr)) ;
}
void update(nod *tatal, int poz, int x)
{
if(tatal -> st == tatal -> dr)
{
tatal -> val = x ;
return ;
}
if(poz <= tatal -> mid)update(tatal -> fiust, poz, x) ;
else update(tatal -> fiudr, poz, x) ;
tatal -> val = max(tatal -> fiust -> val, tatal -> fiudr -> val) ;
}
nod tree[400009] ;
void create(int f, int st, int dr)
{
tree[f]. st = st ;
tree[f]. dr = dr ;
tree[f]. mid = (st + dr) / 2 ;
if(st == dr)return ;
tree[f].fiust = &tree[2 * f] ;
tree[f]. fiudr = &tree[2 * f + 1] ;
create(2 * f, st, tree[f]. mid) ;
create(2 * f + 1, tree[f]. mid + 1, dr) ;
}
int v[100009], n ;
int main()
{
int q ;
cin >> n >> q ;
create(1, 1, n) ;
for(int f = 1, a ; f <= n ; f ++)
cin >> a, update(&tree[1], f, a) ;
while(q --)
{
int a, b, c ;
cin >> a >> b >> c ;
if(a == 0)
cout << query(&tree[1], b, c) << '\n' ;
else update(&tree[1], b, c) ;
}
return 0 ;
}
/*
10 3
54 36 17 77 21 74 75 0 73 106
1 6 13427
1 4 6289
0 10 10
1 1 370
1 9 33
1 10 12273
0 8 9
0 8 9
1 7 3620
0 5 9
1 10 35
0 8 8
0 2 2
0 5 10
1 3 23314
0 1 5
0 2 9
1 9 33
1 10 9129
0 5 5
1 2 49
*/