# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
924110 | TIN | Vudu (COCI15_vudu) | C++17 | 466 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>
using namespace std;
#define FNAME "test"
#define sz(v) (int) (v).size()
#define all(v) (v).begin(), (v).end()
typedef long long ll;
const int N = 1e6 + 5;
int n;
vector<ll> a;
ll P;
vector<ll> pre;
ll ans;
struct Fenwick {
int n;
vector<ll> f;
Fenwick(int n) : n(n), f(n + 1, 0) {}
void set(ll i) {
for (; i <= n; i += i & (-i)) f[i]++;
return;
}
ll get(ll i) const {
ll r = 0;
for (; i >= 1; i -= i &(-i)) r += f[i];
return r;
}
};
void Task() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
}
void compress(vector<ll>& a) {
set<ll> s(a.begin(), a.end());
vector<ll> b(s.begin(), s.end());
for (ll &x : a) x = lower_bound(b.begin(), b.end(), x) - b.begin() + 1;
return;
}
void Solve() {
//Your Code
cin >> n;
a.resize(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
cin >> P;
pre.resize(n + 1);
pre[0] = 0;
for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (a[i] - P);
compress(pre);
Fenwick BIT(sz(pre) + 5);
ans = 0;
for (int i = 1; i <= n; i++) {
BIT.set(pre[i - 1]);
ans += BIT.get(pre[i]);
}
cout << ans << '\n';
}
int main() {
Task();
Solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |