Flowers 樹狀陣列 離散化

2021-06-08 06:11:51 字數 608 閱讀 2035

題意:給你一些花,以及這些花開花的時間,問你在某一時間開花的總個數~~,很明顯的樹狀陣列題,插線問點。。

ac**:

#include#include#include#include#include#define n 1000005

using namespace std;

typedef struct node

node;

bool cmp(node a,node b)

return ans;

}int main()

sort(s1,s1+res,cmp);

int ans=0;

s2[s1[0].id]=++ans;

for(int i=1;i!=res;++i)

if(s1[i].num!=s1[i-1].num) s2[s1[i].id]=++ans;

else s2[s1[i].id]=ans;

for(int i=0;i!=tot;)

printf("case #%d:\n",k);

for(int i=tot;i!=res;++i)

}return 0;

}

離散化 樹狀陣列

題目描述 erwin最近對一種叫 thair 的東西巨感興趣。在含有n個整數的序列a1,a2 an中,三個數被稱作 thair 當且僅當i求乙個序列中 thair 的個數。輸入格式 開始乙個正整數n,以後n個數a1 an。輸出格式 thair 的個數 思路 列舉中間的數字,求排在它前面,小於它的有幾...

排序(離散化 樹狀陣列)

題目 資料範圍大,交換相鄰的的樹,使有序 解題說明 關鍵是知道,每個數交換的次數是其前面比它大的樹的個數。用樹狀陣列維護一下 ac include include include includeusing namespace std typedef long long ll const int ma...

樹狀陣列 (離散化 樹狀陣列 求逆序對)

sample test s input 52 3 1 5 4 output 3 題目大意 求逆序對的個數 題目分析 求逆序對有很多方法,比如說用合併排序 分治 樹狀陣列 線段樹,甚至連暴力 氣泡排序 也可以做,但是要注意會不會超時。這裡就講一下樹狀陣列的方法,這一題最有意思的是離散化的方法,這個方法...