This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long ll;
int n, a[N], ans, lst;
set<pair<int, int>> st;
int main() {
// freopen("money.in", "r", stdin);
// freopen("money.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
st.insert({a[i], i});
if (lst == a[i])
continue;
lst = a[i];
auto id = st.find({a[i], i});
if (id == st.begin()) {
ans++;
continue;
}
id--;
if ((*id).second == i - 1) {
continue;
}
id = st.lower_bound({a[i], -1});
if (id == st.begin()) {
ans++;
continue;
}
id--;
if ((*id).second == i - 1) {
st.erase({a[i], i});
continue;
}
ans++;
}
cout << ans;
}
/**
6
1 5 2 5 5 6
**/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |