Submission #2872940


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("%d",&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 vjudge1
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1185 Byte
Status WA
Exec Time 53 ms
Memory 5488 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 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 WA 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 36 ms 3956 KB
b06 WA 50 ms 5104 KB
b07 WA 49 ms 5104 KB
b08 WA 53 ms 5104 KB
b09 WA 47 ms 5104 KB
b10 WA 46 ms 5104 KB
b11 WA 1 ms 256 KB
b12 WA 1 ms 256 KB
b13 WA 16 ms 2036 KB
b14 WA 50 ms 5104 KB
b15 WA 43 ms 5104 KB
b16 WA 48 ms 5104 KB
b17 WA 51 ms 5104 KB
b18 WA 50 ms 5104 KB
b19 WA 50 ms 5104 KB
b20 WA 52 ms 5104 KB
b21 WA 43 ms 5104 KB
b22 WA 50 ms 5104 KB
b23 WA 51 ms 5488 KB