제출 #168166

#제출 시각아이디문제언어결과실행 시간메모리
168166muhammad_hokimiyonSimple game (IZhO17_game)C++14
100 / 100
79 ms7772 KiB
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

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

using namespace std;

const int N = 1e6 + 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...