# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
961680 | Blagoj | Vudu (COCI15_vudu) | C++17 | 276 ms | 33588 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
struct FenwickTree {
vector<ll> fwt;
FenwickTree(int sz) {
fwt.resize(sz + 10000);
}
ll get(int ind) {
ll ans = 0;
for (ind++; ind; ind -= ind & -ind) ans = max(ans, fwt[ind]);
return ans;
}
void update(int ind) {
for (ind++; ind < fwt.size(); ind += ind & -ind) fwt[ind]++;
}
} fwt(1e6);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, p;
cin >> n;
ll a[n + 1], prf[n + 1];
memset(prf, 0, sizeof(prf));
for (int i = 1; i <= n; i++) {
cin >> a[i];
prf[i] = prf[i - 1] + a[i];
}
cin >> p;
vector<ll> v;
for (ll i = 0; i <= n; i++) v.push_back({prf[i] - p * i});
sort(all(v));
v.erase(unique(all(v)), v.end());
ll ans = 0;
for (ll i = 0; i <= n; i++) {
ll x = lower_bound(all(v), prf[i] - p * i) - v.begin();
ans += fwt.get(x);
fwt.update(x);
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |