This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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()
{
//freopen("TEST.INP","r",stdin);
scanf("%d%d",&n,&T);
for(int i=1;i<=n;i++)
scanf("%d",&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--)
{
scanf("%d",&type);
if(type==1)
{
scanf("%d%d",&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
{
scanf("%d",&val);
printf("%d\n",Query(1,1,MAX,val));
}
}
}
Compilation message (stderr)
game.cpp: In function 'int main()':
game.cpp:46:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&T);
^
game.cpp:48:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
^
game.cpp:56:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&type);
^
game.cpp:59:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&pos,&val);
^
game.cpp:76:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&val);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |