# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
48440 | aleksami | Vudu (COCI15_vudu) | C++14 | 426 ms | 65536 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>
using namespace std;
typedef long long ll;
#define MAXN 1000005
ll a[MAXN];
int bit[MAXN];
void update(int idx,int val)
{
while(idx < MAXN)
{
bit[idx]+=val;
idx+=idx&(-idx);
}
}
int get(int idx)
{
int s=0;
while(idx > 0)
{
s+=bit[idx];
idx-=idx&(-idx);
}
return s;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
vector <ll> v;
ll p;
cin >> p;
for(int i = 1; i <= n; i++)a[i]-=p;
for(int i = 1; i <= n; i++)
{
a[i]+=a[i-1];
v.push_back(a[i]);
}
v.push_back(0LL);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
ll ans = 0LL;
for(int i = 0; i <= n; i++)
{
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
if(i>0)update(a[i-1],1);
ans += get(a[i]);
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |