Submission #2873718


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 2e5+10;

ll n,k,x,s[maxn],tree[maxn*4];
vector<ll> v;

void add(ll x){
    while(x < maxn){
        tree[x] += 1;
        x += x&-x;
    }
}

ll sum(ll x){
    ll res = 0;
    while(x > 0){
        res += tree[x];
        x -= x&-x;
    }
    return res;
}

int main(){
    cin >> n >> k;
    for(int i=1; i<=n; i++){
        x = read();
        x -= k;
        s[i] = s[i-1]+x;
    }
    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;

    ll ans = 0;
    for(int i=0; i<=n; i++){
        ans += sum(s[i]);
        add(s[i]);
    }
    cout << ans << endl;


    return 0;
}

Submission Info

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

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 29 ms 3956 KB
b06 AC 35 ms 5104 KB
b07 AC 48 ms 4336 KB
b08 AC 48 ms 4336 KB
b09 AC 38 ms 5104 KB
b10 AC 41 ms 5104 KB
b11 AC 1 ms 256 KB
b12 AC 1 ms 256 KB
b13 AC 18 ms 2036 KB
b14 AC 49 ms 5104 KB
b15 AC 24 ms 4336 KB
b16 AC 38 ms 5104 KB
b17 AC 49 ms 5104 KB
b18 AC 50 ms 5104 KB
b19 AC 36 ms 5104 KB
b20 AC 34 ms 3956 KB
b21 AC 28 ms 3956 KB
b22 AC 49 ms 5104 KB
b23 AC 48 ms 5104 KB