当前位置:网站首页>Template_ Find the reverse pair of permutations_ Sort based on merge
Template_ Find the reverse pair of permutations_ Sort based on merge
2022-07-06 02:21:00 【This question AC sleep again】
//
#include<bits/stdc++.h>
using namespace std;
#define int long long // Large amount of data
const int N=1e5+6;
int in[N];
int ans;
void merge( int x1,int y1,int x2,int y2 )
{
int tt[N];
int i=x1,j=x2,pos=0;
while( i<=y1 && j<=y2 ) // j-( x1+pos ) Position difference
{
if( in[i]<=in[j] ) tt[pos++]=in[i++];
else { ans+=j-( x1+pos ); tt[pos++]=in[j++]; }
}
while( i<=y1 ) tt[pos++]=in[i++];
while( j<=y2 ) tt[pos++]=in[j++];
for( i=0;i<pos;i++ ) in[x1+i]=tt[i];
}
void f( int x,int y )
{
if( x==y ) return ;
int mid=( x+y )>>1;
f( x,mid );
f( mid+1,y );
merge( x,mid,mid+1,y );
}
signed main()
{
int n,i;
while( cin>>n )
{
for( i=0;i<n;i++ ) cin>>in[i];
ans=0;
f( 0,n-1 );
cout<<ans<<endl;
}
return 0;
}边栏推荐
- Leetcode3, implémenter strstr ()
- leetcode3、實現 strStr()
- Genius storage uses documents, a browser caching tool
- RDD creation method of spark
- Sword finger offer 12 Path in matrix
- 01. Go language introduction
- Concept of storage engine
- Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
- Structural theme model (I) STM package workflow
猜你喜欢

【机器人库】 awesome-robotics-libraries

leetcode3、實現 strStr()

PHP campus movie website system for computer graduation design

Use image components to slide through photo albums and mobile phone photo album pages

Computer graduation design PHP campus restaurant online ordering system

Multi function event recorder of the 5th National Games of the Blue Bridge Cup

Executing two identical SQL statements in the same sqlsession will result in different total numbers
![[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning](/img/37/83953c24ec141667b304f9dac440f1.jpg)
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning

02. Go language development environment configuration

Initial understanding of pointer variables
随机推荐
一位博士在华为的22年
【社区人物志】专访马龙伟:轮子不好用,那就自己造!
[coppeliasim] efficient conveyor belt
vs code保存时 出现两次格式化
Adapter-a technology of adaptive pre training continuous learning
2022年版图解网络PDF
Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
How to set an alias inside a bash shell script so that is it visible from the outside?
PHP campus movie website system for computer graduation design
Overview of spark RDD
PAT甲级 1033 To Fill or Not to Fill
Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
ftp上传文件时出现 550 Permission denied,不是用户权限问题
Easy to use js script
【机器人库】 awesome-robotics-libraries
剑指 Offer 29. 顺时针打印矩阵
SSM 程序集
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
[depth first search notes] Abstract DFS
Audio and video engineer YUV and RGB detailed explanation