題目:
資料範圍大,交換相鄰的的樹,使有序
解題說明:關鍵是知道,每個數交換的次數是其前面比它大的樹的個數。用樹狀陣列維護一下~
ac**:
#include#include#include#includeusing namespace std;
typedef long long ll;
const int maxn=500010;
mapmp;
int be[maxn];
int temp[maxn];
int c[maxn];
int get(int x)
void modify(int x,int sum)
int main()
sort(temp,temp+n);
int m=unique(temp,temp+n)-temp;
for(int i=0;i
離散化 樹狀陣列
題目描述 erwin最近對一種叫 thair 的東西巨感興趣。在含有n個整數的序列a1,a2 an中,三個數被稱作 thair 當且僅當i求乙個序列中 thair 的個數。輸入格式 開始乙個正整數n,以後n個數a1 an。輸出格式 thair 的個數 思路 列舉中間的數字,求排在它前面,小於它的有幾...
Flowers 樹狀陣列 離散化
題意 給你一些花,以及這些花開花的時間,問你在某一時間開花的總個數 很明顯的樹狀陣列題,插線問點。ac include include include include include define n 1000005 using namespace std typedef struct node n...
樹狀陣列 (離散化 樹狀陣列 求逆序對)
sample test s input 52 3 1 5 4 output 3 題目大意 求逆序對的個數 題目分析 求逆序對有很多方法,比如說用合併排序 分治 樹狀陣列 線段樹,甚至連暴力 氣泡排序 也可以做,但是要注意會不會超時。這裡就講一下樹狀陣列的方法,這一題最有意思的是離散化的方法,這個方法...