# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968648 | VMaksimoski008 | Vudu (COCI15_vudu) | C++14 | 755 ms | 65536 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>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
struct BIT {
int n;
vector<int> tree;
void config(int _n) {
n = _n + 5;
tree.resize(_n+10);
}
void update(int p, int v) {
for(p++; p<n; p+=p&-p) tree[p] += v;
}
int query(int p) {
int ans = 0;
for(p++; p>0; p-=p&-p) ans += tree[p];
return ans;
}
};
int32_t main() {
int n, p, i;
ll ans = 0;
cin >> n;
vector<ll> v(n+1);
for(i=1; i<=n; i++) cin >> v[i];
cin >> p;
ll sum = 0;
for(i=1; i<=n; i++) {
sum += v[i];
v[i] = sum - (ll)i * p;
}
set<ll> s;
for(ll &x : v) s.insert(x);
vector<ll> comp(all(s));
for(ll &x : v) x = lower_bound(all(comp), x) - comp.begin();
BIT bit; bit.config(n);
bit.update(v[0], 1);
for(i=1; i<=n; i++) {
ans += bit.query(v[i]);
bit.update(v[i], 1);
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |