P3932 island 68 on the floating continent
The storage points of the goblin warehouse can be seen on a digital axis. Each storage point has something and there is a distance between them.
Each time they select a goblin, and the rest of the people will find all the items in the [L, R] storage point. After checking the items, they will ask her, what is the cost of shipping all the stored items in this interval to another warehouse?
For example, the storage point I has x items and needs to be shipped to the storage point J. The price is
\ [X \ times \ mathrm {Dist} (I, j) \]
DIST is the distance between warehouses.
Of course, since the little fairies don't calculate a lot of numbers, You Need To modulo 19260817 for your answer.
Error Log: The question modulo is too malignant(Actually because-1 s)
Solution
Line Segment tree
The total maintenance interval size of each line segment Tree node. The cost of moving items to the left and right endpoints
Then the merge is obvious. Move the object to the sub-endpoint and then simulate moving it over the range.
About inquiry
If the vertex \ (x \) is out of the range, we will discuss the situation on the left and on the right, and find out who minus the coordinates.
If the point \ (x \) is broken at \ (x \) within the interval, it is equivalent to two previous cases.
Use the \ (dalao \) Code for the first time.
This is also the first time I have seen the model of this cancer.
One sentence that references the question,Modulo all the operations you can think
Code
# Include <iostream> # include <cstdio> # include <queue> # include <cstring> # include <algorithm> # include <climits> # define ll long # define rep (I, x, Y) for (ll I = (x); I <= (y); I ++) using namespace STD; ll RD () {ll out = 0, flag = 1; char c = getchar (); While (C <'0' | C> '9') {If (C = '-') flag =-1; C = getchar () ;}while (C >='0' & C <= '9 ') {out = out * 10 + C-'0'; C = getchar ();} return flag * out;} const ll maxn = 400019, M = 19260817; ll num, NA; ll p [maxn], V [maxn]; # define lid (ID <1) # define RID (ID <1) | 1 struct seg_tree {ll l, r; ll p [2]; // ll sum; ll move [2]; // move left and right end point position} tree [maxn <2]; void pushup (ll id) {tree [ID]. sum = (tree [lid]. sum + tree [RID]. sum) % m + M) % m; tree [ID]. P [0] = tree [lid]. P [0]; tree [ID]. P [1] = tree [RID]. P [1]; tree [ID]. move [0] = (tree [lid]. move [0] + tree [RID]. move [0]) % m + M) % m + (tree [RID]. sum * (tree [RID]. P [0]-tree [lid]. P [0]) % m + M) % m; tree [ID]. move [0] = (tree [ID]. move [0] % m + M) % m; tree [ID]. move [1] = (tree [RID]. move [1] + tree [lid]. move [1]) % m + M) % m + (tree [lid]. sum * (tree [RID]. P [1]-tree [lid]. P [1]) % m + M) % m; tree [ID]. move [1] = (tree [ID]. move [1] % m + M) % m;} void build (ll id, ll l, ll R) {tree [ID]. L = L, tree [ID]. R = r; If (L = r) {tree [ID]. P [0] = tree [ID]. P [1] = P [l]; tree [ID]. sum = V [l]; tree [ID]. move [0] = tree [ID]. move [1] = 0; return;} ll mid = (L + r)> 1; build (lid, L, mid), build (RID, Mid + 1, r); pushup (ID);} seg_tree query (ll id, ll l, ll R) {If (tree [ID]. L = L & tree [ID]. R = r) return tree [ID]; ll mid = (tree [ID]. L + tree [ID]. r)> 1; if (mid <L) return query (RID, L, R); else if (mid> = r) return query (lid, L, R ); else {seg_tree ret, L = query (lid, L, mid), r = query (RID, Mid + 1, R); ret. sum = (L. sum + R. sum) % m + M) % m; ret. P [0] = L. P [0]; ret. P [1] = R. P [1]; ret. move [0] = (L. move [0] + R. move [0]) % m + M) % m + (R. sum * (R. P [0]-l. P [0]) % m + M) % m; ret. move [0] = (Ret. move [0] % m + M) % m; ret. move [1] = (R. move [1] + L. move [1]) % m + M) % m + (L. sum * (R. P [1]-l. P [1]) % m + M) % m; ret. move [1] = (Ret. move [1] % m + M) % m; return ret ;}} void Init () {num = RD (), Na = RD (); P [1] = 1; rep (I, 2, num) P [I] = P [I-1] + RD (); rep (I, 1, num) V [I] = RD () % m; build (1, 1, num);} void solve () {While (Na --) {ll x = RD (), L = RD (), r = RD (); If (x <= L) {seg_tree ans = query (1, L, R); LL output = ans. move [0] + (ans. sum * (ans. P [0]-P [x]) % m + M) % m; printf ("% LLD \ n ", (output % m + M) % m);} else if (x> = r) {seg_tree ans = query (1, L, R); LL output = ans. move [1] + (ans. sum * (P [x]-ans. P [1]) % m + M) % m; printf ("% LLD \ n", (output % m + M) % m);} else {seg_tree ans = query (1, L, x); LL output = ans. move [1] + (ans. sum * (P [x]-ans. P [1]) % m + M) % m; Output = (output % m + M) % m; ans = query (1, x, R); Output = (output + ans. move [0]) % m + M) % m + (ans. sum * (ans. P [0]-P [x]) % m + M) % m; printf ("% LLD \ n ", (output % m + M) % m) ;}} int main () {Init (); solve (); Return 0 ;}
P3932 island 68 on the floating continent