关于退役这档事
查看原帖
关于退役这档事
147999
Warriors_Cat楼主2020/12/7 13:10

RT

某位小同学在考场上做这题时打了一个平平常常的树状数组。

struct BIT{
	int t[N];
	inline void Clear(){ memset(t, 0, sizeof(t)); }
	inline int lb(int x){ return x & -x; }
	inline void chnge(int x, int y){ for(; x <= 30; x += lb(x)) t[x] += y; }
	inline int qery(int x){ int ans = 0; for(; x; x -= lb(x)) ans += t[x]; return ans; }
}Tree; 

他并没有觉得有什么问题,可赛后,他发现自己崩了。

这个树状数组应该这么写:

struct BIT{
	int t[30];
	inline void Clear(){ memset(t, 0, sizeof(t)); }
	inline int lb(int x){ return x & -x; }
	inline void chnge(int x, int y){ for(; x <= 30; x += lb(x)) t[x] += y; }
	inline int qery(int x){ int ans = 0; for(; x; x -= lb(x)) ans += t[x]; return ans; }
}Tree; 

于是这位同学成功从 O(26log26Tnlnn)O(26\log 26Tn\ln n) 变成了 O(log26Tn2lnn)O(\log 26Tn^2\ln n)84pts84 pts 成功沦为 56pts56pts,1= 即将变 2=。

希望各位不要重蹈覆辙。

2020/12/7 13:10
加载中...