#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define intt int
#define fi first
#define se second
const intt mxN = 1e5 + 5;
const intt LG = 20;
const intt inf = 1e18;
const intt mod = 10007;
intt n, p;
vector<intt> a(mxN), pre(mxN);
void _() {
cin >> n;
a.resize(n);
for(intt i = 0; i < n; i++) {
cin >> a[i];
pre[i] = a[i];
if(i) pre[i] += pre[i-1];
}
cin >> p;
ordered_multiset<intt> mst;
mst.insert(pre[0]);
intt ans = 0;
for(intt i = 1; i < n; i++) {
ans += mst.order_of_key((pre[i] - p * i) + 1);
mst.insert(pre[i] - p * i);
}
for(intt i = 0; i < n; i++) {
if(pre[i] / (i + 1) >= p) {
ans++;
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
intt t = 1, buu = 1;
// cin >> t;
while(t--){
// cout << "Case #" << buu++ << ": ";
_();
}
}
Compilation message (stderr)
vudu.cpp:14:18: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
14 | const intt inf = 1e18;
| ^~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |