Submission #36138

#TimeUsernameProblemLanguageResultExecution timeMemory
36138Dat160601Money (IZhO17_money)C++14
100 / 100
259 ms9988 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int n,a[1000007],bit[1000007]; int ans=1,cur=1; void upd(int pos){ for(int i=pos;i<=1000000;i+=i&-i){ bit[i]++; } } long long get(int pos){ long long res=0; for(int i=pos;i>=1;i-=i&-i){ res+=bit[i]; } return res; } int main(){ ios_base::sync_with_stdio(0); cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=2;i<=n;i++){ int res=get(a[i]-1); res-=get(a[cur]); if(a[i]<a[i-1] || res>0){ ans++; while(cur<i){ upd(a[cur]); cur++; } } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...