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;
vector<int> wow(1000001);
vector<int> br(1000001);
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--) {
wow[wut[i].first] = i;
}
int y = n-1,ans = 0;
while(y >= 0) {
int p = wow[haha[y]]-1+br[haha[y]];
for(int i = y; i >= 0; i--) {
if(haha[i] != haha[y]) {
break;
}
br[haha[y]]++;
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 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... |