Pagini recente » Cod sursa (job #91235) | Cod sursa (job #677601) | Cod sursa (job #1935627) | Cod sursa (job #1325416) | Cod sursa (job #2082638)
#include <bits/stdc++.h>
using namespace std;
class Reader {
public:
Reader(const string& filename):
m_stream(filename),
m_pos(kBufferSize - 1),
m_buffer(new char[kBufferSize]) {
next();
}
Reader& operator>>(int& value) {
value = 0;
while (current() < '0' || current() > '9')
next();
while (current() >= '0' && current() <= '9') {
value = value * 10 + current() - '0';
next();
}
return *this;
}
private:
const int kBufferSize = 32768;
char current() {
return m_buffer[m_pos];
}
void next() {
if (!(++m_pos != kBufferSize)) {
m_stream.read(m_buffer.get(), kBufferSize);
m_pos = 0;
}
}
ifstream m_stream;
int m_pos;
unique_ptr<char[]> m_buffer;
};
int n;
const int MAXN = 1e5 + 10;
int arb[MAXN<<1];
void build(){
for(int i = n; i > 0; --i){
arb[i] = max(arb[i<<1], arb[i<<1|1]);
}
}
void update(int poz, int val){
poz += n;
arb[poz] = val;
while(poz > 1){
arb[poz>>1] = max(arb[poz], arb[poz^1]);
poz>>=1;
}
}
int query(int st, int dr){
int best = -1;
st += n;
dr += n;
while(st < dr){
if(st&1) best = max(best, arb[st++]);
if(dr&1) best = max(best, arb[--dr]);
st>>=1;
dr>>=1;
}
return best;
}
int main(){
Reader f("arbint.in");
ofstream g("arbint.out");
int m;
f >> n >> m;
for(int i = 1; i <= n; ++i){
int x;
f >> arb[i+n];
}
build();
for(int i = 1; i <= m; ++i){
int cd, x, y;
f >> cd >> x >> y;
if(cd == 0) g << query(x, y+1) <<'\n';
else update(x, y);
}
return 0;
}