| TheForces Round #39 (1000-Forces) |
|---|
| Закончено |
This is the hard version of this problem. In this version, you need to answer multiple queries.
Wuhudsm got irritated because Sanjay kept proposing too many questions to him. So Wuhudsm decided to give Sanjay a tough question. Wuhudsm told Sanjay that he cannot ask any more questions until he solves this one. Since he had no friends, he handed it over to you. Please solve it for him.
Given an array $$$a$$$ of length $$$n$$$, the cost $$$c$$$ is defined as:
$$$$$$ c = a_1 \cdot 1 + a_2 \cdot 2 + \dots + a_{n} \cdot n $$$$$$
You are given $$$q$$$ queries of two types:
A left cyclic shift operation moves each element of the array one position to the left, with the first element moving to the end.
For example, $$$$$$ a = [1, 2, 3, 4] \quad$$$$$$ after one left shift becomes $$$$$$a = [2, 3, 4, 1] $$$$$$
The sum of $$$n$$$ and $$$q$$$ across all test cases does not exceed $$$10^5$$$.
For each query of type $$$2$$$, print the answer to this query in a new line.
241 2 3 432 21 1 52 331 -1 132 21 3 -10000000002 1000000000
22 32 0 -1999999998
In the first query of the first test case, if the array $$$a$$$ is left shifted $$$2$$$ times, $$$a=[3, 4, 1, 2]$$$.
We get $$$ c = 3 \cdot 1 + 4 \cdot 2 + 1 \cdot 3 + 2 \cdot 4 = 3 + 8 + 3 + 8 = 22 $$$.
| Название |
|---|


