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;
typedef long long ll;
typedef long double ld;
const int MAX = 1000000;
int h[MAX+5];
int seg[4*MAX+5];
void upd(int node, int l, int r, int tl, int tr, int val){
if(l > tr || tl > r) return;
if(tl <= l && r <= tr){
seg[node] += val;
return;
}
int mid = (l+r)/2;
upd(node*2, l, mid, tl, tr, val);
upd(node*2+1, mid+1, r, tl, tr, val);
}
int query(int node, int l, int r, int x){
if(l == r) return seg[node];
int mid = (l+r)/2;
if(x <= mid) return seg[node] + query(node*2, l, mid, x);
return seg[node] + query(node*2+1, mid+1, r, x);
}
int main(){
ios_base::sync_with_stdio(false);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
for(int i=1; i<=n; i++){
cin >> h[i];
}
for(int i=2; i<=n; i++){
upd(1, 1, MAX, min(h[i-1], h[i]), max(h[i-1], h[i]), 1);
}
while(m--){
int t;
cin >> t;
if(t == 1){
int i, y;
cin >> i >> y;
if(i > 1) upd(1, 1, MAX, min(h[i-1], h[i]), max(h[i-1], h[i]), -1);
if(i < n) upd(1, 1, MAX, min(h[i+1], h[i]), max(h[i+1], h[i]), -1);
h[i] = y;
if(i > 1) upd(1, 1, MAX, min(h[i-1], h[i]), max(h[i-1], h[i]), 1);
if(i < n) upd(1, 1, MAX, min(h[i+1], h[i]), max(h[i+1], h[i]), 1);
}
else{
int y;
cin >> y;
cout << query(1, 1, MAX, y) << "\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... |