Submission #429355

#TimeUsernameProblemLanguageResultExecution timeMemory
429355jovan_bMoney (IZhO17_money)C++17
100 / 100
233 ms14932 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int MAXN = 1000000; int bit[MAXN+5]; void bitadd(int x, int val){ while(x <= MAXN){ bit[x] += val; x += x & -x; } } int bitget(int x){ int res = 0; while(x){ res += bit[x]; x -= x & -x; } return res; } int a[MAXN+5]; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n; cin >> n; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i<n; i++) bitadd(a[i], 1); int splits = 0; int bgn = a[n]; for(int i=n-1; i>=1; i--){ if(a[i] > a[i+1]){ bgn = a[i]; splits++; } else{ if(bitget(bgn-1) - bitget(a[i]) > 0){ splits++; bgn = a[i]; } } bitadd(a[i], -1); } cout << splits + 1 << "\n"; return 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...