Submission #270599

#TimeUsernameProblemLanguageResultExecution timeMemory
270599wutwereBaloni (COCI15_baloni)C++17
100 / 100
1171 ms92540 KiB
#include <bits/stdc++.h> using namespace std; using ll=int64_t; #define pb push_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define _F(i,a,b,s) for(int i=(a);((s)>0?i<(b):i>(b));i+=(s)) #define _1(e) _F(i,0,e,1) #define _2(i,e) _F(i,0,e,1) #define _3(i,b,e) _F(i,b,e,(b)<(e)?1:-1) #define _G(a,b,c,d,e,...) e #define FOR(...) _G(__VA_ARGS__,_F,_3,_2,_1)(__VA_ARGS__) const int MAXN = 1e6 + 1; set<int> pos[MAXN]; int main() { ios::sync_with_stdio(0),cin.tie(0); int n; cin >> n; set<int> hv; FOR (i, n) { int h; cin >> h; pos[h].insert(i); hv.insert(h); } int ans = 0; for (auto it = hv.rbegin(); it != hv.rend(); it++) { int i = *it; while (!pos[i].empty()) { ans++; auto lastit = pos[i].begin(); int last = *lastit; pos[i].erase(lastit); FOR (j, i - 1, 0) { auto nxtit = pos[j].upper_bound(last); if (nxtit != pos[j].end()) { last = *nxtit; pos[j].erase(nxtit); } else { break; } } } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...