Pagini recente » Cod sursa (job #2969985) | Cod sursa (job #6142) | Cod sursa (job #1530906) | Cod sursa (job #2813121) | Cod sursa (job #1477759)
#include <bits/stdc++.h>
using namespace std;
class InputReader {
public:
InputReader() {}
InputReader(const char *file_name) {
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
inline InputReader &operator >>(int &n) {
while(buffer[cursor] < '0' || buffer[cursor] > '9') {
advance();
}
n = 0;
while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1 << 17;
int cursor;
char buffer[SIZE];
inline void advance() {
++ cursor;
if(cursor == SIZE) {
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
};
InputReader fin ("arbint.in");
ofstream fout ("arbint.out");
const int kmax = 100003;
const int blocksMax = 318;
int n, m, blockSize;
int v[kmax];
int blck[blocksMax];
void read(){
fin >> n >> m;
for (int i = 0; i < n; ++i)
fin >> v[i];
}
void build(){
blockSize = sqrt(n) + 1;
for (int i = 0; i < n; ++i)
blck[i / blockSize] = max(blck[i / blockSize], v[i]);
}
int go (int x){
return (x - blockSize) % blockSize;
}
int query (int a, int b){
int qtk = 0;
int l = b - blockSize;
for (; a % blockSize and a <= b; ++a)
qtk = max(qtk, v[a]);
for (; a <= l ; a += blockSize )
qtk = max(blck[a / blockSize], qtk);
for (; a <= b; ++a)
qtk = max(qtk, v[a]);
return qtk;
}
void solve(){
for ( ; m; --m){
int op, a, b;
fin >> op >> a >> b;
--a;
b -= !op;
if (!op){
fout << query(a, b) << "\n";
}
else {
v[a] = b;
blck[a / blockSize] = max(blck[a / blockSize], v[a]);
}
}
}
int main(){
read();
build();
solve ( );
}