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 <algorithm>
#include <vector>
using namespace std;
const int N = 1'000'002;
const int H = 1'000'000;
int a[N], t[4 * N];
void Upd (int v, int vl, int vr, int l, int r, int val)
{
if (vl == l && r == vr)
{
t[v] += val;
return;
}
int m = (vl + vr) / 2;
if (l <= m)
Upd (v * 2, vl, m, l, min (r, m), val);
if (r > m)
Upd (v * 2 + 1, m + 1, vr, max (m + 1, l), r, val);
}
int Get (int v, int vl, int vr, int pos)
{
if (vl == vr)
return t[v];
int m = (vl + vr) / 2;
if (pos <= m)
return t[v] + Get (v * 2, vl, m, pos);
return t[v] + Get (v * 2 + 1, m + 1, vr, pos);
}
int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
{
cin >> a[i];
if (i != 0)
{
Upd (1, 1, H, min (a[i - 1], a[i]), max (a[i - 1], a[i]), 1);
}
}
while (m--)
{
int type;
cin >> type;
if (type == 1)
{
int pos, val;
cin >> pos >> val;
pos--;
if (pos != 0)
{
Upd (1, 1, H, min (a[pos - 1], a[pos]), max (a[pos - 1], a[pos]), -1);
Upd (1, 1, H, min (a[pos - 1], val), max (a[pos - 1], val), 1);
}
if (pos != n - 1)
{
Upd (1, 1, H, min (a[pos + 1], a[pos]), max (a[pos + 1], a[pos]), -1);
Upd (1, 1, H, min (a[pos + 1], val), max (a[pos + 1], val), 1);
}
a[pos] = val;
}
else
{
int h;
cin >> h;
cout << Get (1, 1, H, 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... |