# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968099 | vjudge1 | Vudu (COCI15_vudu) | C++17 | 199 ms | 31716 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 <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
using pii = pair<ll, int>;
#define fr first
#define se second
const int N = 1e6+2;
ll n, a[N], fw[N];
pii qs[N];
void upd(int i){
for (;i < N;i+=i&-i) fw[i]++;
}
ll qry(int i, ll res = 0){
for (;i;i-=i&-i) res += fw[i]; return res;
}
int main()
{
ll p, ans = 0; scanf("%lld", &n);
for (int i = 1;i <= n;i++) scanf("%lld", a+i);
scanf("%lld", &p);
for (int i = 1;i <= n;i++) a[i] -= p;
for (int i = 1;i <= n;i++) qs[i] = {a[i]+qs[i-1].fr, i};
sort(qs+1, qs+n+1);
for (int i = 1;i <= n;i++){
int x = qs[i].se;
ans += qry(x); upd(x);
ans += qs[i].fr >= 0;
}
printf("%lld", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |