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;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define N 1000005
int fen[N];
void update(int x, int v){
while(x < N){
fen[x] += v;
x += x & -x;
}
}
int get(int x){
int s = 0;
while(x){
s += fen[x];
x -= x & -x;
}
return s;
}
int h[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin>>n>>m;
for(int i = 1; i <= n; ++i){
cin>>h[i];
}
for(int i = 2; i <= n; ++i){
update(min(h[i], h[i - 1]), 1);
update(max(h[i], h[i - 1]), -1);
}
while(m--){
int t;
cin>>t;
if(t == 2){
int a;
cin>>a;
cout<<get(a)<<'\n';
} else {
int i, x;
cin>>i>>x;
if(i != 1){
update(min(h[i], h[i - 1]), -1);
update(max(h[i], h[i - 1]), 1);
}
if(i != n){
update(min(h[i], h[i + 1]), -1);
update(max(h[i], h[i + 1]), 1);
}
h[i] = x;
if(i != 1){
update(min(h[i], h[i - 1]), 1);
update(max(h[i], h[i - 1]), -1);
}
if(i != n){
update(min(h[i], h[i + 1]), 1);
update(max(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... |