#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
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);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
33656 KB |
Output is correct |
2 |
Correct |
3 ms |
33656 KB |
Output is correct |
3 |
Correct |
6 ms |
33656 KB |
Output is correct |
4 |
Correct |
3 ms |
33656 KB |
Output is correct |
5 |
Correct |
9 ms |
33656 KB |
Output is correct |
6 |
Correct |
6 ms |
33656 KB |
Output is correct |
7 |
Correct |
3 ms |
33656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
33656 KB |
Output is correct |
2 |
Correct |
3 ms |
33656 KB |
Output is correct |
3 |
Correct |
6 ms |
33656 KB |
Output is correct |
4 |
Correct |
3 ms |
33656 KB |
Output is correct |
5 |
Correct |
9 ms |
33656 KB |
Output is correct |
6 |
Correct |
6 ms |
33656 KB |
Output is correct |
7 |
Correct |
3 ms |
33656 KB |
Output is correct |
8 |
Correct |
126 ms |
33656 KB |
Output is correct |
9 |
Correct |
289 ms |
33656 KB |
Output is correct |
10 |
Correct |
293 ms |
33656 KB |
Output is correct |
11 |
Correct |
109 ms |
33656 KB |
Output is correct |
12 |
Correct |
143 ms |
33656 KB |
Output is correct |
13 |
Correct |
123 ms |
33656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
33656 KB |
Output is correct |
2 |
Correct |
3 ms |
33656 KB |
Output is correct |
3 |
Correct |
6 ms |
33656 KB |
Output is correct |
4 |
Correct |
3 ms |
33656 KB |
Output is correct |
5 |
Correct |
9 ms |
33656 KB |
Output is correct |
6 |
Correct |
6 ms |
33656 KB |
Output is correct |
7 |
Correct |
3 ms |
33656 KB |
Output is correct |
8 |
Correct |
126 ms |
33656 KB |
Output is correct |
9 |
Correct |
289 ms |
33656 KB |
Output is correct |
10 |
Correct |
293 ms |
33656 KB |
Output is correct |
11 |
Correct |
109 ms |
33656 KB |
Output is correct |
12 |
Correct |
143 ms |
33656 KB |
Output is correct |
13 |
Correct |
123 ms |
33656 KB |
Output is correct |
14 |
Correct |
429 ms |
33656 KB |
Output is correct |
15 |
Correct |
423 ms |
33656 KB |
Output is correct |
16 |
Correct |
429 ms |
33656 KB |
Output is correct |
17 |
Correct |
469 ms |
33656 KB |
Output is correct |
18 |
Correct |
466 ms |
33656 KB |
Output is correct |