# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
81587 | chelly | Vudu (COCI15_vudu) | C++11 | 440 ms | 66560 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;
int N, P;
long long int ar[1000001];
int p[1000001], bit[1000002];
int query(int pos) {
int ans = 0;
for(int i = pos; i>0; i -= i&-i) ans += bit[i];
return ans;
}
int update (int pos){
for(int i = pos; i<=N+1; i += i&-i) bit[i]++;
}
bool cmp (int x, int y) { return ar[x] < ar[y]||(ar[x]==ar[y]&&x<y); }
int main () {
scanf("%d", &N);
for(int i = 1; i <= N; i++) scanf("%lld", ar + i);
scanf("%d", &P);
for(int i = 1; i <= N; i++)
ar[i] += ar[i-1] - P;
for(int i = 0; i <= N; i++)
p[i] = i;
sort(p, p + N + 1, cmp);
long long int ans = 0;
for(int i = 0; i <= N; i++){
ans += query(p[i] + 1);
update (p[i]+1);
}
printf("%lld\n", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |