[HDU 6318] Swaps and Inversions】的更多相关文章

Swaps and Inversions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2315    Accepted Submission(s): 882 Problem Description Long long ago, there was an integer sequence a.Tonyfang think this se…
Swaps and Inversions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2787    Accepted Submission(s): 1071 Problem Description Long long ago, there was an integer sequence a.Tonyfang think this s…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=6318 Problem Description Long long ago, there was an integer sequence a.Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Because he is angry, you will ha…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6318 [算法] 线段树 / 树状数组 [代码] #include<bits/stdc++.h> using namespace std; #define MAXN 100010 long long i,n,x,y,len,ans,l,r,mid; long long a[MAXN],rk[MAXN],tmp[MAXN]; struct SegmentTree { struct Node { l…
题意:一个逆序对罚钱x元,现在给你交换的机会,每交换任意相邻两个数花钱y,问你最少付多少钱 思路:最近在补之前还没过的题,发现了这道多校的题.显然,交换相邻两个数逆序对必然会变化+1或者-1,那我们肯定是-1操作.那么显然问题就变成了求逆序对数*min(x,y).树状数组求逆序对数. 代码: #include<set> #include<map> #include<stack> #include<cmath> #include<queue> #i…
6318.Swaps and Inversions 这个题就是找逆序对,然后逆序对数*min(x,y)就可以了. 官方题解:注意到逆序对=交换相邻需要交换的次数,那么输出 逆序对个数 即可. 求逆序对有4种操作,线段树 .BIT.归并排序.树状数组. 我敲了线段树.归并排序和树状数组版的. 关于这几种方法求逆序对,自行百度吧,懒了... 代码(线段树版-注意排序): //1010-找逆序对数-线段树求逆序对数 #include<iostream> #include<cstdio>…
Swaps and Inversions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3588    Accepted Submission(s): 976 Problem Description Long long ago, there was an integer sequence a.Tonyfang think this se…
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> using namespace std; typedef long long ll; ; int a[N]; int ra[N]; int tr[N]; int n,x,y; int sz; int lowbit(int x) { return x&-x; } void add(int x,int c)…
Long long ago, there was an integer sequence a.Tonyfang think this sequence is messy, so he will count the number of inversions in this sequence. Because he is angry, you will have to pay x yuan for every inversion in the sequence.You don't want to p…
题意: 给定一串数组,其中含有一个逆序对则需要花费x,交换相邻两个数需要花费y,输出最小花费. n<=1e5,-1e9<=a[i]<=1e9 思路: #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<iostream> #include<algorithm> #include<map> #include…