Pagini recente » Cod sursa (job #157339) | Cod sursa (job #2355403) | Cod sursa (job #2476522) | Cod sursa (job #1586140) | Cod sursa (job #1194299)
#include <fstream>
using namespace std;
const int N = 1 << 17;
class Aint{
int aint[2 * N];
inline static int getPos(int n){
return N + n - 1;
}
inline static int comp(int x, int y){
return x > y ? x : y;
}
public:
void update(int poz, int val){
aint[ poz += N - 1 ] = val;
while (poz >>= 1)
aint[poz] = comp(aint[poz << 1], aint[1 + (poz << 1)]);
}
int query(int x, int y){
int ansX = aint[x += N - 1], ansY = aint[y += N - 1];
int stopX = x >> (31 - __builtin_clz(x ^ y) );
int stopY = y >> (31 - __builtin_clz(x ^ y) );
while ( stopX < ( x >>= __builtin_ctz(~x) ) )
ansX = comp( ansX, aint[x ^= 1] );
while ( stopY < ( y >>= __builtin_ctz(y) ) )
ansY = comp( aint[y ^= 1], ansY );
return comp(ansX, ansY);
}
};
Aint A;
int main(){
int n, nrQ, tip, x, y;
ifstream in("arbint.in");
in >> n >> nrQ;
for (int i = 1 ; i <= n ; i++){
in >> x;
A.update(i, x);
}
ofstream out("arbint.out");
while (nrQ--){
in >> tip >> x >> y;
if (tip == 0)
out << A.query(x, y) << '\n';
else
A.update(x, y);
}
out.close();
in.close();
return 0;
}