hdu 5877(樹狀陣列 離散化)

2021-08-06 02:26:47 字數 892 閱讀 1577

題意:查詢節點與它的父親節點相乘小於k的種類數。

思路:用乙個樹狀陣列維護,查詢的話就是它的父親節點小於k/a[i]的個數。當跑完這個分支之後,要對他進行清除操作。

ps:數比較大,需要離散化。

#include#include#include#include#include#include#include#include#includeusing namespace std;

#define clr(x,y) memset(x,y,sizeof x)

typedef long long ll;

const int maxn = 1e5 + 10;

ll a[maxn],b[maxn],c[maxn];

struct edgeedge[maxn*2];

int edge_num;

int in[maxn];

int head[maxn];

int tree[maxn];

ll ans;int n;ll m;int len;

inline int lowbit(int x)

void update(int x,int val)

int get(int x)

void dfs(int u)

update(c[u],-1);

}int main()

;head[x] = edge_num ++;

}int root;for(int i = 1; i <= n; i ++)if(!in[i])root = i;

clr(tree,0);

ans = 0;dfs(root);

printf("%i64d\n",ans);

}return 0;

}

HDU 3743 樹狀陣列,離散化

其實,我也知道這道題是求逆序數來做的,但是問題來了,怎麼求逆序數,常規的解法肯定是不行的,因為資料量很大,那麼想到能用線段樹來做,是可以的,不過我還沒敲過,既然在看樹狀陣列就用這個做。又因為資料可以達到一百萬,並且資料又用不到,所以可以對資料進行離散化 include include include...

離散化 樹狀陣列

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

hdu5542 樹狀陣列 離散化 dp

推薦 通過離散化 樹狀陣列 優化 include using namespace std const int mod 1e9 7 const int maxn 1e3 60 int s maxn 最初的陣列 int e maxn 排序後的書序 int num maxn 儲存 離散化後的位置 int ...