鏈結自己找,bzoj還沒開
也很顯然是點分樹維護,對每個點開兩個樹狀陣列,維護點分樹上子樹之和,然後修改詢問仍然暴力爬樹,詢問也是用兩個樹狀陣列作差消掉當前子樹影響
code:
#include
using
namespace std;
inline
intread()
while
(isdigit
(ch)
)return res*f;
}const
int n=
1e5+
5,inf=
1e9;
struct heap
inline
void
erase
(int x)
inline
void
pop(
)inline
inttop()
inline
intsize()
inline
intsecond()
}ans,now[n]
,up[n]
;int vis[n<<1]
,head[n]
,nxt[n<<1]
,tot=0;
inline
void
add(
int x,
int y)
int dp[n]
,fa[n][20
],siz[n]
,pt[n]
;int sum,rt;
void
getroot
(int v,
int f)
dp[v]
=max
(dp[v]
,sum-siz[v]);
if(dp[v]
) rt=v;
}vector<
int>tr1[n]
,tr2[n]
;int d[n]
,dis[n][20
];void
getship
(int v,
int anc,
int f,
int dd)
}void
buildtree
(int v)
}inline
intlb
(int x)
int val[n]
;inline
intqsum1
(int x,
int y)
inline
intqsum2
(int x,
int y)
inline
intquery
(int x,
int k)
inline
void
change
(int x,
int v)
}int
main()
dp[0]
=inf;sum=n;
getroot(1
,0);
buildtree
(rt)
;for
(int i=
1;i<=n;i++
) fa[i]
[d[i]+1
]=i;
for(
int i=
1;i<=n;i++
)change
(i,val[i]);
int ans=0;
while
(m--
)return0;
}
bzoj3730 震波(點分樹 bit)
傳送門 點分樹板題。然而並沒有遇到卡常之類的事。對於分出來的每一層用兩棵bit bitbi t動態維護到自己距離不超過k kk的與到自己點分樹父親距離不超過k kk的點數。include define ri register int using namespace std const int rle...
點分樹 樹狀陣列 BZOJ 3730 震波
線段樹t成翔 只能用vector寫bit 痛苦的回憶啊 思路不難想 先建出點分樹 然後每個點對於他掌管的點的距離與權值建成bit 然後每次查詢就是爬點分樹 這裡有點注意 往樹上爬的時候不能中途break,不會因為有乙個祖先爬不上去就終止,說不定有乙個爺爺比爸爸還近 include include i...
BZOJ3730 震波 動態點分治
include include include include include include define space putchar define enter putchar n using namespace std typedef long long ll template void rea...