#include <bits/stdc++.h>
using namespace std;
const int MAX=1e6;
int n,T,a[100005],tree[4000005],lazy[4000005];
void Down(int k)
{
tree[2*k]+=lazy[k];
lazy[2*k]+=lazy[k];
tree[2*k+1]+=lazy[k];
lazy[2*k+1]+=lazy[k];
lazy[k]=0;
}
void Update(int k,int l,int r,int L,int R,int val)
{
if(l>R||L>r)
return;
if(L<=l&&r<=R)
{
tree[k]+=val;
lazy[k]+=val;
return;
}
Down(k);
int mid=(l+r)/2;
Update(2*k,l,mid,L,R,val);
Update(2*k+1,mid+1,r,L,R,val);
}
int Query(int k,int l,int r,int pos)
{
if(l==r)
return tree[k];
Down(k);
int mid=(l+r)/2;
if(pos<=mid)
return Query(2*k,l,mid,pos);
return Query(2*k+1,mid+1,r,pos);
}
int main()
{
ios_base::sync_with_stdio(false);
//freopen("TEST.INP","r",stdin);
cin>>n>>T;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=2;i<=n;i++)
Update(1,1,MAX,min(a[i-1],a[i]),max(a[i-1],a[i]),1);
for(int i=2;i<n;i++)
Update(1,1,MAX,a[i],a[i],-1);
int type,pos,val;
while(T--)
{
cin>>type;
if(type==1)
{
cin>>pos>>val;
if(pos>1)
Update(1,1,MAX,min(a[pos-1],a[pos]),max(a[pos-1],a[pos]),-1);
if(pos<n)
Update(1,1,MAX,min(a[pos],a[pos+1]),max(a[pos],a[pos+1]),-1);
if(1<pos&&pos<n)
Update(1,1,MAX,a[pos],a[pos],1);
a[pos]=val;
if(pos>1)
Update(1,1,MAX,min(a[pos-1],a[pos]),max(a[pos-1],a[pos]),1);
if(pos<n)
Update(1,1,MAX,min(a[pos],a[pos+1]),max(a[pos],a[pos+1]),1);
if(1<pos&&pos<n)
Update(1,1,MAX,a[pos],a[pos],-1);
}
else
{
cin>>val;
cout<<Query(1,1,MAX,val)<<"\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
33816 KB |
Output is correct |
2 |
Correct |
6 ms |
33816 KB |
Output is correct |
3 |
Correct |
6 ms |
33816 KB |
Output is correct |
4 |
Correct |
6 ms |
33816 KB |
Output is correct |
5 |
Correct |
9 ms |
33816 KB |
Output is correct |
6 |
Correct |
0 ms |
33816 KB |
Output is correct |
7 |
Correct |
6 ms |
33816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
33816 KB |
Output is correct |
2 |
Correct |
6 ms |
33816 KB |
Output is correct |
3 |
Correct |
6 ms |
33816 KB |
Output is correct |
4 |
Correct |
6 ms |
33816 KB |
Output is correct |
5 |
Correct |
9 ms |
33816 KB |
Output is correct |
6 |
Correct |
0 ms |
33816 KB |
Output is correct |
7 |
Correct |
6 ms |
33816 KB |
Output is correct |
8 |
Runtime error |
223 ms |
33816 KB |
Execution timed out (wall clock limit exceeded) |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
33816 KB |
Output is correct |
2 |
Correct |
6 ms |
33816 KB |
Output is correct |
3 |
Correct |
6 ms |
33816 KB |
Output is correct |
4 |
Correct |
6 ms |
33816 KB |
Output is correct |
5 |
Correct |
9 ms |
33816 KB |
Output is correct |
6 |
Correct |
0 ms |
33816 KB |
Output is correct |
7 |
Correct |
6 ms |
33816 KB |
Output is correct |
8 |
Runtime error |
223 ms |
33816 KB |
Execution timed out (wall clock limit exceeded) |
9 |
Halted |
0 ms |
0 KB |
- |