# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
462602 | Hamed5001 | Vudu (COCI15_vudu) | C++14 | 1100 ms | 58996 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;
map<int, int> ID;
int id = 1;
const int mxN = 1e6+100;
int BIT[mxN];
void add(int idx, int delta) {
for (; idx < id; idx += idx & -idx)
BIT[idx] += delta;
}
int query(int idx) {
int ret = 0;
for (; idx > 0; idx -= idx & -idx)
ret += BIT[idx];
return ret;
}
void solve() {
int N, P;
cin >> N;
vector<int> A(N); for (auto& a : A) cin >> a;
cin >> P;
for (auto& a : A) a-=P;
vector<int> AA;
int sum = 0;
for (auto a : A) {
sum += a;
AA.push_back(sum);
}
sort(AA.rbegin(), AA.rend());
ID[0] = id++;
for (int i = 0; i < AA.size(); ++i) {
if (!ID[AA[i]])
ID[AA[i]] = id++;
}
for (auto aa : AA) {
add(ID[aa], 1);
}
// cout << query(3) << endl;
// for (auto& [a, b] : ID) {
// cout << a << ' ' << b << endl;
// }
sum = 0;
ll ans = 0;
for (auto a : A) {
int sumid = ID[sum];
ans += query(sumid);
sum += a;
add(sumid, -1);
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |