当前位置:网站首页>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;
}边栏推荐
- 在线怎么生成富文本
- [depth first search] Ji Suan Ke: Betsy's trip
- Publish your own toolkit notes using NPM
- 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
- 500 lines of code to understand the principle of mecached cache client driver
- 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 hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
- How to improve the level of pinduoduo store? Dianyingtong came to tell you
- 2022 PMP project management examination agile knowledge points (8)
- Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
猜你喜欢
![[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

Using SA token to solve websocket handshake authentication

How to generate rich text online

Adapter-a technology of adaptive pre training continuous learning

Selenium waiting mode

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

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

Redis string type

Publish your own toolkit notes using NPM

Leetcode3, implémenter strstr ()
随机推荐
Selenium waiting mode
Gbase 8C database upgrade error
[solution] add multiple directories in different parts of the same word document
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
leetcode3、實現 strStr()
使用npm发布自己开发的工具包笔记
Bidding promotion process
Shutter doctor: Xcode installation is incomplete
Genius storage uses documents, a browser caching tool
Formatting occurs twice when vs code is saved
大厂镜像库
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
[depth first search] Ji Suan Ke: Betsy's trip
Extracting key information from TrueType font files
genius-storage使用文档,一个浏览器缓存工具
Use the list component to realize the drop-down list and address list
[eight part essay] what is the difference between unrepeatable reading and unreal reading?
Pangolin Library: subgraph
SSM assembly
Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械