Submission #170258

#TimeUsernameProblemLanguageResultExecution timeMemory
170258nvmdavaSimple game (IZhO17_game)C++17
100 / 100
91 ms7032 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define N 1000005

int fen[N];

void update(int x, int v){
    while(x < N){
        fen[x] += v;
        x += x & -x;
    }
}

int get(int x){
    int s = 0;
    while(x){
        s += fen[x];
        x -= x & -x;
    }
    return s;
}

int h[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin>>n>>m;

    for(int i = 1; i <= n; ++i){
        cin>>h[i];
    }
    for(int i = 2; i <= n; ++i){
        update(min(h[i], h[i - 1]), 1);
        update(max(h[i], h[i - 1]), -1);
    }
    while(m--){
        int t;
        cin>>t;
        if(t == 2){
            int a;
            cin>>a;
            cout<<get(a)<<'\n';
        } else {
            int i, x;
            cin>>i>>x;
            if(i != 1){
                update(min(h[i], h[i - 1]), -1);
                update(max(h[i], h[i - 1]), 1);
            }
            if(i != n){
                update(min(h[i], h[i + 1]), -1);
                update(max(h[i], h[i + 1]), 1);
            }
            h[i] = x;
            if(i != 1){
                update(min(h[i], h[i - 1]), 1);
                update(max(h[i], h[i - 1]), -1);
            }
            if(i != n){
                update(min(h[i], h[i + 1]), 1);
                update(max(h[i], h[i + 1]), -1);
            }
        }
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...