时间管理
题意比较明显了。关键是维护gcd区间修改。
任老板直播的时候讲了:
在对一段区间做x变换后,下一次操作可能对区间内的数没有实质性的改变,比如如果区间内的数 全部变成1,无论什么数进行修改区间,区间的值不发生变化。具体怎么操作,维护了区间最大值和最小值,如果区间最大值=最小值=gcd(修改的值,最大值)那么说明本次修改对区间没有贡献,可以直接返回。然后指出这个算法不足之处比如对于2424242424242 这样的区间修改值=8虽然对区间没有贡献,但是最大值不等于最小值,所以依然要递归到叶子节点才能返回。
直播结束后任老板想到解决这个问题的方法,维护一个tag,tag记录该段区间的一个公倍数,对于某次修改如果修改值是tag的倍数说明,本次修改对区间无贡献。就可以return了
tag的维护:
对于某次修改后,该区间的一个公倍数为修改值,将这个修改值和原本的tag取gcd可以得到新的tag(小于等于原先的tag),区间全是1的tag=1,区间最大=最小=gcd的tag=最大
#include
#include
#include
#include
#include
#include
#include
#include
实际上tag写的好可以不用再维护最大值和最小值,将更新操作加上tag的更新,如果子区间tag值一致则更新,否则变成0
任老板官方修改后:
#include
#include
#include
#include
#include
#include
#include
#include