This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//I wrote this code 4 u <3
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
const int maxN = (int) 1e6 + 1e3;
template<typename T>
struct Bit { // [l, r)
    vector<T> t;
    int sz;
    Bit(int n) : t(n + 1), sz(n) {}
    void upd(int i, int val) {
        for (++i; i <= sz; i += i & -i) {
            t[i] += val;
        }
    }
    T get(int x) {
        ll ret = 0;
        for (; x; x -= x & -x) {
            ret += t[x];
        }
        return ret;
    }
    T get(int l, int r) {
        return get(r) - get(l);
    }
};
signed main(int32_t argc, char *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    Bit<int> bit(maxN);
    auto add = [&](int l, int r, int v) {
        if (l > r) {
            swap(l, r);
        }
        bit.upd(l, v);
        bit.upd(r + 1, -v);
    };
    for (int i = 0; i < n - 1; ++i) {
        add(a[i], a[i + 1], 1);
    }
    while (m--) {
        int t;
        cin >> t;
        if (t == 1) {
            int i, v;
            cin >> i >> v;
            --i;
            if (i > 0) {
                add(a[i], a[i - 1], -1);
                add(v, a[i - 1], 1);
            }
            if (i < n - 1) {
                add(a[i], a[i + 1], -1);
                add(v, a[i + 1], 1);
            }
            a[i] = v;
        } else {
            int h;
            cin >> h;
            cout << bit.get(h + 1) << '\n';
        }
    }
}
/*
 */
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |