当前位置:网站首页>模板_求排列逆序对_基于归并排序
模板_求排列逆序对_基于归并排序
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;
}边栏推荐
- leetcode-2.回文判断
- The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
- How to improve the level of pinduoduo store? Dianyingtong came to tell you
- Selenium element positioning (2)
- How to use C to copy files on UNIX- How can I copy a file on Unix using C?
- Computer graduation design PHP college classroom application management system
- PHP campus movie website system for computer graduation design
- I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
- Grabbing and sorting out external articles -- status bar [4]
- [width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
猜你喜欢

Open source | Ctrip ticket BDD UI testing framework flybirds

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

Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail

SQL statement

Leetcode3, implémenter strstr ()

Computer graduation design PHP campus restaurant online ordering system

在线怎么生成富文本

Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail

SPI communication protocol

2022 edition illustrated network pdf
随机推荐
Competition question 2022-6-26
[depth first search] Ji Suan Ke: Betsy's trip
This time, thoroughly understand the deep copy
Overview of spark RDD
Global and Chinese markets of screw rotor pumps 2022-2028: Research Report on technology, participants, trends, market size and share
NLP fourth paradigm: overview of prompt [pre train, prompt, predict] [Liu Pengfei]
leetcode3、实现 strStr()
Online reservation system of sports venues based on PHP
729. My schedule I / offer II 106 Bipartite graph
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
Computer graduation design PHP enterprise staff training management system
Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
Unity learning notes -- 2D one-way platform production method
机器学习训练与参数优化的一般过程 (讨论)
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
MySQL index
RDD creation method of spark
How to use C to copy files on UNIX- How can I copy a file on Unix using C?
How does redis implement multiple zones?
Formatting occurs twice when vs code is saved