Submission #2872951


Source Code Expand

    #include<bits/stdc++.h>

    using namespace std;

    const int maxn = 2e5+111;

    long long c[maxn];
    long long s[maxn];
    long long lowbit(long long x)
    {
        return x & -x;
    }

    long long sum(long long x)
    {
        long long res = 0;
        while(x>0)
        {
            res += c[x];
            x -= lowbit(x);
        }
        return res;
    }

    void add(long long x,long long v)
    {
        while(x<maxn)
        {
            c[x] += v;
            x += lowbit(x);
        }
    }

    int main()
    {
        long long n,k;
        cin>>n>>k;
        long long x;
        vector<long long> v;
        for(int i =1;i<=n;i++)
        {
            scanf("%lld",&x);
            x -= k;
            s[i] = s[i-1] + x;
            //v.push_back(s[i]);
        }
        for(int i =0;i<=n;i++)
        v.push_back(s[i]);
        sort(v.begin(),v.end());
        v.resize(unique(v.begin(),v.end()) - v.begin());
        for(int i = 0;i<=n;i++)
            s[i] = lower_bound(v.begin(),v.end(),s[i])-v.begin()+1;
        long long ans = 0;
        for(int i = 0;i<=n;i++)
            {ans += sum(s[i]);
            add(s[i],1);}
        cout<<ans<<endl;
    }

Submission Info

Submission Time
Task E - Meaningful Mean
User vjudge4
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1202 Byte
Status AC
Exec Time 57 ms
Memory 5104 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:42:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld",&x);
                             ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 23
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 36 ms 3956 KB
b06 AC 43 ms 5104 KB
b07 AC 56 ms 4336 KB
b08 AC 56 ms 4336 KB
b09 AC 48 ms 5104 KB
b10 AC 50 ms 5104 KB
b11 AC 1 ms 256 KB
b12 AC 1 ms 256 KB
b13 AC 20 ms 2036 KB
b14 AC 57 ms 5104 KB
b15 AC 36 ms 4336 KB
b16 AC 46 ms 5104 KB
b17 AC 57 ms 5104 KB
b18 AC 57 ms 5104 KB
b19 AC 44 ms 5104 KB
b20 AC 42 ms 3956 KB
b21 AC 36 ms 3956 KB
b22 AC 57 ms 5104 KB
b23 AC 56 ms 5104 KB