Submission #94476

# Submission time Handle Problem Language Result Execution time Memory
94476 2019-01-19T08:35:44 Z theknife2001 Vudu (COCI15_vudu) C++11
42 / 140
1000 ms 66560 KB
#include <bits/stdc++.h>
#define ll long long
#define mid (l+r)/2

using namespace std;
map < ll , int > mp;
const int N=1e6+55;
int tree[N*4];
ll sum[N];
ll a[N];
int n;

void update(int node , int l , int r , int ind)
{
    if(l==r&&l==ind)
    {
        tree[node]++;
        return ;
    }
    if(ind<=mid)
        update(node*2,l,mid,ind);
    else
        update(node*2+1,mid+1,r,ind);
    tree[node]=tree[node*2]+tree[node*2+1];
}

int query(int node  , int l , int r , int x , int y)
{
    if(x<=l&&r<=y)
        return tree[node];
    if(l>y||r<x)
        return 0;
    return query(node*2,l,mid,x,y)+query(node*2+1,mid+1,r,x,y);
}

int main()
{
    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];
    }
    sort(a,a+n);
    int cnt=1;
    for(int i=0;i<n;i++)
    {
        if(mp[a[i]]==0)
            mp[a[i]]=cnt++;
    }
    ll ans=0;
    for(int i=n-1;i>=0;i--)
    {
        if(sum[i]>=0)
            ans++;
        ans+=query(1,0,1e6,0,mp[sum[i]]);
        update(1,0,1e6,mp[sum[i]]);
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1016 KB Output is correct
2 Correct 7 ms 860 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Runtime error 890 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Execution timed out 1047 ms 52596 KB Time limit exceeded
6 Runtime error 865 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 857 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Execution timed out 1071 ms 66560 KB Time limit exceeded
9 Runtime error 887 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 870 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)