Submission #486349

#TimeUsernameProblemLanguageResultExecution timeMemory
486349Sho10Simple game (IZhO17_game)C++17
100 / 100
80 ms11116 KiB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho #define ll long long #define double long double #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define aint(a) (a).begin(), (a).end() #define f first #define s second #define pb push_back #define mp make_pair #define pi pair #define rc(s) return cout<<s,0 #define endl '\n' #define mod 998244353 #define PI 3.14159265359 #define INF 1000000005 #define LINF 1000000000000000005ll #define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; ll n,m,h[100005],bit[1000005],mxx=1000000; void upd(ll pos,ll val){ for(;pos<=mxx;pos+=pos&(-pos)){ bit[pos]+=val; } } void update(ll x,ll y,ll val){ if(x>y){ swap(x,y); } upd(x,val); upd(y+1,-val); } ll query(ll pos){ ll res=0; for(;pos;pos-=pos&(-pos)){ res+=bit[pos]; } return res; } int32_t main(){ CODE_START; cin>>n>>m; for(ll i=1;i<=n;i++) { cin>>h[i]; if(i>=2){ update(h[i],h[i-1],1ll); } } while(m--){ ll type; cin>>type; if(type==2){ ll pos; cin>>pos; cout<<query(pos)<<endl; }else if(type==1){ ll pos,val; cin>>pos>>val; ll i=pos; if(pos>=2){ update(h[i],h[i-1],-1); } if(pos<n){ update(h[i],h[i+1],-1); } h[i]=val; if(pos>=2){ update(h[i],h[i-1],1); } if(pos<n){ update(h[i],h[i+1],1); } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...