이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// solved by using fenvick tree
// + binary search
# include <iostream>
using namespace std;
const int N = 1e6 + 100;
int n, ans = 1;
int a[N];
int cnt[N];
void update(int i)
{
while(i <= N){
cnt[i]++;
i += (i & -i);
}
}
int get(int i){
int ret = 0;
while(i > 0){
ret += cnt[i];
i -= (i & -i);
}
return ret;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
update(1e6);
update(a[1]);
int x = 1e6;
for (int i = 2; i <= n; i++){
if(a[i] < a[i - 1] || x < a[i]){
int l = a[i], m, r = 1e6;
while(r > l){
m = (r + l) >> 1;
if(get(a[m]) > a[i])
r = m;
else
l = m + 1;
}
x = l;
++ ans;
}
update(a[i]);
}
cout << ans;
}
# | 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... |