Classical Data Structure Problem

아직 제출이 없습니다시간 제한3초메모리 제한128 MB

문제

You have an integer array A=\[a_0,a_1,,a_2m1]A = \[a\_0, a\_1, \ldots, a\_{2^m-1}] of length 2m2^m. Initially, the array consists of zeros.

You also have an integer variable xx. Initially, x=0x = 0.

For each i=1,2,,ni = 1, 2, \ldots, n, you are given two integers p_ip\_i and q_iq\_i, and you have to perform the following steps:

  • Let p=(p_i+x)mod2mp' = (p\_i + x) \bmod 2^m and q=(q_i+x)mod2mq' = (q\_i + x) \bmod 2^m.
  • Let l=min(p,q)l = \min(p', q') and r=max(p,q)r = \max(p', q').
  • For each j=l,l+1,,rj = l, l+1, \ldots, r, increase a_ja\_j by ii, then increase xx by a_ja\_j.

Find the value of xmod230x \bmod 2^{30} at the end of this process.

입력

The first line contains two integers nn and mm (1n500,0001 \le n \le 500\\,000; 1m301 \le m \le 30).

The ii-th of the following nn lines contains two integers p_ip\_i and q_iq\_i (0p_i,q_i<2m0 \le p\_i, q\_i < 2^m).

출력

Print the value of xmod230x \bmod 2^{30}.

힌트

In the example test, initially, A=\[0,0,0,0]A = \[0, 0, 0, 0] and x=0x = 0. Then:

  • For i=1i = 1, we have l=1l = 1 and r=2r = 2. Then, A=\[0,1,1,0]A = \[0, 1, 1, 0] and x=2x = 2.
  • For i=2i = 2, we have l=1l = 1 and r=3r = 3. Then, A=\[0,3,3,2]A = \[0, 3, 3, 2] and x=10x = 10.
  • For i=3i = 3, we have l=0l = 0 and r=1r = 1. Then, A=\[3,6,3,2]A = \[3, 6, 3, 2] and x=19x = 19.
  • For i=4i = 4, we have l=0l = 0 and r=3r = 3. Then, A=\[7,10,7,6]A = \[7, 10, 7, 6] and x=49x = 49.
  • For i=5i = 5, we have l=1l = 1 and r=3r = 3. Then, A=\[7,15,12,11]A = \[7, 15, 12, 11] and x=87x = 87.