文章分类 -  线段树

摘要:对于数组A,A[i]的逆序对数量为i之前比它大的数的个数。如果已经知道A中的最大值max,当我们顺序的去求A[i]的逆序对的数量的时候,其实就是找此时A中i之前A[i]到max的数有多少个。当然,对于求区间内的事情,树状数组和线段树是最为擅长的。一下代码仅仅考虑A中的元素为整数的情况,如果数太大者有double的情形需要先离散化处理。#include #include #include #include using namespace std;struct Node { Node(int h, int t) : head(h), tail(t), left(NULL), right(NULL. 阅读全文
posted @ 2013-08-25 19:23 dmthinker 阅读(605) 评论(0) 推荐(0)