当前位置:网站首页>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;
}
边栏推荐
- Executing two identical SQL statements in the same sqlsession will result in different total numbers
- LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
- Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
- Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
- 0211 embedded C language learning
- Using SA token to solve websocket handshake authentication
- Gbase 8C database upgrade error
- Competition question 2022-6-26
- 论文笔记: 图神经网络 GAT
- Campus second-hand transaction based on wechat applet
猜你喜欢
Using SA token to solve websocket handshake authentication
SPI communication protocol
How to improve the level of pinduoduo store? Dianyingtong came to tell you
Redis如何实现多可用区?
Extracting key information from TrueType font files
[depth first search] Ji Suan Ke: Betsy's trip
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
在线怎么生成富文本
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
Use image components to slide through photo albums and mobile phone photo album pages
随机推荐
Use the list component to realize the drop-down list and address list
剑指 Offer 29. 顺时针打印矩阵
Get the relevant information of ID card through PHP, get the zodiac, get the constellation, get the age, and get the gender
Gbase 8C database upgrade error
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
Xshell 7 Student Edition
Easy to use js script
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
How to use C to copy files on UNIX- How can I copy a file on Unix using C?
Bigder:34/100 面试感觉挺好的,没有收到录取
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
零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO
FTP server, ssh server (super brief)
RDD conversion operator of spark
2022 PMP project management examination agile knowledge points (8)
sql表名作为参数传递
有没有sqlcdc监控多张表 再关联后 sink到另外一张表的案例啊?全部在 mysql中操作
PHP campus financial management system for computer graduation design
Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail