#P4231. 三步必杀

三步必杀

Description

There are NN pillars in a row, and initially each pillar has damage 00.

Yuugi will perform MM attacks. Each attack is described by four parameters l,r,s,el, r, s, e:

It means this attack affects all pillars from the ll-th to the rr-th (inclusive), dealing damage ss to the first pillar and ee to the last pillar within the range.

The damage values form an arithmetic progression. For example, if l=1,r=5,s=2,e=10l = 1, r = 5, s = 2, e = 10, then the damages to pillars 151 \sim 5 are 2,4,6,8,102, 4, 6, 8, 10 respectively.

The oni need the final damage of each pillar after all attacks are completed.

Input Format

The first line contains 22 integers N,MN, M, separated by a space; same below.

Each of the next MM lines contains 44 integers l,r,s,el, r, s, e, as described above.

It is guaranteed that every individual damage applied to any pillar is an integer.

Output Format

Because the output might be too large to print in full, to ensure you can indeed maintain all pillars’ damage, output two integers separated by a space: the XOR sum of all pillars’ final damages and the maximum of them.

(The XOR sum is the value obtained by bitwise XOR over all numbers.)

(The XOR operator in C++ is ^.)

5 2
1 5 2 10
2 4 1 1

3 10
6 2
1 5 2 10
2 4 1 1
3 10

Hint

Sample explanation:

Sample 1:

Damage from the first attack: 2,4,6,8,102, 4, 6, 8, 10.

Damage from the second attack: 0,1,1,1,00, 1, 1, 1, 0.

Final damage of each pillar after all attacks: 2,5,7,9,102, 5, 7, 9, 10.

Output the XOR sum and the maximum, which are 3,103, 10.

Sample 2:

The sixth pillar is not hit, so the answer remains unchanged.

Constraints:

This problem is worth 100100 points, split into 44 subtasks. (x/y)(x/y) means (score/testcase count).

  • Fairy level (18/3)(18/3): 1N,M10001 \le N, M \le 1000. Even fairies playing around could finish this job, right?
  • Kappa level (10/1)(10/1): s=es = e. Can this replace my work?
  • Tengu level (20/4)(20/4): 1N,M1051 \le N, M \le 10^5. Small tricks no longer suffice.
  • Oni God level (52/2)(52/2): No special restrictions. Time to really think.

These four parts of testdata do not overlap.

For all data: 1N1071 \le N \le 10^7, 1M3×1051 \le M \le 3 \times 10^5, 1l<rN1 \le l < r \le N.

All input, output, and pillar damage values are always within [0,9×1018][0, 9 \times 10^{18}].

Tip:

Due to various reasons, the time limit may be tight. C++ participants, please do not use cin for input.

by orangebird.

Translated by ChatGPT 5