// 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(1000000);
update(a[1]);
int x = N - 99;
for (int i = 2; i <= n; i++){
if(a[i] < a[i - 1] || x < a[i]){
int l = a[i], m, r = 1000000;
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |