# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
94545 | theknife2001 | Vudu (COCI15_vudu) | C++17 | 334 ms | 45356 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define mid (l+r)/2
#define ii pair < ll , int >
#define se second
#define fi first
using namespace std;
const int N=1e6+55;
vector < ii > vec;
int tree[N];
ll sum[N];
ll a[N];
int n;
bool cmp (ii A, ii B) {
if (A.first != B.first) return A.first < B.first;
return A.second > B.second;
}
int query(int x)
{
if(x<=0)
return 0;
return query(x-(x&(-x)))+tree[x];
}
void update(int x)
{
if(x>n)
return ;
tree[x]++;
update(x+(x&(-x)));
}
int main()
{
ios::sync_with_stdio(false);
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
int p;
cin>>p;
for(int i=n-1;i>=0;i--)
{
sum[i]=a[i]-p;
if(i!=n-1)
sum[i]+=sum[i+1];
a[i]=sum[i];
}
for(int i=0;i<n;i++)
{
vec.push_back({a[i],i+1});
}
sort(vec.begin(),vec.end(),cmp);
int cnt=1;
ll ans=0;
for(int i=0;i<n;i++)
{
// cout<<vec[i].fi<<' '<<vec[i].se<<endl;
if(vec[i].fi>=0)
ans++;
ans+=(i)-query(vec[i].se);
// cout<<ans<<endl;
update(vec[i].se);
}
cout<<ans<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |