// In the Name of God
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)
#define itr iterator
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define ub upper_bound
#define lb lower_bound
const int N = 1e5 + 5;
const int mod = 1e8 + 7;
const int inf = 1e6 + 1;
const double eps = 1e-15;
const int pw = 257;
int n, m, a[N], t[inf * 4];
void upd(int v, int l, int r, int L, int R, int val) {
if (L > R)
swap(L, R);
if (L > r || l > R)
return;
if (L <= l && r <= R) {
t[v] += val;
return;
}
int mid = (l + r) >> 1;
upd(v + v, l, mid, L, R, val);
upd(v + v + 1, mid + 1, r, L, R, val);
}
int get(int v, int l, int r, int pos) {
if (l == r)
return t[v];
int mid = (l + r) >> 1;
if (pos <= mid)
return t[v] + get(v + v, l, mid, pos);
else
return t[v] + get(v + v + 1, mid + 1, r, pos);
}
int main() {
#ifdef Madi
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
ios_base :: sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m;
rep(i, 1, n) {
cin >> a[i];
if (i > 1)
upd(1, 1, inf, a[i - 1], a[i], 1);
}
rep(i, 1, m) {
int type;
cin >> type;
if (type == 1) {
int pos, val;
cin >> pos >> val;
if (pos > 1)
upd(1, 1, inf, a[pos - 1], a[pos], -1);
if (pos < n)
upd(1, 1, inf, a[pos + 1], a[pos], -1);
a[pos] = val;
if (pos > 1)
upd(1, 1, inf, a[pos - 1], a[pos], 1);
if (pos < n)
upd(1, 1, inf, a[pos + 1], a[pos], 1);
}
else {
int x;
cin >> x;
cout << get(1, 1, inf, x) << "\n";
}
}
#ifdef Madi
cerr << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
6648 KB |
Output is correct |
3 |
Correct |
8 ms |
6392 KB |
Output is correct |
4 |
Correct |
8 ms |
6648 KB |
Output is correct |
5 |
Correct |
8 ms |
6648 KB |
Output is correct |
6 |
Correct |
8 ms |
6520 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
6648 KB |
Output is correct |
3 |
Correct |
8 ms |
6392 KB |
Output is correct |
4 |
Correct |
8 ms |
6648 KB |
Output is correct |
5 |
Correct |
8 ms |
6648 KB |
Output is correct |
6 |
Correct |
8 ms |
6520 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
41 ms |
1756 KB |
Output is correct |
9 |
Correct |
113 ms |
11128 KB |
Output is correct |
10 |
Correct |
103 ms |
11288 KB |
Output is correct |
11 |
Correct |
36 ms |
1528 KB |
Output is correct |
12 |
Correct |
66 ms |
3064 KB |
Output is correct |
13 |
Correct |
56 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
6648 KB |
Output is correct |
3 |
Correct |
8 ms |
6392 KB |
Output is correct |
4 |
Correct |
8 ms |
6648 KB |
Output is correct |
5 |
Correct |
8 ms |
6648 KB |
Output is correct |
6 |
Correct |
8 ms |
6520 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
41 ms |
1756 KB |
Output is correct |
9 |
Correct |
113 ms |
11128 KB |
Output is correct |
10 |
Correct |
103 ms |
11288 KB |
Output is correct |
11 |
Correct |
36 ms |
1528 KB |
Output is correct |
12 |
Correct |
66 ms |
3064 KB |
Output is correct |
13 |
Correct |
56 ms |
2808 KB |
Output is correct |
14 |
Correct |
179 ms |
11148 KB |
Output is correct |
15 |
Correct |
191 ms |
11388 KB |
Output is correct |
16 |
Correct |
197 ms |
11128 KB |
Output is correct |
17 |
Correct |
200 ms |
11132 KB |
Output is correct |
18 |
Correct |
183 ms |
11256 KB |
Output is correct |