Language: C++

#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

template <typename Base>
class BinaryIndexedTree
{
public:
    using T = typename Base::T;
    using AbelGroup = Base;

    BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); }
    BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity())
    {
        for (int i = 1; i <= size; i++) {
            value[i] = val[i - 1];
        }
        for (int x = 1; x < size; x++) {
            value[x + (x & -x)] += value[x];
        }
    }

    T accumulate(const int a) const
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        T sum = AbelGroup::identity();
        while (ind > 0) {
            sum = op(sum, value[ind]);
            ind &= ind - 1;
        }
        return sum;
    }

    void add(const int a, const T& val)
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        while (ind <= size) {
            value[ind] = op(value[ind], val);
            ind += ind & (-ind);
        }
    }

    T get(const int a) const
    {
        assert(0 <= a and a < data_num);
        if (a == 0) {
            return accumulate(a);
        } else {
            return op(op.inv(accumulate(a - 1)), accumulate(a));
        }
    }

    void print() const
    {
        show(value);
    }

    // Needs ordered in Base abel-group
    int lowerBound(T w) const
    {
        if (w <= AbelGroup::identity()) {
            return 0;
        }
        int x = 0;
        for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) {
            if (x + k <= size and value[x + k] < w) {
                w = op(w, op.inv(value[x + k]));
                x += k;
            }
        }
        return x;
    }

private:
    const int data_num;
    const int size;
    const AbelGroup op{};
    vector<T> value;
};

struct Sum {
    using T = ll;
    T operator()(const T& a, const T& b) const
    {
        return a + b;
    }
    T inv(const T& a) const
    {
        return -a;
    }
    static constexpr T identity()
    {
        return 0;
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> s(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        if (i == 0) {
            s[i] = a[i];
        } else {
            s[i] = s[i - 1] + a[i];
        }
    }
    vector<ll> t(n);
    for (ll i = 0; i < n; i++) {
        t[i] = s[i] - (i + 1) * k;
    }
    int un = 0;
    for (ll i = 0; i < n; i++) {
        if (t[i] >= 0) {
            un++;
        }
    }
    //    show(t);

    map<int, int> zip;
    vector<ll> t_copy = t;
    sort(t_copy.begin(), t_copy.end());
    t_copy.erase(unique(t_copy.begin(), t_copy.end()), t_copy.end());
    for (int i = 0; i < t_copy.size(); i++) {
        zip[t_copy[i]] = i;
    }
    for (int i = 0; i < n; i++) {
        t[i] = zip[t[i]];
    }

    //    show(t);
    BinaryIndexedTree<Sum> bit{n};
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        //        bit.print();
        sum += bit.accumulate(t[i]);
        bit.add(t[i], 1);
    }
    //    bit.print();
    cout << sum + un << endl;
    return 0;
}
#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

template <typename Base>
class BinaryIndexedTree
{
public:
    using T = typename Base::T;
    using AbelGroup = Base;

    BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); }
    BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity())
    {
        for (int i = 1; i <= size; i++) {
            value[i] = val[i - 1];
        }
        for (int x = 1; x < size; x++) {
            value[x + (x & -x)] += value[x];
        }
    }

    T accumulate(const int a) const
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        T sum = AbelGroup::identity();
        while (ind > 0) {
            sum = op(sum, value[ind]);
            ind &= ind - 1;
        }
        return sum;
    }

    void add(const int a, const T& val)
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        while (ind <= size) {
            value[ind] = op(value[ind], val);
            ind += ind & (-ind);
        }
    }

    T get(const int a) const
    {
        assert(0 <= a and a < data_num);
        if (a == 0) {
            return accumulate(a);
        } else {
            return op(op.inv(accumulate(a - 1)), accumulate(a));
        }
    }

    void print() const
    {
        show(value);
    }

    // Needs ordered in Base abel-group
    int lowerBound(T w) const
    {
        if (w <= AbelGroup::identity()) {
            return 0;
        }
        int x = 0;
        for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) {
            if (x + k <= size and value[x + k] < w) {
                w = op(w, op.inv(value[x + k]));
                x += k;
            }
        }
        return x;
    }

private:
    const int data_num;
    const int size;
    const AbelGroup op{};
    vector<T> value;
};

struct Sum {
    using T = ll;
    T operator()(const T& a, const T& b) const
    {
        return a + b;
    }
    T inv(const T& a) const
    {
        return -a;
    }
    static constexpr T identity()
    {
        return 0;
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> s(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        if (i == 0) {
            s[i] = a[i];
        } else {
            s[i] = s[i - 1] + a[i];
        }
    }
    vector<ll> t(n);
    for (ll i = 0; i < n; i++) {
        t[i] = s[i] - (i + 1) * k;
    }
    int un = 0;
    for (ll i = 0; i < n; i++) {
        if (t[i] >= 0) {
            un++;
        }
    }
    //    show(t);

    map<int, int> zip;
    vector<ll> t_copy = t;
    sort(t_copy.begin(), t_copy.end());
    t_copy.erase(unique(t_copy.begin(), t_copy.end()), t_copy.end());
    for (int i = 0; i < t_copy.size(); i++) {
        zip[t_copy[i]] = i;
    }
    for (int i = 0; i < n; i++) {
        t[i] = zip[t[i]];
    }

    //    show(t);
    BinaryIndexedTree<Sum> bit{n};
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        //        bit.print();
        sum += bit.accumulate(t[i]);
        bit.add(t[i], 1);
    }
    //    bit.print();
    cout << sum + un << endl;
    return 0;
}
#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

template <typename Base>
class BinaryIndexedTree
{
public:
    using T = typename Base::T;
    using AbelGroup = Base;

    BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); }
    BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity())
    {
        for (int i = 1; i <= size; i++) {
            value[i] = val[i - 1];
        }
        for (int x = 1; x < size; x++) {
            value[x + (x & -x)] += value[x];
        }
    }

    T accumulate(const int a) const
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        T sum = AbelGroup::identity();
        while (ind > 0) {
            sum = op(sum, value[ind]);
            ind &= ind - 1;
        }
        return sum;
    }

    void add(const int a, const T& val)
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        while (ind <= size) {
            value[ind] = op(value[ind], val);
            ind += ind & (-ind);
        }
    }

    T get(const int a) const
    {
        assert(0 <= a and a < data_num);
        if (a == 0) {
            return accumulate(a);
        } else {
            return op(op.inv(accumulate(a - 1)), accumulate(a));
        }
    }

    void print() const
    {
        show(value);
    }

    // Needs ordered in Base abel-group
    int lowerBound(T w) const
    {
        if (w <= AbelGroup::identity()) {
            return 0;
        }
        int x = 0;
        for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) {
            if (x + k <= size and value[x + k] < w) {
                w = op(w, op.inv(value[x + k]));
                x += k;
            }
        }
        return x;
    }

private:
    const int data_num;
    const int size;
    const AbelGroup op{};
    vector<T> value;
};

struct Sum {
    using T = ll;
    T operator()(const T& a, const T& b) const
    {
        return a + b;
    }
    T inv(const T& a) const
    {
        return -a;
    }
    static constexpr T identity()
    {
        return 0;
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> s(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        if (i == 0) {
            s[i] = a[i];
        } else {
            s[i] = s[i - 1] + a[i];
        }
    }
    vector<ll> t(n);
    for (ll i = 0; i < n; i++) {
        t[i] = s[i] - (i + 1) * k;
    }
    int un = 0;
    for (ll i = 0; i < n; i++) {
        if (t[i] >= 0) {
            un++;
        }
    }
    //    show(t);

    map<int, int> zip;
    vector<ll> t_copy = t;
    sort(t_copy.begin(), t_copy.end());
    t_copy.erase(unique(t_copy.begin(), t_copy.end()), t_copy.end());
    for (int i = 0; i < t_copy.size(); i++) {
        zip[t_copy[i]] = i;
    }
    for (int i = 0; i < n; i++) {
        t[i] = zip[t[i]];
    }

    //    show(t);
    BinaryIndexedTree<Sum> bit{n};
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        //        bit.print();
        sum += bit.accumulate(t[i]);
        bit.add(t[i], 1);
    }
    //    bit.print();
    cout << sum + un << endl;
    return 0;
}
#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

template <typename Base>
class BinaryIndexedTree
{
public:
    using T = typename Base::T;
    using AbelGroup = Base;

    BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); }
    BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity())
    {
        for (int i = 1; i <= size; i++) {
            value[i] = val[i - 1];
        }
        for (int x = 1; x < size; x++) {
            value[x + (x & -x)] += value[x];
        }
    }

    T accumulate(const int a) const
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        T sum = AbelGroup::identity();
        while (ind > 0) {
            sum = op(sum, value[ind]);
            ind &= ind - 1;
        }
        return sum;
    }

    void add(const int a, const T& val)
    {
        assert(0 <= a and a < data_num);
        int ind = a + 1;
        while (ind <= size) {
            value[ind] = op(value[ind], val);
            ind += ind & (-ind);
        }
    }

    T get(const int a) const
    {
        assert(0 <= a and a < data_num);
        if (a == 0) {
            return accumulate(a);
        } else {
            return op(op.inv(accumulate(a - 1)), accumulate(a));
        }
    }

    void print() const
    {
        show(value);
    }

    // Needs ordered in Base abel-group
    int lowerBound(T w) const
    {
        if (w <= AbelGroup::identity()) {
            return 0;
        }
        int x = 0;
        for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) {
            if (x + k <= size and value[x + k] < w) {
                w = op(w, op.inv(value[x + k]));
                x += k;
            }
        }
        return x;
    }

private:
    const int data_num;
    const int size;
    const AbelGroup op{};
    vector<T> value;
};

struct Sum {
    using T = ll;
    T operator()(const T& a, const T& b) const
    {
        return a + b;
    }
    T inv(const T& a) const
    {
        return -a;
    }
    static constexpr T identity()
    {
        return 0;
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> s(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
        if (i == 0) {
            s[i] = a[i];
        } else {
            s[i] = s[i - 1] + a[i];
        }
    }
    vector<ll> t(n);
    for (ll i = 0; i < n; i++) {
        t[i] = s[i] - (i + 1) * k;
    }
    int un = 0;
    for (ll i = 0; i < n; i++) {
        if (t[i] >= 0) {
            un++;
        }
    }
    //    show(t);

    map<int, int> zip;
    vector<ll> t_copy = t;
    sort(t_copy.begin(), t_copy.end());
    t_copy.erase(unique(t_copy.begin(), t_copy.end()), t_copy.end());
    for (int i = 0; i < t_copy.size(); i++) {
        zip[t_copy[i]] = i;
    }
    for (int i = 0; i < n; i++) {
        t[i] = zip[t[i]];
    }

    //    show(t);
    BinaryIndexedTree<Sum> bit{n};
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        //        bit.print();
        sum += bit.accumulate(t[i]);
        bit.add(t[i], 1);
    }
    //    bit.print();
    cout << sum + un << endl;
    return 0;
}


Compiler output:
a.cc:188:10: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)'
  188 | ostream& operator<<(ostream& os, const vector<T>& v)
      |          ^~~~~~~~
a.cc:11:10: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here
   11 | ostream& operator<<(ostream& os, const vector<T>& v)
      |          ^~~~~~~~
a.cc:199:10: error: redefinition of 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)'
  199 | ostream& operator<<(ostream& os, const pair<S, T>& p)
      |          ^~~~~~~~
a.cc:22:10: note: 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' previously declared here
   22 | ostream& operator<<(ostream& os, const pair<S, T>& p)
      |          ^~~~~~~~
a.cc:207:14: error: redefinition of 'constexpr const ll MOD'
  207 | constexpr ll MOD = 1e9 + 7;
      |              ^~~
a.cc:30:14: note: 'constexpr const ll MOD' previously defined here
   30 | constexpr ll MOD = 1e9 + 7;
      |              ^~~
a.cc:210:13: error: redefinition of 'template<class T> constexpr const T INF'
  210 | constexpr T INF = numeric_limits<T>::max() / 100;
      |             ^~~
a.cc:33:13: note: 'template<class T> constexpr const T INF<T>' previously declared here
   33 | constexpr T INF = numeric_limits<T>::max() / 100;
      |             ^~~
a.cc:213:7: error: redefinition of 'class BinaryIndexedTree<Base>'
  213 | class BinaryIndexedTree
      |       ^~~~~~~~~~~~~~~~~
a.cc:36:7: note: previous definition of 'class BinaryIndexedTree<Base>'
   36 | class BinaryIndexedTree
      |       ^~~~~~~~~~~~~~~~~
a.cc:290:8: error: redefinition of 'struct Sum'
  290 | struct Sum {
      |        ^~~
a.cc:113:8: note: previous definition of 'struct Sum'
  113 | struct Sum {
      |        ^~~
a.cc:306:5: error: redefinition of 'int main()'
  306 | int main()
      |     ^~~~
a.cc:129:5: note: 'int main()' previously defined here
  129 | int main()
      |     ^~~~
a.cc:365:10: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)'
  365 | ostream& operator<<(ostream& os, const vector<T>& v)
      |          ^~~~~~~~
a.cc:11:10: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here
   11 | ostream& operator<<(ostream& os, const vector<T>& v)
      |          ^~~~~~~~
a.cc:376:10: error: redefinition of 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)'
  376 | ostream& operator<<(ostream& os, const pair<S, T>& p)
      |          ^~~~~~~~
a.cc:22:10: note: 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' previously declared here
   22 | ostream& operator<<(ostream& os, const pair<S, T>& p)
      |          ^~~~~~~~
a.cc:384:14: error: redefinition of 'constexpr const ll MOD'
  384 | constexpr ll MOD = 1e9 + 7;
      |              ^~~
a.cc:30:14: note: 'constexpr const ll MOD' previously defined here
   30 | constexpr ll MOD = 1e9 + 7;
      |              ^~~
a.cc:387:13: error: redefinition of 'template<class T> constexpr const T INF'
  387 | constexpr T INF = numeric_limits<T>::max() / 100;
      |             ^~~
a.cc:33:13: note: 'template<class T> constexpr const T INF<T>' previously declared here
   33 | constexpr T INF = numeric_limits<T>::max() / 100;
      |             ^~~
a.cc:390:7: error: redefinition of 'class BinaryIndexedTree<Base>'
  390 | class BinaryIndexedTree
      |       ^~~~~~~~~~~~~~~~~
a.cc:36:7: note: previous definition of 'class BinaryIndexedTree<Base>'
   36 | class BinaryIndexedTree
      |       ^~~~~~~~~~~~~~~~~
a.cc:467:8: error: redefinition of 'struct Sum'
  467 | struct Sum {
      |        ^~~
a.cc:113:8: note: previous definition of 'struct Sum'
  113 | struct Sum {
      |        ^~~
a.cc:483:5: error: redefinition of 'int main()'
  483 | int main()
      |     ^~~~
a.cc:129:5: note: 'int main()' previously defined here
  129 | int main()
      |     ^~~~
a.cc:542:10: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)'
  542 | ostream& operator<<(ostream& os, const vector<T>& v)
      |          ^~~~~~~~
a.cc:11:10: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here
   11 | ostream& operator<<(ostream& os, const vector<T>& v)
      |          ^~~~~~~~
a.cc:553:10: error: redefinition of 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)'
  553 | ostream& operator<<(ostream& os, const pair<S, T>& p)
      |          ^~~~~~~~
a.cc:22:10: note: 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' previously declared here
   22 | ostream& operator<<(ostream& os, const pair<S, T>& p)
      |          ^~~~~~~~
a.cc:561:14: error: redefinition of 'constexpr const ll MOD'
  561 | constexpr ll MOD = 1e9 + 7;
      |              ^~~
a.cc:30:14: note: 'constexpr const ll MOD' previously defined here
   30 | constexpr ll MOD = 1e9 + 7;
      |              ^~~
a.cc:564:13: error: redefinition of 'template<class T> constexpr const T INF'
  564 | constexpr T INF = numeric_limits<T>::max() / 100;
      |             ^~~
a.cc:33:13: note: 'template<class T> constexpr const T INF<T>' previously declared here
   33 | constexpr T INF = numeric_limits<T>::max() / 100;
      |             ^~~
a.cc:567:7: error: redefinition of 'class BinaryIndexedTree<Base>'
  567 | class BinaryIndexedTree
      |       ^~~~~~~~~~~~~~~~~
a.cc:36:7: note: previous definition of 'class BinaryIndexedTree<Base>'
   36 | class BinaryIndexedTree
      |       ^~~~~~~~~~~~~~~~~
a.cc:644:8: error: redefinition of 'struct Sum'
  644 | struct Sum {
      |        ^~~
a.cc:113:8: note: previous definition of 'struct Sum'
  113 | struct Sum {
      |        ^~~
a.cc:660:5: error: redefinition of 'int main()'
  660 | int main()
      |     ^~~~
a.cc:129:5: note: 'int main()' previously defined here
  129 | int main()
      |     ^~~~