poj 2828 線段樹插孔處理

2021-07-02 12:23:03 字數 1132 閱讀 9633

給你乙個數列出現的先後順序num【i】和對應數值   輸出最後排好序的對應數值,如

4

0 77

1 51

1 33

2 69

第一步  77

第二部 77  51

第三步 77  33 51

第四部77  33  69 51

後面先出現的位置是固定的  所以從後往前處理。 線段樹每個節點存當前區間還有多少個空位;

#include

#include

#include

using

namespace std;

#define

ll(x)

(x<<1)

#define

rr(x)

((x<<1)|

1)struct

node

tree[4*

200000

];int num[

200010][3

],queue[

200010

];int

deal

(int l,

int r,

int point)

intupdate

(int l,

int r,

int pos,

int point,

int value)

int mid=(l+r)/2;

if(pos<=tree[

ll(point)].cont)

update

(l,mid,pos,

ll(point),value);

else

update

(mid+1

,r,pos-tree[

ll(point)].cont,

rr(point),value);

return0;

}int

main

()for

(i=n;i>=

1;i--)

for(i=

1;i<=n;i++)

printf("

\n");}

return0;

}

線段樹典型例題 poj2828

逆序處理。注意到如果逆序插入,則每次插入的位置都是第x個空位。所以可以用線段樹來尋找第x個合法位置 include include include include include using namespace std const int n 200005 int sum n 3 pos n val...

poj2828 線段樹好題

題目意思是一群人排隊買票,然後後面乙個乙個的來人插隊,每個人都有乙個特殊的編號,每次告訴你他插在第幾個人的後面,問最後這串人的數字串最後是什麼。如果模擬來搞的話每次要乙個乙個的挪動人,最差的情況下每個人的位置都要變,是o n 2 的,200000的資料顯然是搞不動。正著思考麻煩的時候可以試著反向來思...

poj 2828 線段樹 單點更新

題意 有n個人排隊,每乙個人都有乙個val來對應,每乙個後來人都會插入當前隊伍的某乙個位置pos後面。要求把隊伍最後的狀態輸出。題解 一看到這種題目如果之前做過類似的題目很容易就可以想到要倒序完成 因為這樣每個數插入的位置在當前都是可以確定的,sum記錄當前線段的空位數 include includ...