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 NM = 1e5, LIM = 1e6;
int N, M, a[NM+5];
int bit[LIM+5];
void update(int x, int val){
while (x <= LIM){
bit[x] += val;
x += x & (-x);
}
}
int get(int x){
int res = 0;
while (x > 0){
res += bit[x];
x -= x & (-x);
}
return res;
}
void upd(int pos, int d){
if (pos > 1){
int l = min(a[pos], a[pos-1])+1, r = max(a[pos], a[pos-1])-1;
if (l <= r){
update(l, d);
update(r+1, -d);
}
}
if (pos < N){
int l = min(a[pos], a[pos+1])+1, r = max(a[pos], a[pos+1])-1;
if (l <= r){
update(l, d);
update(r+1, -d);
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++) cin >> a[i];
for (int i = 1; i < N; i++){
int l = min(a[i], a[i+1])+1, r = max(a[i], a[i+1])-1;
if (l <= r){
update(l, 1);
update(r+1, -1);
}
}
while (M--){
int type; cin >> type;
if (type == 1){
int pos, val; cin >> pos >> val;
upd(pos, -1);
a[pos] = val;
upd(pos, 1);
}
else{
int H; cin >> H;
cout << get(H) << '\n';
}
}
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... |