当前位置:网站首页>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;
}
边栏推荐
- 零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
- 一位博士在华为的22年
- 【机器人手眼标定】eye in hand
- Concept of storage engine
- Sword finger offer 38 Arrangement of strings
- 更改对象属性的方法
- 好用的 JS 脚本
- Use image components to slide through photo albums and mobile phone photo album pages
- 模板_求排列逆序对_基于归并排序
- Adapter-a technology of adaptive pre training continuous learning
猜你喜欢
【无标题】数据库中一条查询SQL执行的过程
Use the list component to realize the drop-down list and address list
Initial understanding of pointer variables
Paper notes: graph neural network gat
It's wrong to install PHP zbarcode extension. I don't know if any God can help me solve it. 7.3 for PHP environment
MySQL lethal serial question 1 -- are you familiar with MySQL transactions?
02. Go language development environment configuration
2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition
Keyword static
零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO
随机推荐
How to generate rich text online
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
Regular expressions: examples (1)
RDD partition rules of spark
Have a look at this generation
I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
【无标题】数据库中一条查询SQL执行的过程
How does redis implement multiple zones?
LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
Online reservation system of sports venues based on PHP
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
Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
PHP campus movie website system for computer graduation design
Using SA token to solve websocket handshake authentication
通过PHP 获取身份证相关信息 获取生肖,获取星座,获取年龄,获取性别
Initial understanding of pointer variables
Compact lidar global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
Use image components to slide through photo albums and mobile phone photo album pages
The third level of C language punch in
Bidding promotion process