hiho~
역순 대 누 드 문제
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LowBit(x) ((x)&(-(x)))
const int MAXN = 100005;
int n,nn;
int a[MAXN] = {0},b[MAXN] ={0};
int sum[MAXN] = {0};
long long ans = 0;
void insert(int x)
{
while(x <= n)
{
sum[x] ++; x += LowBit(x);
}
}
int count(int x)
{
int ret = 0;
while(x > 0)
{
ret += sum[x]; x-=LowBit(x);
}
return ret;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("hiho.in","r",stdin);
freopen("hiho.out","w",stdout);
#endif
scanf("%d",&n);
for(int i = 1; i <= n ;i++)
{scanf("%d",&a[i]); b[i] = a[i];}
std::sort(b + 1, b + n + 1);
nn = std::unique(b + 1,b + n + 1)- (b + 1);
for(int i = 1; i <= n; i++)
{
static int bi;
bi = std::lower_bound(b + 1, b + nn + 1,a[i]) - b;
ans += count(n) - count(bi); insert(bi);
}
std::cout << ans;
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
hiho~hihoCoder You can use the the following accounts to login directly or use hihoCoder account( or ) Email Password Login h...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.