Submission #1128686

#TimeUsernameProblemLanguageResultExecution timeMemory
1128686VietnowSimple game (IZhO17_game)C++20
0 / 100
2 ms324 KiB
#include <bits/stdc++.h>
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define int long long
#define ff first
#define ss second
#define pb push_back
#define y1 zildjian
#define left radio
#define right head
 
using namespace std;
 
const int N = 1e6+1;
const int INF = 1e18;
const int mod = 1e9+7;
const int mod1 = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int t[N*4];
int lazy[N*4];

void push(int v, int tl, int tr){
    if(lazy[v]){
        t[v] += (tr-tl+1)*lazy[v];
        if(tl!=tr){
            lazy[v*2] += lazy[v];
            lazy[v*2+1] += lazy[v];
        }
        lazy[v] = 0;
    }
}

void upd(int v, int tl, int tr, int l, int r){
    push(v,tl,tr);
    if(tl>=l && tr<=r){
        lazy[v]++;
        push(v,tl,tr);
        return;
    }
    if(tl<r || tr>l) return;
    int m = (tl+tr)/2;
    upd(v*2,tl,m,l,r);
    upd(v*2+1,m+1,tr,l,r);
    t[v] = t[v*2]+t[v*2+1];
}

int get(int v, int tl, int tr, int x){
    push(v,tl,tr);
    if(tl == tr){
        return t[v];
    }
    int m = (tl+tr)/2;
    if(x<=m) return get(v*2,tl,m,x);
    return get(v*2+1,m+1,tr,x);
}

int n,m;
int h[N];

void solve(){
    cin>>n>>m;
    int mx = 0;
    for(int i = 1;i<=n;i++){
        cin>>h[i];
        mx = max(mx,h[i]);
    }
    for(int i = 1;i<n;i++){
        upd(1,1,mx,min(h[i],h[i+1]),max(h[i],h[i+1]));
    }
    // 1 1 1 1 1
    bool changed = 0;
    while(m--){
        int t;
        cin>>t;
        if(t == 1){
            int pos,val;
            cin>>pos>>val;
            h[pos] = val;
            changed = 1;
        }
        else{
            int x;
            cin>>x;
            if(changed){
                int ans = 0;
                for(int i = 1;i<n;i++){
                    if(x>h[i] && x < h[i+1]) ans++;
                    if(x<h[i] && x>h[i+1]) ans++;
                }
                cout<<ans<<'\n';
            }
            else{
                cout<<get(1,1,mx,x)<<'\n';
            }
        }
    }
}


signed main(){
    // freopen("bootfall.in","r",stdin); 
    // freopen("bootfall.out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    int t = 1;
    // cin>>t;
    for(int i = 1;i<=t;i++){
        // cout<<"Case "<<i<<": ";
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...