Submission #38586

#TimeUsernameProblemLanguageResultExecution timeMemory
38586MrPlanyMoney (IZhO17_money)C++14
100 / 100
613 ms9828 KiB
#include <iostream> using namespace std; const int N = 1e6+5; int n,a[N],t[N]; int sum(int k){ int s=0; while(k>0){ s+=t[k]; k-=k&-k; } return s; } int add(int k, int val){ while(k<N){ t[k]+=val; k+=k&-k; } } int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; int ans = 0; for(int i=1;i<=n;i++){ int l,r;l = r = i; while( a[r+1]>=a[r] && sum(a[r+1]-1) - sum(a[l])<=0) r++; ans++; while(l<=r) add(a[l++],1); i=r; } cout << ans; }

Compilation message (stderr)

money.cpp: In function 'int add(int, int)':
money.cpp:18:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...