#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5, mx=1e6+5;
int n, m, h[nx], t, x, y;
struct segtree
{
int d[4*mx], lz[4*mx];
void pushlz(int l, int r, int i)
{
if (l==r) return d[i]+=lz[i], lz[i]=0, void();
lz[2*i]+=lz[i];
lz[2*i+1]+=lz[i];
lz[i]=0;
}
void update(int l, int r, int i, int ql, int qr, int vl)
{
pushlz(l, r, i);
if (ql<=l&&r<=qr) return lz[i]+=vl, pushlz(l, r, i), void();
if (qr<l||r<ql) return;
int md=(l+r)/2;
update(l, md, 2*i, ql, qr, vl);
update(md+1, r, 2*i+1, ql, qr, vl);
}
int query(int l, int r, int i, int idx)
{
pushlz(l, r, i);
if (l==r) return d[i];
int md=(l+r)/2;
if (idx<=md) return query(l, md, 2*i, idx);
return query(md+1, r, 2*i+1, idx);
}
} s;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<=n; i++) cin>>h[i];
for (int i=2; i<=n; i++) s.update(1, mx-1, 1, min(h[i], h[i-1]), max(h[i], h[i-1]), 1);
while (m--)
{
cin>>t;
if (t==1)
{
cin>>x>>y;
if (x!=1) s.update(1, mx-1, 1, min(h[x], h[x-1]), max(h[x], h[x-1]), -1);
s.update(1, mx-1, 1, min(h[x+1], h[x]), max(h[x+1], h[x]), -1);
h[x]=y;
if (x!=1) s.update(1, mx-1, 1, min(h[x], h[x-1]), max(h[x], h[x-1]), 1);
s.update(1, mx-1, 1, min(h[x+1], h[x]), max(h[x+1], h[x]), 1);
}
else cin>>x, cout<<s.query(1, mx-1, 1, x)<<'\n';
}
}
/*
3 3
1 5 1
2 3
1 1 5
2 3
5 5
10 1 10 1 10
2 5
2 6
1 3 1
2 5
2 6
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
5 ms |
17756 KB |
Output is correct |
3 |
Correct |
4 ms |
17756 KB |
Output is correct |
4 |
Incorrect |
5 ms |
17756 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
5 ms |
17756 KB |
Output is correct |
3 |
Correct |
4 ms |
17756 KB |
Output is correct |
4 |
Incorrect |
5 ms |
17756 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
5 ms |
17756 KB |
Output is correct |
3 |
Correct |
4 ms |
17756 KB |
Output is correct |
4 |
Incorrect |
5 ms |
17756 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |