Why the Cows Climbed onto the Information Island
Time limit2sMemory limit256 MB
On a circle of N values, each query flips one value's sign; after every query print the sum of products over all N windows of four consecutive cows.
- Level
Medium6 of 10
- Topics
- Implementation, Math, Array, Brute force
- Solved
- No attempts yet
Problem
cows have climbed onto the Information Island!
The cows are resting in the front yard on the first floor of the Information Island, sitting in a circle in the order . Each cow has a sticker with a quality score on it. Next to the herd, Ukje found a formula that Hyobin had worked out, and it looks like this.
(where )
In words, for the cows sitting in a circle, it is the sum of the products of the quality scores of every four consecutive cows.
Ukje plans to be mean so that Hyobin cannot leave school. Over rounds, Ukje will pick some -th cow. Then he will peel off the sticker with and stick on a sticker with . Hyobin then has to recompute times. A sticker stays swapped until it gets swapped again later.

You, Hyobin's best friend, have decided to help Hyobin, who is being tormented by the troublemaker Ukje. Help Hyobin compute !
Input
The first line gives , the number of cows, and , the number of times Ukje will play his trick.
The second line gives the quality scores of the cows in order.
The third line gives the cow indices that Ukje will pick, in order.
Output
Over lines, print the recomputed value of .