当前位置:网站首页>模板_求排列逆序对_基于归并排序
模板_求排列逆序对_基于归并排序
2022-07-06 02:06:00 【这题AC再睡.】
//
#include<bits/stdc++.h>
using namespace std;
#define int long long // 大数据量
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 ) 位置差
{
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;
}边栏推荐
- Grabbing and sorting out external articles -- status bar [4]
- 通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
- Card 4G industrial router charging pile intelligent cabinet private network video monitoring 4G to Ethernet to WiFi wired network speed test software and hardware customization
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Executing two identical SQL statements in the same sqlsession will result in different total numbers
- Apicloud openframe realizes the transfer and return of parameters to the previous page - basic improvement
- Virtual machine network, networking settings, interconnection with host computer, network configuration
- 【clickhouse】ClickHouse Practice in EOI
- vs code保存时 出现两次格式化
- Concept of storage engine
猜你喜欢

Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022

数据工程系列精讲(第四讲): Data-centric AI 之样本工程

Leetcode3, implémenter strstr ()

Extracting key information from TrueType font files

【机器人库】 awesome-robotics-libraries

Accelerating spark data access with alluxio in kubernetes

RDD partition rules of spark

0211 embedded C language learning

Campus second-hand transaction based on wechat applet

SQL statement
随机推荐
论文笔记: 图神经网络 GAT
插卡4G工业路由器充电桩智能柜专网视频监控4G转以太网转WiFi有线网速测试 软硬件定制
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
National intangible cultural heritage inheritor HD Wang's shadow digital collection of "Four Beauties" made an amazing debut!
Computer graduation design PHP animation information website
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Redis key operation
[solution] add multiple directories in different parts of the same word document
0211 embedded C language learning
Install redis
Tensorflow customize the whole training process
Minecraft 1.16.5 biochemical 8 module version 2.0 storybook + more guns
Global and Chinese market of wheelchair climbing machines 2022-2028: Research Report on technology, participants, trends, market size and share
Campus second-hand transaction based on wechat applet
selenium 元素定位(2)
Redis daemon cannot stop the solution
RDD conversion operator of spark
2022年版图解网络PDF
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
How to generate rich text online