# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
87480 | zoooma13 | Vudu (COCI15_vudu) | C++14 | 1079 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;
#define MAX_N 1000006
int N;
long long A[MAX_N];
int P;
int bit[MAX_N];
int query(int idx){
int ret = 0;
for(int i=idx+1; i; i-=(i&-i))
ret += bit[i];
return ret;
}
void update(int idx){
for(int i=idx+1; i<=N+5; i+=(i&-i))
bit[i] += 1;
}
int main()
{
scanf("%d",&N);
for(int i=1; i<=N; i++)
scanf("%d",&A[i]);
scanf("%d",&P);
map <long long ,int> mp;mp[0];
for(int i=1; i<=N; i++){
A[i] += A[i-1]-P;
mp[A[i]];
}
int id = 0;
for(auto&i : mp)
i.second = id++;
for(int i=0; i<=N; i++)
A[i] = mp[A[i]];
long long ans = 0;
for(int i=0; i<=N; i++){
ans += query(A[i]);
update(A[i]);
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |