Submission #94482

# Submission time Handle Problem Language Result Execution time Memory
94482 2019-01-19T10:02:56 Z theknife2001 Vudu (COCI15_vudu) C++11
0 / 140
702 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];
ll sum[N];
ll a[N];
int n;

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];
    }
    sort(a,a+n);
    int cnt=1;
    for(int i=0;i<n;i++)
    {
        if(mp[a[i]]==0)
            mp[a[i]]=cnt++;
    }
    assert(0);
    ll ans=0;
    for(int i=n-1;i>=0;i--)
    {
        if(sum[i]>=0)
            ans++;
        ans+=query(mp[sum[i]]);
        update(mp[sum[i]]);
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1784 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 5 ms 1400 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 5 ms 1400 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 666 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 440 ms 66560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 653 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 627 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 652 ms 66560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 702 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 631 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)