Submission #2872914


Source Code Expand

    #include<bits/stdc++.h>

    using namespace std;

    const int maxn = 2e5+111;

    long long c[maxn<<2];
    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("%d",&x);
            x -= k;
            s[i] = s[i-1] + x;
            v.push_back(s[i]);
        }
        v.push_back(s[0]);
        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(long long 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 vjudge3
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1161 Byte
Status WA
Exec Time 53 ms
Memory 6000 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:42:26: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
             scanf("%d",&x);
                          ^
./Main.cpp:42:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
                           ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 1
WA × 2
AC × 3
WA × 20
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 WA 2 ms 2304 KB
a02 AC 2 ms 2304 KB
a03 WA 2 ms 2304 KB
b04 AC 2 ms 2304 KB
b05 AC 36 ms 5616 KB
b06 WA 50 ms 6000 KB
b07 WA 50 ms 6000 KB
b08 WA 53 ms 6000 KB
b09 WA 45 ms 6000 KB
b10 WA 47 ms 6000 KB
b11 WA 2 ms 2304 KB
b12 WA 2 ms 2304 KB
b13 WA 22 ms 4084 KB
b14 WA 49 ms 6000 KB
b15 WA 41 ms 6000 KB
b16 WA 48 ms 6000 KB
b17 WA 48 ms 6000 KB
b18 WA 49 ms 6000 KB
b19 WA 50 ms 6000 KB
b20 WA 50 ms 6000 KB
b21 WA 43 ms 6000 KB
b22 WA 50 ms 6000 KB
b23 WA 48 ms 6000 KB