# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
48438 | aleksami | Vudu (COCI15_vudu) | C++14 | 1065 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;
#define MAXN 1000005
typedef long long ll;
ll a[MAXN];
int tree[4*MAXN];
vector <ll> v;
void update(int node,int left,int right,int idx,int val)
{
if(left==right)
{
tree[node]+=val;
return ;
}
int mid=left+right>>1;
if(idx <= mid)update(node*2,left,mid,idx,val);
if(idx > mid)update(node*2+1,mid+1,right,idx,val);
tree[node]=tree[node*2]+tree[node*2+1];
}
int query(int node,int left,int right,int l,int r)
{
if(left >= l && right <= r)return tree[node];
int mid = left+right>>1;
int ans=0;
if(l <= mid)ans+=query(node*2,left,mid,l,r);
if(r > mid)ans+=query(node*2+1,mid+1,right,l,r);
return ans;
}
set <ll> st;
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
ll p;
cin >> p;
for(int i = 1; i <= n; i++)
{
a[i]-=p;
}
//v.push_back(0LL);
st.insert(0LL);
for(int i = 1; i <= n; i++)
{
a[i]+=a[i-1];
st.insert(a[i]);//v.push_back(a[i]);
}
for(auto x:st)v.push_back(x);
//sort(v.begin(),v.end());
ll ans=0;
for(int i = 0; i <= n; i++)
{
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
if(i!=0)update(1,0,v.size()-1,a[i-1],1);
ans += 1LL*query(1,0,v.size()-1,0,a[i]);
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |