Submission #729881

#TimeUsernameProblemLanguageResultExecution timeMemory
729881NintsiChkhaidzeMoney (IZhO17_money)C++17
0 / 100
0 ms340 KiB
#include <bits/stdc++.h> #define pb push_back #define tree int h,int l,int r #define left (h<<1),l,(l+r)>>1 #define right ((h<<1)|1),((l+r)>>1) + 1,r #define f first #define s second #define ll long long using namespace std; const int N = 1e6 + 5; int a[N],fen[N]; void upd(int idx){ while (idx <= 1000000){ fen[idx] += 1; idx += (idx & (-idx)); } } int get(int idx){ int s = 0; while (idx){ s += fen[idx]; idx -= (idx & (-idx)); } return s; } signed main (){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n; cin>>n; for (int i = 1; i <= n; i++) cin>>a[i]; int l = 1,ans=0; while (l <= n){ int r = l,mn = a[l],mx = a[l]; while (r + 1 <= n){ if (a[r + 1] < a[r]) break; int mn1 = min(mn,a[r + 1]),mx1 = max(mx,a[r + 1]); if (get(mx1) - get(mn1 - 1) > 0) break; mn = mn1,mx = mx1; r++; } for (int i = l; i <= r; i++) upd(a[i]); l = r + 1; ++ans; } 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...