Submission #168165

# Submission time Handle Problem Language Result Execution time Memory
168165 2019-12-11T17:38:49 Z muhammad_hokimiyon Simple game (IZhO17_game) C++14
0 / 100
3 ms 1272 KB
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long

using namespace std;

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

int n,q;
int a[N];
int t[N];
int l[N];
int r[N];

void upd( int x , int g )
{
    while( x < N ){
        t[x] += g;
        x += x & -x;
    }
}

int get( int x )
{
    int res = 0;
    while( x > 0 ){
        res += t[x];
        x -= x & -x;
    }
    return res;
}

void solve()
{
    cin >> n >> q;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i];
    }
    for( int i = 1; i < n; i++ ){
        l[i] = min(a[i] , a[i + 1]);
        r[i] = max(a[i] , a[i + 1]) + 1;
        upd(l[i] , 1);
        upd(r[i] , -1);
    }
    for( int i = 1; i <= q; i++ ){
        int tp;
        cin >> tp;
        if( tp == 1 ){
            int x , y;
            cin >> x >> y;
            if( x < n ){
                upd(l[x] , -1);
                upd(r[x] , 1);
            }
            if( x > 1 ){
                upd(l[x - 1] , -1);
                upd(r[x - 1], 1);
            }
            a[x] = y;
            if( x < n ){
                l[x] = min(a[x] , a[x + 1]);
                r[x] = max(a[x] , a[x + 1]) + 1;
                upd(l[x] , 1);
                upd(r[x] , -1);
            }
            if( x > 1 ){
                l[x - 1] = min(a[x] , a[x - 1]);
                r[x - 1] = max(a[x] , a[x - 1]) + 1;
                upd(l[x - 1] , 1);
                upd(r[x - 1] , -1);
            }
        }
        else{
            int h;
            cin >> h;
            cout << get(h) << "\n";
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int t = 1;//cin >> t;
    while( t-- ){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 3 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 3 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 3 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -