Submission #1688781


Source Code Expand

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

template<typename T>
struct BIT {
  vector<T> data;
  BIT() {}
  BIT(int n) : data(n+1, 0) {}
  void init(int n) { data.assign(n+1, 0); }
  T sum(int ed) const {
    // cerr << ">> " << ed << endl;
    for(T res(0); ; ed &= ed-1) if(ed) res += data[ed]; else return res;
  }
  void add(int i, const T& x) {
    // cerr << ">>> " << i << endl;
    for(++i; i < (int)data.size(); i += i&-i) data[i] += x;
  }
};

int n;
ll k;
ll vs[200000+10];
ll ss[200000+10];
ll ts[200000+10];

int main(void) {
  scanf("%d%lld", &n, &k);
  REP(i, n) {
    scanf("%lld", &vs[i]);
    ts[i+1] = ss[i+1] = ss[i] + vs[i] - k;
  }

  sort(ts, ts + n+1);
  ll res = 0;
  BIT<ll> bit(n+1);
  {
    int idx = lower_bound(ts, ts+n+1, ss[n]) - ts;
    // cerr << " add to " << idx << endl;
    bit.add(idx, 1);
  }
  for(int i = n-1; i >= 0; --i) {
    // cerr << "i=" << i << ", ss[i]=" << ss[i] << endl; 
    int idx = lower_bound(ts, ts+n+1, ss[i]) - ts;
    // cerr << " + " << bit.sum(n) - bit.sum(idx) << " @ i=" << i << ", idx=" << idx << endl;
    res += bit.sum(n) - bit.sum(idx);
    int idx2 = lower_bound(ts, ts+n+1, ss[i]) - ts;
    // cerr << " add to " << idx2 << endl;
    bit.add(idx2, 1);
  }
  printf("%lld\n", res);
  
  return 0;
}

Submission Info

Submission Time
Task E - Meaningful Mean
User ush
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1493 Byte
Status WA
Exec Time 73 ms
Memory 6528 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:35:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld", &n, &k);
                          ^
./Main.cpp:37:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &vs[i]);
                          ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 12
WA × 11
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 2 ms 2304 KB
a02 AC 2 ms 2304 KB
a03 AC 2 ms 2304 KB
b04 AC 2 ms 2304 KB
b05 AC 44 ms 6528 KB
b06 AC 55 ms 6528 KB
b07 WA 70 ms 6528 KB
b08 AC 70 ms 6528 KB
b09 AC 59 ms 6528 KB
b10 WA 63 ms 6528 KB
b11 AC 2 ms 2304 KB
b12 WA 2 ms 2304 KB
b13 WA 26 ms 3840 KB
b14 WA 73 ms 6528 KB
b15 AC 44 ms 6528 KB
b16 WA 57 ms 6528 KB
b17 WA 72 ms 6528 KB
b18 WA 72 ms 6528 KB
b19 AC 56 ms 6528 KB
b20 WA 49 ms 6528 KB
b21 AC 43 ms 6528 KB
b22 WA 70 ms 6528 KB
b23 WA 68 ms 6528 KB