Submission #1362125

#TimeUsernameProblemLanguageResultExecution timeMemory
1362125iamhereforfunSimple game (IZhO17_game)C++20
100 / 100
33 ms9564 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))
#define int long long

const int N = 2e5 + 5;
const int M = 1e6 + 5;
const int B = 18;
const long long K = 2;
const int LG = 20;
const int INF = 1e18 + 5;
const int P = 31;
const int MOD = 1e9 + 7;
const int nx[] = {0, 1, 0, -1}, ny[] = {-1, 0, 1, 0};

struct Fenwick
{
    vector<int> ft;
    int n;
    Fenwick(int len)
    {
        n = len;
        ft.assign(n + 1, 0);
    }
    void update(int pos, int val)
    {
        while (pos <= n)
        {
            ft[pos] += val;
            pos += LSOne(pos);
        }
    }
    int get(int pos)
    {
        int sum = 0;
        while (pos > 0)
        {
            sum += ft[pos];
            pos -= LSOne(pos);
        }
        return sum;
    }
    int get(int l, int r)
    {
        return get(r) - get(l - 1);
    }
} ft(M);

int n, m, h[N];

void update(int a, int b, int t)
{
    if (a > b)
        swap(a, b);
    ft.update(a, t);
    ft.update(b + 1, -t);
}

inline void solve()
{
    cin >> n >> m;
    for (int x = 0; x < n; x++)
    {
        cin >> h[x];
    }
    for (int x = 0; x < n - 1; x++)
    {
        update(h[x], h[x + 1], 1);
    }
    for (int x = 0; x < m; x++)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int p, v;
            cin >> p >> v;
            p--;
            if (p > 0)
            {
                update(h[p], h[p - 1], -1);
                update(v, h[p - 1], 1);
            }
            if (p < n - 1)
            {
                update(h[p], h[p + 1], -1);
                update(v, h[p + 1], 1);
            }
            h[p] = v;
        }
        else
        {
            int i;
            cin >> i;
            cout << ft.get(i) << "\n";
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...