Submission #893192

#TimeUsernameProblemLanguageResultExecution timeMemory
893192AndreyMoney (IZhO17_money)C++14
100 / 100
1469 ms73992 KiB
#include <bits/stdc++.h> using namespace std; vector<int> wow(1000001); vector<int> br(1000001); set<int> pos; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> haha(n); for(int i = 0; i < n; i++) { cin >> haha[i]; } pos.insert(-1); for(int i = 0; i < n; i++) { pos.insert(i); } vector<pair<int,int>> wut(n); for(int i = 0; i < n; i++) { wut[i] = {haha[i],i}; } sort(wut.begin(),wut.end()); for(int i = n-1; i >= 0; i--) { wow[wut[i].first] = i; } int y = n-1,ans = 0; while(y >= 0) { int p = wow[haha[y]]-1+br[haha[y]]; for(int i = y; i >= 0; i--) { if(haha[i] != haha[y]) { break; } br[haha[y]]++; p++; } while(y >= 0 && p >= 0 && wut[p].first == haha[y]) { y--; pos.erase(p); p = *(--pos.upper_bound(p)); } ans++; } cout << ans; 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...