Pagini recente » Cod sursa (job #574036) | Cod sursa (job #2146534) | Cod sursa (job #2680432) | Cod sursa (job #3129654) | Cod sursa (job #1877571)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int n; int m;
int aib[NMAX];
int v[NMAX];
int query(int, int);
int bit(int x) { return x & -x; }
void change(int pos, int value) {
v[pos] = value;
for(int x = pos ; x <= n ; x += bit(x)) {
if(aib[x] == pos) {
int newMaxim = query(x - bit(x) + 1, x - 1);//log N, special query
aib[x] = v[x] > v[newMaxim] ? x : newMaxim;
} else
aib[x] = v[pos] > v[aib[x]] ? pos : aib[x];
}
}
int query(int st, int dr) {
int maxInd = 0;
for(int pos = dr; pos >= st; pos -= bit(pos)) {
if(pos - bit(pos) + 1 < st) { //nu pot face query
if(v[maxInd] < v[pos])
maxInd = pos;
pos--;
} else //e ok sa fac query pe intervalul [pos - bit(pos) + 1, pos]
maxInd = v[maxInd] < v[aib[pos]] ? aib[pos] : maxInd;
}
return maxInd;
}
int main() {
freopen("arbint.in", "r", stdin);
freopen("arbint.out", "w", stdout);
cin >> n >> m;
int a, b;
for(int i = 1; i <= n ; ++i) {
cin >> v[i];
change(i, v[i]);
}
int t;
aib[0] = -INF;
for(int i = 1; i <= m ; ++i) {
cin >> t >> a >> b;
if(t == 0) cout << v[query(a, b)] << '\n';
if(t == 1) change(a, b);
}
return 0;
}