PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000173. Tổng giao các hình chữ nhật có trọng số (Static Rectangle Add Rectangle Sum)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng giao các hình chữ nhật có trọng số (Static Rectangle Add Rectangle Sum)

Static Rectangle Add Rectangle Sum

Source: Library Checker

Version: Phước Hưng OJ Extended

Problem Statement

You are given NN weighted half-open rectangles [li,ri)×[di,ui)[l_i,r_i)\times[d_i,u_i). For each of QQ half-open query rectangles [l,r)×[d,u)[l,r)\times[d,u), compute the weighted sum of intersection areas, summing the intersection area against every initial rectangle multiplied by its weight:

$$\sum_{i=1}^{N}w_i\,\max(0,\min(r,r_i)-\max(l,l_i))\,\max(0,\min(u,u_i)-\max(d,d_i)).$$

Overlaps between the initial rectangles contribute separately. Print each result modulo 998244353998244353. The initial rectangles are static; there are no updates.

Input

The first line contains N,QN,Q, followed by NN lines l d r u w describing weighted rectangles and QQ lines l d r u describing query rectangles.

Output

For each query rectangle, output its weighted intersection area sum modulo 998244353998244353.

Subtask

  • Subtask 1 (20 points): 1≤N≤151\le N\le 15; 1≤Q≤301\le Q\le 30; every integer rectangle has 0≤l<r≤1090\le l<r\le10^9, 0≤d<u≤1090\le d<u\le10^9; 0≤w<9982443530\le w<998244353; output is modulo 998244353998244353.
  • Subtask 2 (30 points): 1≤N≤20001\le N\le 2000; 1≤Q≤30001\le Q\le 3000; every integer rectangle has 0≤l<r≤1090\le l<r\le10^9, 0≤d<u≤1090\le d<u\le10^9; 0≤w<9982443530\le w<998244353; output is modulo 998244353998244353.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 1≤Q≤2000001\le Q\le 200000; every integer rectangle has 0≤l<r≤1090\le l<r\le10^9, 0≤d<u≤1090\le d<u\le10^9; 0≤w<9982443530\le w<998244353; output is modulo 998244353998244353.

Examples

Example 1

Input

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

Output

36
10
8
3

Explanation

The first rectangle has area 9 and weight 2, contributing 18 to the full-region query. The second has area 6 and weight 3, contributing another 18, for 36. The second query intersects each rectangle in a 1×21\times2 region, yielding 2⋅2+2⋅3=102\cdot2+2\cdot3=10. The third overlaps only the first rectangle in a 2×22\times2 region, yielding 8. The last overlaps only the second in one unit square, yielding 3.

Example 2

Input

1 3
0 0 1000000000 1000000000 998244352
0 0 1 1
0 0 2 2
100 100 101 101

Output

998244352
998244349
998244352

Explanation

The weight 998244352998244352 is congruent to −1-1 modulo 998244353998244353. The first intersection has area 1 and yields 998244352998244352. The second has area 4 and yields −4(mod998244353)=998244349-4\pmod{998244353}=998244349. The third has area 1 again and yields 998244352998244352.