Submission #480056

#TimeUsernameProblemLanguageResultExecution timeMemory
480056NachoLibrePo (COCI21_po)C++17
20 / 70
53 ms6332 KiB
#include <bits/stdc++.h> #define ll long long #define sz(x) ((int)x.size()) using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n + 1); vector<pair<int, int>> b(n + 1); for(int i = 1; i <= n; ++i) { cin >> a[i]; b[i].first = a[i]; b[i].second = i; } sort(b.begin() + 1, b.end()); set<int> s; s.insert(n + 1); int ans = 0; for(int i = 1; i <= n; ) { int j = i; for(int ii = i; ii <= n; ++ii) { if(b[ii].first != b[i].first) break; j = ii; } ++ans; for(int k = i + 1; k <= j; ++k) { int x = *s.upper_bound(b[k - 1].second); int y = *s.upper_bound(b[k].second); ans += (x != y); } for(int k = i; k <= j; ++k) { s.insert(b[k].second); } i = j + 1; } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...