#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define info() cerr << __PRETTY_FUNCTION__ << ": " << __LINE__ << endl
#define test(args...) info(), abc("[" + string(#args) + "]", args)
void abc() {cerr << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cerr << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
const int N = 100087, logN = 20, K = 111;
int bit[N];
void add(int p, int v) {
p += 5;
for (int i = p; i < N; i += i & (-i)) bit[i] += v;
}
int query(int p) {
p += 5;
int ans = 0;
for (int i = p; i > 0; i -= i & (-i)) ans += bit[i];
return ans;
}
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector <int> a(n);
auto chg = [&](int i, int v) {
if (i - 1 < 0 || i >= n) return;
int mn = min(a[i - 1], a[i]), mx = max(a[i - 1], a[i]);
add(mn + 1, v);
add(mx, -v);
};
for (int i = 0; i < n; ++i) {
cin >> a[i];
chg(i, 1);
}
while (q--) {
int t, p, x;
cin >> t >> p;
if (t == 1) {
cin >> x, --p;
chg(p, -1);
chg(p + 1, -1);
a[p] = x;
chg(p, 1);
chg(p + 1, 1);
} else {
cout << query(p) << endl;
}
}
}
/*
3 3
1 5 1
2 3
1 1 5
2 3
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Runtime error |
2 ms |
1100 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Runtime error |
2 ms |
1100 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Runtime error |
2 ms |
1100 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |