Submission #1215732

#TimeUsernameProblemLanguageResultExecution timeMemory
1215732M_SH_OSimple game (IZhO17_game)C++20
49 / 100
265 ms247260 KiB
#include <bits/stdc++.h>
//#include "grader.h"
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/

#define ll long long
#define ll1 long long
#define ull unsigned long long
#define dou long double
#define str string
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vbool vector<bool>
#define vstr vector<str>
#define vvll vector<vll>
#define pb push_back
#define pf push_front
#define endl "\n"
#define fr first
#define se second
// #define sortcmp(a) sort(a.begin(), a.end(), cmp)
#define sort(a) sort(a.begin(), a.end())
#define all(a) a.begin(), a.end()
#define reverse(a) reverse(a.begin(), a.end())
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 1000000000000000000
#define ordered_set tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
//using namespace __gnu_pbds;

mt19937 rng(1488);
ll randll(ll l, ll r){
    return uniform_int_distribution<ll>(l, r)(rng);
}

/*vector<map<ll, vll>> s;
vll p;

ll find(ll v) {
    if (p[v] == v) return v;
    return p[v] = find(p[v]);
}

void unite(ll a, ll b) {
    a = find(a);
    b = find(b);

    if (a == b) return;
    if (s[a].size() < s[b].size()) {
        p[a] = b;
        for (auto i : s[a]) {
            for (int j : i.se) {
                s[b][i.fr].pb(j);
            }
        }
        s[a].clear();
    }
    else {
        p[b] = a;
        for (auto i : s[b]) {
            for (int j : i.se) {
                s[a][i.fr].pb(j);
            }
        }
        s[b].clear();
    }
}

vll tree1;

void bt(ll v, ll tl, ll tr, vll& a) {
    if (tl == tr) {
        tree1[v] = a[tl];
        return;
    }

    ll tm = (tl+tr)/2;
    bt(v*2, tl, tm, a);
    bt(v*2, tm+1, tr, a);

    tree1[v] = tree1[v*2]+tree1[v*2+1];
}

ll get(ll l, ll r, ll v, ll tl, ll tr) {
    if (l <= tl && tr <= r) return tree1[v];
    if (tl > r || tr < l) return 0;

    ll tm = (tl+tr)/2;
    return get(l, r, v*2, tl, tm)+get(l, r, v*2+1, tm+1, tr);
}

void update(ll idx, ll val, ll v, ll tl, ll tr) {
    if (tl == tr) {
        tree1[v] = val;
        return;
    }

    ll tm = (tl+tr)/2;

    if (idx <= tm) update(idx, val, v*2, tl, tm);
    else update(idx, val, v*2+1, tm+1, tr);

    tree1[v] = tree1[v*2]+tree1[v*2+1];
}*/

int main() {

    ll n, q;
    cin >> n >> q;
    vll a(n), res(1000007, 0);
    vvll m(10000007);
    for (int i =0 ; i < n; i ++) {
        cin >> a[i];
        m[a[i]].pb(i);
    }

    if (n == 1) {
        while (q --) {
            ll x;
            cin >> x;
            if (x == 1) {
                ll pos, val;
                cin >> pos >> val;
                pos --;
                a[pos] = val;
            }
            else {
                ll k;
                cin >> k;
                if (k == a[0]) cout << 1 << endl;
                else cout << 0 << endl;
            }
        }
        return 0;
    }

    ll res1 = 0;

    for (int i = 1; i <= 1000000; i ++) {
        for (int j : m[i]) {
            if (j == 0) {
                if (a[j+1] >= i) res1 ++;
                continue;
            }
            if (j == n-1) {
                if (a[j-1] >= i) res1 ++;
                continue;
            }
            if (a[j-1] >= i && a[j+1] >= i) res1 ++;
            if (a[j-1] < i && a[j+1] < i) res1 --;
        }
        res[i] = res1;
        for (int j : m[i]) {
            res1 --;
            if (j == 0) {
                if (a[j+1] > i) res1 ++;
                continue;
            }
            if (j == n-1) {
                if (a[j-1] > i) res1 ++;
                continue;
            }
            if (a[j-1] > i && a[j+1] > i) res1 += 2;
            else if (a[j-1] > i || a[j+1] > i) res1 ++;
        }
    }


    while (q --) {
        ll x;
        cin >> x;
        if (x == 1) {
            ll pos, val;
            cin >> pos >> val;
            pos --;
            a[pos] = val;
        }
        else {
            ll k;
            cin >> k;

            if (n > 1000 || q > 1000) {
                cout << res[k] << endl;
                continue;
            }

            ll q = -1;
            ll res = 0;
            for (int i = 0; i < n; i ++) {
                if (a[i] == k) {
                    res ++;
                    q = -1;
                    continue;
                }
                if (a[i] < k) {
                    if (q == 0) res ++;
                    q = 1;
                    continue;
                }
                if (q == 1) res ++;
                q = 0;
            }

            cout << res << endl;
        }
    }
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...