#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
const ll maxn = 1e6 + 100, maxm = 3e5 + 1, maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31, block = 400;
using namespace std;
int n;
int a[maxn], f[maxn];
void upd(int pos, int val){
for (int i = pos; i <= 1e6; i |= (i + 1)){
f[i] += val;
}
}
int get(int pos){
int res = 0;
for (int i = pos; i >= 1; i = (i & (i + 1)) - 1){
res += f[i];
}
return res;
}
int main(){
cin >> n;
for (int i = 1; i <= n; ++i){
cin >> a[i];
}
int pos = 1, ans = 0;
vector<int> v;
v.pb(0), v.pb(inf);
while (pos <= n){
int mx = 0, mn = inf, answ = pos;;
for (int j = pos; j <= n; ++j){
if ((j == pos) || (j - 1 >= pos && a[j] >= a[j - 1])){
mx = max(mx, a[j]);
mn = min(mn, a[j]);
int range = get(mx - 1) - get(mn + 1);
range = max(range, 0);
if (range == 0){
answ = j;
}
else{
break;
}
}
else{
// cout << a[j] << " " << a[j - 1] << '\n';
break;
}
}
ans++;
for (int j = pos; j <= answ; ++j){
upd(a[j], 1);
}
pos = answ + 1;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |