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 <bits/stdc++.h>
#define ss second
#define ff first
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 1e6 + 123;
const int mod = 998244353;
const int inf = 1e9;
int wt;
int cnt[N * 4], h, x, y;
void upd(int v, int l, int r) {
if(x <= l && r <= y){
cnt[v] += wt;
return;
}
if(r < x || y < l)return;
int mid = l + (r - l) / 2;
upd(v * 2 + 1, l, mid), upd(v * 2 + 2, mid + 1, r);
}
int get(int v, int l, int r) {
if(l == r) {
return cnt[v];
}
int mid = l + (r - l) / 2;
if(h <= mid)return cnt[v] + get(v * 2 + 1, l, mid);
else return cnt[v] + get(v * 2 + 2, mid + 1, r);
}
void solve() {
int n, m;
cin >> n >> m;
int a[n];
wt = 1;
for(int i = 0; i < n; i++) {
cin >> a[i];
if(i){
x = a[i], y = a[i - 1];
if(x > y)swap(x, y);
upd(0, 0, N);
}
}
while(m--) {
int type;
cin >> type;
if(type == 1) {
int pos, val;
cin >> pos >> val;
wt = -1;
if(pos != n) {
x = a[pos - 1], y = a[pos];
if(x > y)swap(x, y);
upd(0, 0, N);
}
if(pos != 1) {
x = a[pos - 1], y = a[pos - 2];
if(x > y) swap(x, y);
upd(0, 0, N);
}
a[pos - 1] = val, wt = 1;
if(pos != n) {
x = a[pos - 1], y = a[pos];
if(x > y)swap(x, y);
upd(0, 0, N);
}
if(pos != 1) {
x = a[pos - 1], y = a[pos - 2];
if(x > y) swap(x, y);
upd(0, 0, N);
}
}
else {
cin >> h;
cout << get(0, 0, N) << '\n';
}
}
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
//cin >> t;
while(t--) {
solve();
}
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... |