Submission #92516

#TimeUsernameProblemLanguageResultExecution timeMemory
92516RandooomSimple game (IZhO17_game)C++14
100 / 100
281 ms11384 KiB
#include <bits/stdc++.h>
#define in freopen ("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long int

const int val = (1e6) + 2;
const int inf = (1e6);
double eps = 0.000000001;

using namespace std;

int t[4000005], a[100005];

void update(int v, int tl, int tr, int l, int r, int val){
    if(l > r) return;
    if(tl == l && tr == r) t[v] += val;
    else{
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), val);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, val);
    }
}

int get(int v, int l, int r, int pos){
    if(l == r) return t[v];
    int m = (l + r) / 2;
    if(pos <= m) return t[v] + get(v*2, l, m, pos);
    else return t[v] + get(v*2+1, m+1, r, pos);
}

int solve(){
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; ++i){
        cin >> a[i];
    }
    for(int i=1; i<n; ++i){
        int l = min(a[i], a[i+1]);
        int r = max(a[i], a[i+1]);
        update(1, 1, inf, l, r, 1);
    }
    for(int i=1; i<=m; ++i){
        int q, x, y;
        cin >> q;
        if(q == 1){
            cin >> x >> y;
            if(x > 1){
                int l = min(a[x-1], a[x]);
                int r = max(a[x-1], a[x]);
                update(1, 1, inf, l, r, -1);
            }
            if(x < n){
                int l = min(a[x+1], a[x]);
                int r = max(a[x+1], a[x]);
                update(1, 1, inf, l, r, -1);
            }
            a[x] = y;
            if(x > 1){
                int l = min(a[x-1], a[x]);
                int r = max(a[x-1], a[x]);
                update(1, 1, inf, l, r, 1);
            }
            if(x < n){
                int l = min(a[x+1], a[x]);
                int r = max(a[x+1], a[x]);
                update(1, 1, inf, l, r, 1);
            }
        }
        else{
            cin >> x;
            cout << get(1, 1, inf, x) << endl;
        }
    }
}

int main(){
    //in out
	ios_base::sync_with_stdio(0);
    solve();
    return 0;
}

Compilation message (stderr)

game.cpp: In function 'int solve()':
game.cpp:74:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...