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 + 6;
int v[N];
multiset<int> ms;
void dbg(){
cerr<<ms.size()<<"\n";
for(auto x: ms)
cerr<<x<<" ";
cerr<<"\nok\n";
}
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>v[i];
ms.insert(v[i]);
}
int ans = 0;
for(int i= n; i>=1;){
int j = i;
ans++;
while(j>=1 && v[j] == v[i]){
ms.erase(ms.find(v[i]));
j--;
}
multiset<int>::iterator itr = ms.lower_bound(v[i]);
if(itr != ms.begin()){
itr --;
while(j>=1 && v[j] == (*itr)){
j--;
if(itr == ms.begin()){
ms.erase(itr);
break;
}
multiset<int>::iterator newitr = itr;
newitr --;
ms.erase(itr);
itr = newitr;
}
}
i = j;
}
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... |