// XD XD
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define el cout << "\n";
using namespace std;
using ll = long long;
const int MAXN = 1e6 + 7;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e18 + 7;
template <typename T>
bool ckmin(T& a, T b) {
return a > b ? a = b, true : false;
}
template <typename T>
bool ckmax(T& a, T b) {
return a < b ? a = b, true : false;
}
struct fenwickTree {
vector<int> bit;
int n;
fenwickTree(int n) : n(n) {
bit.assign(n + 1, 0);
}
void update(int x, int val) {
for(; x <= n; x += x & -x) bit[x] += val;
}
int get(int x) {
int res = 0;
for(; x; x -= x & -x) res += bit[x];
return res;
}
};
int n, p;
ll a[MAXN];
void solve(int id) {
// cout << "Case " << id << ": ";
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
cin >> p;
for (int i = 1; i <= n; i++) {
a[i] += a[i - 1] - p;
}
vector<ll> f;
for (int i = 0; i <= n; i++) {
f.push_back(a[i]);
}
sort(all(f));
f.resize(unique(all(f)) - f.begin());
ll ans = 0;
int m = f.size();
fenwickTree ft(m);
for (int i = 0; i <= n; i++) {
int x = lower_bound(all(f), a[i]) - f.begin() + 1;
ans += ft.get(x);
ft.update(x, 1);
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
solve(i);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |