# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
463701 | Hamed5001 | Art Exhibition (JOI18_art) | C++14 | 0 ms | 204 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;
typedef long long ll;
unordered_map<ll, ll> ID;
const int mxN = 1e6+100;
ll BIT[mxN], N, P, id = 1;
void add(int idx, ll delta) {
for (; idx < id; idx += idx & -idx)
BIT[idx] += delta;
}
ll query(int idx) {
ll ret = 0;
for (; idx > 0; idx -= idx & -idx)
ret += BIT[idx];
return ret;
}
void solve() {
cin >> N;
vector<ll> A(N);
for (auto& a : A) scanf("%lld", &a);
cin >> P;
for (auto& a : A) a-=P;
vector<ll> AA;
ll sum = 0;
AA.push_back(sum);
for (auto& a : A) {
sum += a;
AA.push_back(sum);
}
sort(AA.rbegin(), AA.rend());
for (int i = 0; i < AA.size(); ++i) {
if (!ID[AA[i]])
ID[AA[i]] = id++;
}
for (auto& aa : AA) {
add(ID[aa], 1);
}
add(ID[0], -1);
sum = 0;
ll ans = 0;
for (auto a : A) {
ans += query(ID[sum]);
sum += a;
add(ID[sum], -1);
}
printf("%lld", ans);
}
int main() {
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |