#include <bits/stdc++.h>
using namespace std;
int n;
int niz[1000005];
int bit[1000005];
int upit(int x){
int res = 0;
while(x > 0){
res += bit[x];
x -= (x&-x);
}
return res;
}
void add(int x){
while(x <= 1000000){
bit[x]++;
x += (x&-x);
}
}
int query(int l, int r){
return upit(r) - upit(l - 1);
}
void ubaci(int l, int r){
for(int i=l; i<=r; i++){
add(niz[l]);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin >> n;
for(int i=1; i<=n; i++)cin >> niz[i];
int br = 1;
int last = 1;
int res = 1;
while(br <= n){
if(niz[br] < niz[br - 1]){
ubaci(last, br - 1);
last = br;
br++;
res++;
continue;
}
if(query(niz[last], niz[br]) >= 1){
ubaci(last, br - 1);
last = br;
br++;
res++;
}
else br++;
}
cout << res << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
3 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 |
3 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 |
3 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 |
3 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |