Submission #893190

#TimeUsernameProblemLanguageResultExecution timeMemory
893190AndreyMoney (IZhO17_money)C++14
0 / 100
1 ms452 KiB
#include <bits/stdc++.h> using namespace std; map<int,int> wow; map<int,int> br; 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--) { br[wut[i].first] = br[wut[i].first]+1; wow[wut[i].first] = i; } int y = n-1,ans = 0; while(y >= 0) { int p = wow[haha[y]]-1; for(int i = y; i >= 0; i--) { if(haha[i] != haha[y]) { break; } 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...