#P4433. [COCI 2009/2010 #1] ALADIN

[COCI 2009/2010 #1] ALADIN

Description

You are given nn boxes and qq operations of two types:

  • Type 1 operation with input format 1 L R A B: for each box XX with LXRL \leq X \leq R, set its number of stones to (XL+1)×AmodB(X - L + 1) \times A \bmod B, where XX is the index of the box.
  • Type 2 operation with input format 2 L R: query the total number of stones in boxes numbered LL through RR.

Input Format

The first line contains two integers nn (1n1091 \leq n \leq 10^9) and qq (1q5×1041 \leq q \leq 5 \times 10^4).

The next qq lines describe the operations.

Output Format

For each type 2 operation, output the total number of stones.

6 3
2 1 6
1 1 5 1 2
2 1 6

0
3
4 5
1 1 4 3 4
2 1 1
2 2 2
2 3 3
2 4 4

3
2
1
0
4 4
1 1 4 7 9
2 1 4
1 1 4 1 1
2 1 4

16
0

Hint

  • For 30%30\% of the testdata, n,q103n, q \leq 10^3.
  • For 70%70\% of the testdata, q103q \leq 10^3.
  • For 100%100\% of the testdata, 1A,B1061 \leq A, B \leq 10^6.

Translated by ChatGPT 5