当前位置:网站首页>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;
}边栏推荐
- Unity learning notes -- 2D one-way platform production method
- How to use C to copy files on UNIX- How can I copy a file on Unix using C?
- 我把驱动换成了5.1.35,但是还是一样的错误,我现在是能连成功,但是我每做一次sql操作都会报这个
- The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
- Social networking website for college students based on computer graduation design PHP
- Computer graduation design PHP college student human resources job recruitment network
- 论文笔记: 极限多标签学习 GalaXC (暂存, 还没学完)
- 构建库函数的雏形——参照野火的手册
- Multi function event recorder of the 5th National Games of the Blue Bridge Cup
- 抓包整理外篇——————状态栏[ 四]
猜你喜欢

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

leetcode3、實現 strStr()

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

Derivation of Biot Savart law in College Physics

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

2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition

02. Go language development environment configuration

Keyword static

HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
随机推荐
Concept of storage engine
Online reservation system of sports venues based on PHP
SQL statement
Install redis
【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)
I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
Have a look at this generation
[solution] every time idea starts, it will build project
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
Spark accumulator
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
Derivation of Biot Savart law in College Physics
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
How to set an alias inside a bash shell script so that is it visible from the outside?
模板_快速排序_双指针
genius-storage使用文档,一个浏览器缓存工具
Global and Chinese markets of nasal oxygen tubes 2022-2028: Research Report on technology, participants, trends, market size and share
有没有sqlcdc监控多张表 再关联后 sink到另外一张表的案例啊?全部在 mysql中操作
使用npm发布自己开发的工具包笔记
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!