이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |