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 <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <bitset>
#include <vector>
typedef long long llong;
const int MAXN = 100000 + 10;
const int MAXT = 1000000 + 10;
int n, q;
struct Fenwick
{
    int tree[MAXT];
    void update(int pos, int val)
    {
        for (int idx = pos ; idx < MAXT ; idx += idx & (-idx))
        {
            tree[idx] += val;
        }
    }
    int query(int t)
    {
        int res = 0;
        for (int idx = t ; idx > 0 ; idx -= idx & (-idx))
        {
            res += tree[idx];
        }
        return res;
    }
};
int a[MAXN];
Fenwick tree;
void add(int idx)
{
    int min = std::min(a[idx], a[idx + 1]);
    int max = std::max(a[idx], a[idx + 1]);
    tree.update(min + 1, 1);
    tree.update(max + 1, -1);
}
void remove(int idx)
{
    int min = std::min(a[idx], a[idx + 1]);
    int max = std::max(a[idx], a[idx + 1]);
    tree.update(min + 1, -1);
    tree.update(max + 1, 1);
}
void solve()
{
    for (int i = 1 ; i < n ; ++i)
    {
        add(i);
    }
    for (int i = 1 ; i <= n ; ++i)
    {
        int qType, pos, val;
        std::cin >> qType;
        if (qType == 1)
        {
            std::cin >> pos >> val;
            
            if (pos < n) remove(pos);
            if (pos > 1) remove(pos - 1);
            
            a[pos] = val;
            if (pos < n) add(pos);
            if (pos > 1) add(pos - 1);
        } else
        {
            std::cin >> val;
            std::cout << tree.query(val) << '\n';
        }
    }
}
void input()
{
    std::cin >> n >> q;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i];
    }
}
void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}
int main()
{
    fastIOI();
    input();
    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... |