#include<bits/stdc++.h>
#define TASKNAME "bieudo"
#define pb push_back
#define pli pair<int,int>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=1e6+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll bit[maxN];
ll a[maxN];
vector<ll> vec[maxN];
ll n;
void update(ll i,ll val)
{
while(i<=n)
{
bit[i]+=val;
i+=(i&(-i));
}
}
ll get(ll i)
{
ll cc=0;
while(i>0)
{
cc+=bit[i];
i-=(i&(-i));
}
return cc;
}
ll getlr(ll i,ll j)
{
if(i>j) return 0;
return get(j)-get(i-1);
}
void solve()
{
cin >> n;
for(int i=1;i<=n;i++)
{
cin >> a[i];
}
a[0]=0;
ll cnt=0;
for(int i=1;i<=n;i++)
{
ll j=i+1;
cnt++;
vec[cnt].pb(a[i]);
while(j<=n&&a[j]>=a[j-1])
{
vec[cnt].pb(a[j]);
j++;
}
i=j-1;
}
for(auto zz:vec[1])
{
update(zz,1);
}
ll ans=cnt;
for(int i=2;i<=cnt;i++)
{
for(int j=1;j<vec[i].size();j++)
{
if(getlr(vec[i][j-1]+1,vec[i][j]-1)>0)
{
ans++;
}
}
for(auto zz:vec[i])
{
update(zz,1);
}
}
cout << ans;
}
int main()
{
fastio
// freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message
money.cpp: In function 'void solve()':
money.cpp:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int j=1;j<vec[i].size();j++)
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23724 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23812 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23792 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
12 ms |
23816 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23724 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23812 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23792 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
12 ms |
23816 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23724 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23812 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23792 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
12 ms |
23816 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23724 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23812 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
13 ms |
23792 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
12 ms |
23816 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
12 ms |
23764 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |