Submission #549249

#TimeUsernameProblemLanguageResultExecution timeMemory
549249Vladth11Simple game (IZhO17_game)C++14
100 / 100
70 ms6816 KiB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "

using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;

const ll NMAX = 1000002;
const ll VMAX = 26;
const ll INF = (1LL << 55);
const ll MOD = 90000000000000001;
const ll BLOCK = 1000000;
const ll base = 1000000001;
const ll nr_of_bits = 18;

int aib[NMAX];

void update(int node, int x) {
    for(; node < NMAX; node += node&(-node))
        aib[node] += x;
}

int query(int node) {
    int x = 0;
    for(; node > 0; node -= node&(-node))
        x += aib[node];
    return x;
}

int v[NMAX];

void baga(int a, int b, int c){
    if(a > b) swap(a, b);
    update(a, c);
    update(b + 1, -c);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, i, m;
    cin >> n >> m;
    for(i = 1; i <= n; i++) {
        cin >> v[i];
        if(i > 1)
        baga(v[i], v[i - 1], 1);
    }
    for(i = 1; i <= m; i++) {
        int c;
        int l, r;
        cin >> c >> l;
        if(c == 2) {
            cout << query(l) << "\n";
        } else {
            cin >> r;
            if(l < n)
                baga(v[l], v[l + 1], -1);
            if(l > 1)
                baga(v[l - 1], v[l], -1);
            v[l] = r;
            if(l < n)
                baga(v[l], v[l + 1], 1);
            if(l > 1)
                baga(v[l - 1], v[l], 1);

        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...