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<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 1000004;
int t[4 * N], mod[4 * N];
void push(int v, int l, int r) {
if (l == r) {
mod[v] = 0;
return;
}
mod[2 * v] += mod[v];
mod[2 * v + 1] += mod[v];
t[2 * v] += mod[v];
t[2 * v + 1] += mod[v];
mod[v] = 0;
return;
}
void upd(int v, int tl, int tr, int l, int r, int x) {
push(v, tl, tr);
if (tl > tr || l > r) return;
if (tl == l && tr == r) {
mod[v] += x;
t[v] += x;
return;
}
int tm = (tl + tr) >> 1;
upd(2 * v, tl, tm, l, min(r, tm), x);
upd(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, x);
}
int getelem(int v, int tl, int tr, int pos) {
push(v, tl, tr);
if (tl == tr) {
return t[v];
}
int tm = (tl + tr) >> 1;
if (pos <= tm) {
return getelem(2 * v, tl, tm, pos);
}
return getelem(2 * v + 1, tm + 1, tr, pos);
}
int main() {
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n - 1; ++i) {
upd(1, 0, N - 1, min(a[i], a[i + 1]), max(a[i], a[i + 1]), 1);
}
while (q--) {
int type;
cin >> type;
if (type == 2) {
int H;
cin >> H;
cout << getelem(1, 0, N - 1, H) << '\n';
}
else {
int pos, val;
cin >> pos >> val;
--pos;
if (pos) {
upd(1, 0, N - 1, min(a[pos - 1], a[pos]), max(a[pos - 1], a[pos]), -1);
}
if (pos + 1 < n) {
upd(1, 0, N - 1, min(a[pos + 1], a[pos]), max(a[pos + 1], a[pos]), -1);
}
a[pos] = val;
if (pos) {
upd(1, 0, N - 1, min(a[pos - 1], a[pos]), max(a[pos - 1], a[pos]), 1);
}
if (pos + 1 < n) {
upd(1, 0, N - 1, min(a[pos + 1], a[pos]), max(a[pos + 1], a[pos]), 1);
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |