Submission #62772

#TimeUsernameProblemLanguageResultExecution timeMemory
62772TenuunMoney (IZhO17_money)C++17
100 / 100
313 ms152412 KiB
#include<bits/stdc++.h> using namespace std; int tr[1000001], a[1000000]; void update(int ind, int val){ while(ind<=1000000){ tr[ind]+=val; ind+=ind&-ind; } } int get(int ind){ int ans=0; while(ind){ ans+=tr[ind]; ind-=ind&-ind; } return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); memset(tr, 0, sizeof tr); int n, res=0, x, start=0, mx=0; cin >> n; for(int i=0; i<n; i++) cin >> a[i]; for(int i=0; i<n; i++){ start=i; mx=a[i]; //cout << i << " "; res++; while(i+1<n && a[i+1]>=mx && get(a[i+1]-1)-get(a[start])<=0){ i++; mx=max(mx, a[i]); } for(int j=start; j<=i; j++){ update(a[j], 1); } } cout << res; return 0; }

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:27:16: warning: unused variable 'x' [-Wunused-variable]
  int n, res=0, x, start=0, mx=0;
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...