#include <bits/stdc++.h>
int n;
using namespace std;
int tr[400000];
void add(int l,int r)
{
l+=n;
r+=n;
tr[l]++;
if(l!=r)tr[r]++;
while(l/2 != r/2)
{
if(l%2 == 0)tr[l+1]++;
if(r%2 == 1)tr[r-1]++;
l/=2;r/=2;
}
}
int check(int p)
{
p+=n;
int ans = 0;
while(p > 0)
{
ans+=tr[p];
p/=2;
}
return ans;
}
int main()
{
cin>>n;
int a[n];
for(int i =0 ;i<n;i++)
{
cin>>a[i];
tr[i+n] = a[i];
}
int ans = 0;
int i = 1;
int j = n-2;
while(i <=j)
{
if(check(i-1) < check(i))
{
i++;
continue;
}
if(check(j+1) < check(j))
{
j--;
continue;
}
add(i,j);
ans++;
}
if(check(i) == check(j))
{
ans++;
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |