Pagini recente » Cod sursa (job #2390957) | Cod sursa (job #14244) | Cod sursa (job #2955502) | Cod sursa (job #2695539) | Cod sursa (job #3124871)
#include <bits/stdc++.h>
class InParser {
private:
FILE *fin;
char *buff;
short pos = 4095;
inline char get_ch() {
++ pos;
if (pos == 4096) {
pos = 0;
fread(buff, 1, 4096, fin);
}
return buff[pos];
}
public:
InParser(const char *file) {
fin = fopen(file, "r");
buff = new char[4096]();
}
InParser& operator >> (int &x) {
char ch = get_ch();
while (!isdigit(ch))
ch = get_ch();
x = ch - '0';
ch = get_ch();
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = get_ch();
}
return *this;
}
};
int n, queries, *aint, *v, i;
inline void build(int node, int nleft, int nright) {
if (nleft == nright)
aint[node] = v[nleft];
else {
int mid = (nleft + nright) >> 1;
build(node << 1, nleft, mid);
build((node << 1) + 1, mid + 1, nright);
aint[node] = std :: max(aint[node << 1], aint[(node << 1) + 1]);
}
}
int left, right;
inline int query(int node, int nleft, int nright) {
if (left > nright or right < nleft)
return -1;
if (left <= nleft and right >= nright)
return aint[node];
int mid = (nleft + nright) >> 1;
return std :: max(query(node << 1, nleft, mid), query((node << 1) + 1, mid + 1, nright));
}
int update_pos, val;
inline void update(int node, int nleft, int nright) {
if (nleft == nright)
aint[node] = val;
else {
int mid = (nleft + nright) >> 1;
if (update_pos <= mid)
update(node << 1, nleft, mid);
else
update((node << 1) + 1, mid + 1, nright);
aint[node] = std :: max(aint[node << 1], aint[(node << 1) + 1]);
}
}
int x, y, op;
int main() {
std :: ios_base :: sync_with_stdio(0);
InParser fin("arbint.in");
fin >> n >> queries;
v = (int*)calloc(n + 2, sizeof(int));
aint = (int*)calloc((n << 2) + 2, sizeof(int));
for (i = 1; i <= n; ++ i)
fin >> v[i];
build(1, 1, n);
std :: ofstream fout("arbint.out");
while (queries) {
-- queries;
fin >> op >> x >> y;
if (op == 1) {
update_pos = x;
val = y;
update(1, 1, n);
}
else {
left = x;
right = y;
fout << query(1, 1, n) << '\n';
}
}
fout.close();
return 0;
}