Submission #1127756

#TimeUsernameProblemLanguageResultExecution timeMemory
1127756VMaksimoski008Money (IZhO17_money)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> #define ar array //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; struct fenwick { int n; vector<int> tree; fenwick(int _n) : n(_n+10), tree(n+50) {} void update(int p) { for(p++; p<n; p+=p&-p) tree[p]++; } int query(int p) { int ans = 0; for(p++; p; p-=p&-p) ans += tree[p]; return ans; } }; signed main() { int n, ans = 0; cin >> n; vector<int> a(n+1); for(int i=1; i<=n; i++) cin >> a[i]; fenwick fwt(n); for(int i=1; i<=n; i++) { int j=i; while(j < n) { if(a[j+1] < a[j]) break; if(fwt.query(a[i]) != fwt.query(a[j+1]-1)) break; j++; } ans++; for(int k=i; k<=j; k++) fwt.update(a[k]); i = j; } cout << ans << '\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...