Submission #480063

#TimeUsernameProblemLanguageResultExecution timeMemory
480063NachoLibrePo (COCI21_po)C++17
20 / 70
54 ms6084 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 k = i; k <= n; ++k) { if(b[k].first != b[i].first) break; j = k; } ++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)); if(x != y) ++ans; } 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...