Submission #36874

#TimeUsernameProblemLanguageResultExecution timeMemory
36874JustInCaseMoney (IZhO17_money)C++14
100 / 100
229 ms9988 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; const int MAX_N = 1e6 + 5; const int MAX_A = 1e6 + 5; struct IndexTree { private: int data[MAX_A]; public: void Add(int ind, int val); int Get(int ind); int GetInInterval(int low, int high); }; void IndexTree::Add(int ind, int val) { while(ind < MAX_A) { data[ind] += val; ind += (ind & (-ind)); } } int IndexTree::Get(int ind) { int ans = 0; while(ind > 0) { ans += data[ind]; ind -= (ind & (-ind)); } return ans; } int IndexTree::GetInInterval(int low, int high) { return Get(high) - Get(low - 1); } int a[MAX_N]; IndexTree indexTree; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for(int i = 0; i < n; i++) { cin >> a[i]; } int ans = 0; for(int i = 0; i < n; ) { int j; for(j = i + 1; j < n; j++) { if(a[j] < a[j - 1] || indexTree.GetInInterval(a[i] + 1, a[j] - 1) > 0) { break; } } ans++; for(int p = i; p < j; p++) { indexTree.Add(a[p], 1); } i = j; } cout << ans << endl; 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...