Submission #494945

#TimeUsernameProblemLanguageResultExecution timeMemory
494945Ronin13Simple game (IZhO17_game)C++14
100 / 100
60 ms6812 KiB
#include<bits/stdc++.h> #define ll long long #define ull unsigned ll #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back #define inf 1e9+1 #define linf 1e18+1 using namespace std; const int NMAX=1e6+1; vector<int>fen(NMAX); int lsb(int x){ return x&-x; } int n; void add(int pos,int val){ while(pos<=n){ fen[pos]+=val; pos+=lsb(pos); } } int sum(int pos){ int ss=0; while(pos){ ss+=fen[pos]; pos-=lsb(pos); } return ss; } void solve(){ n=1e6; int m;cin>>m; int q;cin>>q; int h[m+1]; for(int i=1;i<=m;i++){ cin>>h[i]; } for(int i=2;i<=m;i++){ int r=max(h[i],h[i-1]); int l=min(h[i],h[i-1]); add(l,1); if(r!=1e6)add(r+1,-1); } while(q--){ int ind;cin>>ind; if(ind==2){ int pos;cin>>pos; cout<<sum(pos)<<"\n"; } else{ int pos,val;cin>>pos>>val; if(pos>1){ int r=max(h[pos],h[pos-1]); int l=min(h[pos],h[pos-1]); add(l,-1); if(r!=1e6)add(r+1,1); } if(pos<m){ int r=max(h[pos],h[pos+1]); int l=min(h[pos],h[pos+1]); add(l,-1); if(r!=1e6)add(r+1,1); } h[pos]=val; if(pos>1){ int r=max(h[pos],h[pos-1]); int l=min(h[pos],h[pos-1]); add(l,1); if(r!=1e6)add(r+1,-1); } if(pos<m){ int r=max(h[pos],h[pos+1]); int l=min(h[pos],h[pos+1]); add(l,1); if(r!=1e6)add(r+1,-1); } } } } int main(){ ios_base::sync_with_stdio(false);cin.tie(0); int test=1;//cin>>test; while(test--)solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...