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> //Andrei Alexandru a.k.a Sho
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 998244353
#define PI 3.14159265359
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m,h[100005],bit[100005],mxx=100000;
void upd(ll pos,ll val){
for(;pos<=mxx;pos+=pos&(-pos)){
bit[pos]+=val;
}
}
void update(ll x,ll y,ll val){
if(x>y){
swap(x,y);
}
upd(x,val);
upd(y+1,-val);
}
ll query(ll pos){
ll res=0;
for(;pos;pos-=pos&(-pos)){
res+=bit[pos];
}
return res;
}
int32_t main(){
CODE_START;
cin>>n>>m;
for(ll i=1;i<=n;i++)
{
cin>>h[i];
if(i>=2){
update(h[i],h[i-1],1ll);
}
}
while(m--){
ll type;
cin>>type;
if(type==2){
ll pos;
cin>>pos;
cout<<query(pos)<<endl;
}else if(type==1){
ll pos,val;
cin>>pos>>val;
ll i=pos;
if(pos>=2){
update(h[i],h[i-1],-1);
}
if(pos<n){
update(h[i],h[i+1],-1);
}
h[i]=val;
if(pos>=2){
update(h[i],h[i-1],1);
}
if(pos<n){
update(h[i],h[i+1],1);
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |