Submission #91006

#TimeUsernameProblemLanguageResultExecution timeMemory
91006popovicirobertMoney (IZhO17_money)C++14
0 / 100
2 ms656 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long #define ld long double // 217 // 44 using namespace std; const int MAXN = (int) 1e6; int arr[MAXN + 1]; int aib[MAXN + 1]; inline void update(int pos, int n) { for(int i = pos; i <= n; i += lsb(i)) { aib[i]++; } } inline int query(int pos) { int ans = 0; for(int i = pos; i > 0; i -= lsb(i)) { ans += aib[i]; } return ans; } inline int sum(int l, int r) { if(l == r) { return 0; } return query(r - 1) - query(l); } int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, n; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n; for(i = 1; i <= n; i++) { cin >> arr[i]; } int ans = 0; i = 1; while(i <= n) { int j = i + 1; update(arr[i], n); ans++; while(j <= n && arr[j] >= arr[j - 1] && sum(arr[j - 1], arr[j]) == 0) { update(arr[j], n); j++; } i = j; } cout << ans; //cin.close(); //cout.close(); 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...