Pagini recente » Cod sursa (job #2186886) | Cod sursa (job #476825) | Cod sursa (job #921458) | Cod sursa (job #1826577) | Cod sursa (job #1182007)
#include <fstream>
#include <iostream>
#include <cstring>
using namespace std;
const int N = 1e5;
template<class Type, const Type E, Type comp(Type, Type)>
class MonoAib{
Type st[N + 2], dr[N + 1];
int size;
inline static int lsb(int x){
return x & -x;
}
inline Type comp3(Type a, Type b, Type c){
return comp( comp(a, b), c );
}
public:
void reset(int n){
memset(st, E, sizeof(st));
memset(dr, E, sizeof(dr));
size = n;
}
void update(int x, Type newVal){
for (int i = x + 1 ; i <= size + 1 ; i += lsb(i))
st[i] = comp3( eQuery(i - lsb(i), x), newVal, eQuery(x + 1, i) );
for (int i = x ; i ; i -= lsb(i))
dr[i] = comp3( eQuery(i, x), newVal, eQuery(x + 1, i + lsb(i)) );
}
Type eQuery(int x, int y){
if (y <= x)
return E;
Type left = E, right = E;
int p;
while (x != y){
p = lsb(x | y);
if (x & p){
left = comp(left, dr[x]);
x += p;
}
if (y & p){
right = comp(st[y], right);
y -= p;
}
}
return comp(left, right);
}
Type query(int x, int y){
return eQuery(x, y + 1);
}
};
inline int max(int a, int b){
return a > b ? a : b;
}
MonoAib<int, 0, max> A;
int main(){
int n, nrE, tip, x, y;
ifstream in("arbint.in");
in >> n >> nrE;
A.reset(n);
for (int i = 1 ; i <= n ; i++){
in >> x;
A.update(i, x);
}
ofstream out("arbint.out");
while (nrE--){
in >> tip >> x >> y;
if (tip == 1)
A.update(x, y);
else
out << A.query(x, y) << '\n';
}
in.close();
out.close();
return 0;
}