摘要:
士兵杀敌(二)时间限制:1000 ms | 内存限制:65535 KB难度:5描述南将军手下有N个士兵,分别编号1到N,这些士兵的杀敌数都是已知的。小工是南将军手下的军师,南将军经常想知道第m号到第n号士兵的总杀敌数,请你帮助小工来回答南将军吧。南将军的某次询问之后士兵i可能又杀敌q人,之后南将军再询问的时候,需要考虑到新增的杀敌数。输入只有一组测试数据第一行是两个整数N,M,其中N表示士兵的个数(1<N<1000000),M表示指令的条数。(1<M<100000)随后的一行是N个整数,ai表示第i号士兵杀敌数目。(0<=ai<=100)随后的M行每行是一条 阅读全文
摘要:
一、插点问线,如“士兵杀敌(二)”要向上修改,向下统计;一般是修改某个位置上的值,查找的是一段区间的和;二、插线问点,如“士兵杀敌(四)”要向上统计,向下修改;一般是修改一段区间的值,查找的是某个位上的值;下图中的C数组就是树状数组,a数组是原数组可以发现这些规律C1=a1C2=a1+a2C3=a3C4=a1+a2+a3+a4C5=a5……C8=a1+a2+a3+a4+a5+a6+a7+a8……C2^n=a1+a2+….+a2^n对于序列a,一个(树状)数组C定义C[i] = a[i – 2^k + 1] + … + a[i],k为i在二进制下末尾0的个数。以上可以看出:设节点编号为i,那么这 阅读全文
摘要:
Problem DescriptionWe all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China! “Oh, God! How terrible! ”Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden 阅读全文
摘要:
hdu 1938Problem DescriptionPeople in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Si 阅读全文