답안 #94477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94477 2019-01-19T08:37:58 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;
short 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1016 KB Output is correct
2 Correct 7 ms 888 KB Output is correct
3 Correct 7 ms 760 KB Output is correct
4 Runtime error 901 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Execution timed out 1056 ms 45872 KB Time limit exceeded
6 Runtime error 869 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 887 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Execution timed out 1080 ms 66560 KB Time limit exceeded
9 Runtime error 906 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 864 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)