luogu#P5009. [yLOI2018] 不老梦

[yLOI2018] 不老梦

Background

Among tens of thousands, by great luck we meet; in an instant, everything becomes clear and bright.
It becomes my courage and fear that make me unstoppable, splitting mountains and seas, falling into the sky.

— Yin Lin, Ageless Dream.

The original name of this problem was Poisonous Block Decomposition Problem.

Problem Description

Fusu really likes writing tricky block decomposition problems while listening to Chinese-style songs. So this statement is intentionally designed to make block decomposition hard to use.

You are given a sequence. Each number in the sequence has three parameters vi,ai,biv_i, a_i, b_i. This sequence has a very magical time-related property: every time moment passes, the value viv_i of the ii-th number increases by ai×bia_i \times b_i.

Now Fusu will ask you some queries and perform some modifications on the sequence. Each operation is one of the following:

  • Query: at time tt, what is the sum of vv over the interval [l,r][l, r].
  • Modify aa: at time tt, add an integer xx to all aa in the interval [l,r][l, r].
  • Modify bb: at time tt, add an integer yy to all bb in the interval [l,r][l, r].
  • Modify vv: at time tt, add an integer zz to all vv in the interval [l,r][l, r].

The initial time is defined as time 00.

Input Format

Each test point has exactly one set of testdata.

The first line contains two integers separated by spaces, representing the length of the sequence nn and the number of operations mm.

The next nn lines each contain 33 integers separated by spaces. On the ii-th line, the integers vi,ai,biv_i, a_i, b_i represent the three parameters at position ii.

The next mm lines describe the operations. The first number of each line is optopt, representing the type of operation.

  • For opt=1opt = 1, it means one query on the sequence. After optopt there are three integers t,x,yt, x, y separated by spaces, meaning: query the sum of vv in interval [x,y][x, y] at time tt.
  • For opt=2opt = 2, it means one modification to the aa values. After optopt there are four integers t,x,y,zt, x, y, z separated by spaces, meaning: at time tt, add zz to all aa in interval [x,y][x, y].
  • For opt=3opt = 3, it means one modification to the bb values. After optopt there are four integers t,x,y,zt, x, y, z separated by spaces, meaning: at time tt, add zz to all bb in interval [x,y][x, y].
  • For opt=4opt = 4, it means one modification to the vv values. After optopt there are four integers t,x,y,zt, x, y, z separated by spaces, meaning: at time tt, add zz to all vv in interval [x,y][x, y].

The data guarantees that the parameter tt is strictly increasing, and there will not be more than one query or modification at the same time moment.

Output Format

For each query operation, output one integer per line, representing the answer modulo 108+710^8 + 7.

5 5
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
2 1 1 3 2 
1 3 2 3
3 4 1 4 -3
4 5 1 3 -5
1 6 1 5
377
2708

Hint

Sample Input/Output 1 Explanation

qwq


Constraints

This problem has 1717 test points, with unequal weights. For each test point, the value of nn is given in the table below.

Test Point ID n=n= Test Point ID n=n=
11 66 1010 105+210^5 + 2
22 1010 1111 1.5×105+21.5 \times 10^5 + 2
33 100100 1212 105+310^5 + 3
44 10310^3 1313 1.5×105+31.5 \times 10^5 + 3
55 3×1033 \times 10^3 1414 2×105+42 \times 10^5 + 4
66 1515 5×104+55 \times 10^4 + 5
77 104+110^4 + 1 1616 105+510^5 + 5
88 105+110^5 + 1 1717 2×105+52 \times 10^5 + 5
99 1.5×105+11.5 \times 10^5 + 1

Scores for test points:

  • For test points 11 to 1414, each test point is worth 55 points.
  • For test points 1515 to 1717, each test point is worth 1010 points.

Values of mm for test points:

  • For test point 11, m=10m = 10.
  • For test point 22, m=50m = 50.
  • For test points 33 to 1717, m=nm = n.

Special properties of test points:

  • For all test points where the last digit of nn is 66, the following property holds: the time moments used by operations start from 11 and increase by 11 each time.
  • For all test points where the last digit of nn is 11, the following property holds: all modification operations only modify aa, and the modification interval satisfies x=yx = y.
  • For all test points where the last digit of nn is 22, the following property holds: all modification operations only modify aa.
  • For all test points where the last digit of nn is 33, the following property holds: no modification operation modifies vv, and for modifications to bb, it holds that x=yx = y.
  • For all test points where the last digit of nn is 44, the following property holds: there are no modification operations.

For all test points, it is guaranteed that 1xyn1 \leq x \leq y \leq n, 1op41 \leq op \leq 4, all given numbers are within the range of 32-bit signed integers, tt is positive, and is given in strictly increasing order.


Hint

  • Please pay attention to the impact of input reading on program efficiency.
  • Please pay attention to the impact of constant factors on program efficiency.
  • The last digit of nn can help you quickly determine the special properties of a test point.
  • If your answer is negative, please take it modulo into a non-negative number before outputting it.

Translated by ChatGPT 5