#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int mod = 998244353;
struct BIT{
ll sz;
vl ft;
void init(){
sz = 1e6+10;
ft.resize(sz+6);
}
void add(ll idx, ll val){
while(idx <= sz){
ft[idx] += val;
idx += (idx & (-idx));
}
}
ll get(ll idx){
ll ret = 0;
while(idx > 0){
ret += ft[idx];
idx -= (idx & (-idx));
}
return ret;
}
ll ask(ll l, ll r){
return get(r) - get(l-1);
}
};
void solve()
{
ll n, i, j, ans = 1;
cin>>n;
vl v(n);
BIT ft;
ft.init();
for(i=0;i<n;i++){
cin>>v[i];
}
ft.add(v[0], 1);
j = 1;
while(j < n && v[j] >= v[j-1]){
ft.add(v[j], 1);
j++;
}
if(j == n){
cout << 1 << '\n';
return ;
}
ans++;
ll bar = ft.get(v[j]);
for(i = j + 1; i<n; i++){
if(ft.get(v[i]) != bar || v[i] < v[i-1]){
ans++;
for(j; j<i; j++){
ft.add(v[j], 1);
}
bar = ft.get(v[j]);
}
}
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//precomp();
ll tst=1;
//cin>>tst;
while(tst--){
solve();
}
}
/*
ok.
*/
Compilation message
money.cpp: In function 'void solve()':
money.cpp:67:17: warning: statement has no effect [-Wunused-value]
67 | for(j; j<i; j++){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8284 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8140 KB |
Output is correct |
4 |
Incorrect |
2 ms |
8284 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8284 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8140 KB |
Output is correct |
4 |
Incorrect |
2 ms |
8284 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8284 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8140 KB |
Output is correct |
4 |
Incorrect |
2 ms |
8284 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8284 KB |
Output is correct |
2 |
Correct |
2 ms |
8284 KB |
Output is correct |
3 |
Correct |
2 ms |
8140 KB |
Output is correct |
4 |
Incorrect |
2 ms |
8284 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |