이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+6;
const int MAXH=1e6+6;
int fen[MAXH];
void update(int idx,int val)
{
for(;idx<MAXH;idx+=idx&(-idx))
{
fen[idx]+=val;
}
}
void update_range(int l,int r,int val)
{
update(l,val);
update(r+1,-val);
}
int query(int idx)
{
int ret=0;
for(;idx>0;idx-=idx&(-idx))
{
ret+=fen[idx];
}
return ret;
}
int n,m;
int y[MAXN];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>y[i];
}
for(int i=2;i<=n;i++)
{
int l=y[i-1],r=y[i];
if(l>r)swap(l,r);
update_range(l,r,+1);
}
for(int i=0;i<m;i++)
{
int t;cin>>t;
if(t==1)
{
int pos,val;
cin>>pos>>val;
if(pos>1)
{
update_range(min(y[pos-1],y[pos]),max(y[pos-1],y[pos]),-1);
update_range(min(val,y[pos-1]),max(y[pos-1],val),+1);
}
if(pos<n)
{
update_range(min(y[pos+1],y[pos]),max(y[pos+1],y[pos]),-1);
update_range(min(val,y[pos+1]),max(y[pos+1],val),+1);
}
y[pos]=val;
}
else
{
int h;
cin>>h;
cout<<query(h)<<endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |