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