# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
684807 | US3RN4M3 | Vudu (COCI15_vudu) | C++17 | 576 ms | 37656 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<ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
template<int size>
struct st {
st<size / 2> l, r;
int val = 0;
st() {}
void add(int pos) {
val++;
if(pos < size/2) l.add(pos);
else r.add(pos - size/2);
}
int get(int pos) {
if(pos == size / 2) return l.val;
else if(pos > size / 2) {
return l.val + r.get(pos - size / 2);
} else return l.get(pos);
}
};
template<>
struct st<1> {
int val = 0;
st() {}
void add(int) {
val++;
}
int get(int) {
return val;
}
};
st<1048576> t;
main() {
int n; cin >> n;
vector<int> nums(n);
for(int & i : nums) cin >> i;
ll p; cin >> p;
vector<pair<ll, int>> vals(n);
ll sum = 0;
ll ans = 0;
for(int i = 0; i < n; i++) {
sum += nums[i];
ll goal = p*(i + 1);
vals[i] = {sum - goal, i};
if(sum >= goal) ans++;
}
sort(vals.begin(), vals.end());
for(int i = 0; i < n; i++) {
ans += t.get(vals[i].second);
t.add(vals[i].second);
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |