#include "bits/stdc++.h"
#define ll long long
using namespace std;
const int sz = 1e7 + 7;
int fw[sz], a[sz];
int n;
void add(int v, int k) {
for (; v <= n; v += v & -v)
fw[v] += k;
}
int qry(int hi) {
int r = 0;
for (; 0 < hi; hi -= hi & -hi)
r += fw[hi];
return r;
}
void relax(int v, int k) {
int r = v - 1;
if (a[r] < a[v])
add(a[r] + 1, k);
else if (a[r] > a[v])
add(a[v] + 1, k);
}
int main() {
int m; cin >> n >> m;
for (int i = 1; i <= n; i ++)
cin >> a[i];
for (int i = 2; i <= n; i ++)
relax(i, 1);
while (m --) {
int t; cin >> t;
if (1 == t) {
int p, v; cin >> p >> v;
int l = a[p];
for (int i : {0, 1}) {
if (1 == p and 0 == i)
continue;
relax(p + i, -1);
a[p] = v;
relax(p + i, 1);
a[p] = l;
}
a[p] = v;
} else {
int x; cin >> x;
cout << qry(x) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |