이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 3e2;
int f[MAXN];
void add(int i, int x){
while (i < MAXN){
f[i] += x;
i += (-i & i);
}
}
void add(int l, int r, int x){
if (l > r) swap(l, r);
add(l, x);
add(r + 1, -x);
}
int get(int i){
int res = 0;
while (i > 0){
res += f[i];
i -= (-i & i);
}
return res;
}
int a[MAXN];
int main(){
ios_base::sync_with_stdio(false);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++){
cin >> a[i];
if (i > 1) add(a[i - 1], a[i], 1);
}
while (q--){
int t;
cin >> t;
if (t == 1){
int i, x;
cin >> i >> x;
if (i > 1){
add(a[i - 1], a[i], -1);
add(a[i - 1], x, 1);
}
if (i < n){
add(a[i], a[i + 1], -1);
add(x, a[i + 1], 1);
}
a[i] = x;
} else {
int h;
cin >> h;
cout << get(h) << endl;
}
}
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... |