이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e5 + 5, M = 1e6 + 5;
int n, m;
int a[N], s[M];
void upd(int i, int x) {
for (; i < M; i += i & -i) {
s[i] += x;
}
}
int qry(int i) {
int res = 0;
for (; i; i -= i & -i) {
res += s[i];
}
return res;
}
void add(int u, int v, int x) {
upd(min(u, v), x);
upd(max(u, v) + 1, -x);
}
void chg(int i, int v) {
if (i < n) {
add(a[i], a[i + 1], -1);
}
if (i > 1) {
add(a[i], a[i - 1], -1);
}
a[i] = v;
if (i < n) {
add(a[i], a[i + 1], 1);
}
if (i > 1) {
add(a[i], a[i - 1], 1);
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (i > 1) {
add(a[i], a[i - 1], 1);
}
}
while (m--) {
int t; cin >> t;
if (t == 1) {
int p, v; cin >> p >> v;
chg(p, v);
} else {
int h; cin >> h;
cout << qry(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... |