【分治-字首積字尾積】JS Window @2018acm徐州邀請賽G
阿新 • • 發佈:2018-12-24
JSZKC has an array A of N integers. More over, he has a Window of length M which means the Window can contain M continuous integers in the array.
At the begging, the Window is at the position 1 which means the Window contains the integers from position 1 to position M. Each time the Window move right by one until it reach the end. So after one move, the window contains position 2 to position M+1.
At each place, we can multiply all the integers in the window. Please calculate the product mod P at each position. As the output maybe very large, you should output the sum of these product.
For example, if the array is”2 3 7 11 13” with m=3 and P=5. So the product at position 1 is 2, at position 2 is 1 and at position 3 is 1. 2+1+1=4. So you should output 4.
At the begging, the Window is at the position 1 which means the Window contains the integers from position 1 to position M. Each time the Window move right by one until it reach the end. So after one move, the window contains position 2 to position M+1.
At each place, we can multiply all the integers in the window. Please calculate the product mod P at each position. As the output maybe very large, you should output the sum of these product.
For example, if the array is”2 3 7 11 13” with m=3 and P=5. So the product at position 1 is 2, at position 2 is 1 and at position 3 is 1. 2+1+1=4. So you should output 4.