bzoj3524 Couriers 主席樹裸題

2021-08-17 20:44:12 字數 1128 閱讀 5340

許可權題

傳送門:

description

給乙個長度為n的序列a。1≤a[i]≤n。

m組詢問,每次詢問乙個區間[l,r],是否存在乙個數在[l,r]中出現的次數大於(r-l+1)/2。如果存在,輸出這個數,否則輸出0。

input

第一行兩個數n,m。

第二行n個數,a[i]。

接下來m行,每行兩個數l,r,表示詢問[l,r]這個區間。

output

m行,每行對應乙個答案。

sample input

7 5

1 1 3 2 3 4 3

1 31 4

3 71 7

6 6

sample output
103

04

**:

#include

using

namespace

std;

const

int maxn=5e5+5;

struct nodetree[maxn*20];

int m,n,tot;

int root[maxn];

inline

void update(int pre,int &cur,int l,int r,int x)

inline

int query(int pre,int cur,int l,int r,int k)

int mid=l+r>>1;

if(tree[tree[cur].ls].sum-tree[tree[pre].ls].sum>k)

return query(tree[pre].ls,tree[cur].ls,l,mid,k);

else

if(tree[tree[cur].rs].sum-tree[tree[pre].rs].sum>k)

return query(tree[pre].rs,tree[cur].rs,mid+1,r,k);

else

return0;}

int main()

for(int i=1;i<=m;i++)

return

0;}

Just h index(主席樹裸題)

just h index 題意 輸入第一行給了 n q 代表有 n 個數 q 次詢問,第二行給出這 n 個數,每次詢問乙個區間,答出乙個最大的數 h 使得這個區間裡大於等於 h 的數的個數大於等 h 題解 見 吧,比較好理解的,主席樹 ac code 1 主席樹是多個權值線段樹 2 include ...

BZOJ4571 美味(主席樹)

一家餐廳有 n 道菜,編號 1 n 大家對第 i 道菜的評價值為 ai 1 i n 有 m 位顧客,第 i 位顧客的期 望值為 bi,而他的偏好值為 xi 因此,第 i 位顧客認為第 j 道菜的美味度為 bi xor aj xi xor 表示異或 運算。第 i 位顧客希望從這些菜中挑出他認為最美味的...

bzoj5334(線段樹裸題)

description 小豆現在有乙個數x,初始值為1.小豆有q次操作,操作有兩種型別 1 m x x m 輸出 x mod 2 pos x x 第pos次操作所乘的數 保證第pos次操作一定為型別1,對於每乙個型別1 的操作至多會被除一次 輸出x mod input 一共有t組輸入 t 5 對於每...