#include<bits/stdc++.h>
#define meta int tm = tl + (tr - tl) / 2, x = (i << 1) + 1, y = x + 1
using namespace std;
using ll = long long;
const int maxn = 1e6 + 1;
int st[maxn * 4] {};
void update(int i, int tl, int tr, int pos) {
if(tl == tr) {
st[i]++;
return;
}
meta;
if(pos <= tm) update(x, tl, tm, pos);
else update(y, tm + 1, tr, pos);
st[i] = st[x] + st[y];
}
int query(int i, int tl, int tr, int l, int r) {
if(l <= tl && tr <= r) return st[i];
if(tr < l || tl > r) return 0;
meta;
if(r <= tm) return query(x, tl, tm, l, r);
else if(l > tm) return query(y, tm + 1, tr, l, r);
else return query(x, tl, tm, l, tm) + query(y, tm + 1, tr, tm + 1, r);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
ll p[n + 1], a[n];
for(int i = 0; i < n; i++) {
cin >> a[i];
}
ll x;
cin >> x;
p[0] = 0;
for(int i = 1; i <= n; i++) {
p[i] = p[i - 1] + a[i - 1];
}
for(int i = 1; i <= n; i++) {
p[i] -= x * i;
}
ll ans = 0;
vector<pair<ll, int>> v;
for(int i = 0; i <= n; i++) {
v.push_back({p[i], i});
}
sort(v.begin(), v.end());
for(int i = 0; i <= n; i++) {
int x = v[i].second;
ans += query(0, 0, n, 0, x);
update(0, 0, n, x);
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |