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 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... |