# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
444182 | blue | Vudu (COCI15_vudu) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
long long* a;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
a = new long long[N+1];
a[0] = 0;
for(int i = 1; i <= N; i++) cin >> a[i];
long long P;
cin >> P;
for(int i = 1; i <= N; i++)
{
a[i] = a[i-1] + (a[i] - P);
}
//Count number of (i, j) such that i < j and a[i] < a[j]
int I[N+1];
for(int i = 0; i <= N; i++) I[i] = i;
sort(I, I+N+1, [] (int x, int y)
{
if(a[x] == a[y]) return x < y;
else return a[x] < a[y];
});
vector<long long> BIT(2+N, 0);
long long res = 0;
for(int i:I)
{
for(int j = (i+1)-1; j >= 0+1; j -= j&-j)
res += BIT[j];
for(int j = (i+1); j <= N+1; j += j&-j)
BIT[j] += 1;
}
cout << res << '\n';
}