이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAX = 1000000;
int h[MAX+5];
int bit[MAX+5];
void upd(int x, int val){
while(x <= MAX+1){
bit[x] += val;
x += x & -x;
}
}
int query(int x){
int res = 0;
while(x){
res += bit[x];
x -= x & -x;
}
return res;
}
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(min(h[i-1], h[i]), 1);
upd(max(h[i-1], h[i])+1, -1);
}
while(m--){
int t;
cin >> t;
if(t == 1){
int i, y;
cin >> i >> y;
if(i > 1){
upd(min(h[i-1], h[i]), -1);
upd(max(h[i-1], h[i])+1, 1);
}
if(i < n){
upd(min(h[i+1], h[i]), -1);
upd(max(h[i+1], h[i])+1, 1);
}
h[i] = y;
if(i > 1){
upd(min(h[i-1], h[i]), 1);
upd(max(h[i-1], h[i])+1, -1);
}
if(i < n){
upd(min(h[i+1], h[i]), 1);
upd(max(h[i+1], h[i])+1, -1);
}
}
else{
int y;
cin >> y;
cout << query(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... |