CF1495E.Qingshan and Daniel

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Qingshan and Daniel are going to play a card game. But it will be so boring if only two persons play this. So they will make nn robots in total to play this game automatically. Robots made by Qingshan belong to the team 11 , and robots made by Daniel belong to the team 22 . Robot ii belongs to team tit_i . Before the game starts, aia_i cards are given for robot ii .

The rules for this card game are simple:

  • Before the start, the robots are arranged in a circle in the order or their indices. The robots will discard cards in some order, in each step one robot discards a single card. When the game starts, robot 11 will discard one of its cards. After that, robots will follow the following rules:
  • If robot ii discards the card last, the nearest robot whose team is opposite from ii 's will discard the card next. In another word jj will discard a card right after ii , if and only if among all jj that satisfy titjt_i\ne t_j , dist(i,j)dist(i,j) (definition is below) is minimum.
  • The robot who has no cards should quit the game immediately. This robot won't be considered in the next steps.
  • When no robot can discard the card next, the game ends.

We define the distance from robot xx to robot yy as dist(x,y)=(yx+n)modndist(x,y)=(y-x+n)\bmod n . It is similar to the oriented distance on the circle.

For example, when n=5n=5 , the distance from 11 to 33 is dist(1,3)=(31+5)mod5=2dist(1,3)=(3-1+5)\bmod 5=2 , the distance from 33 to 11 is dist(3,1)=(13+5)mod5=3dist(3,1)=(1-3+5)\bmod 5 =3 .

Later, Qingshan finds out that it will take so much time to see how robots play. She wants to know the result as quickly as possible. You, as Qingshan's fan, are asked to calculate an array [ans1,ans2,,ansn][ans_1,ans_2,\ldots,ans_n]ansians_i is equal to the number of cards, that ii -th robot will discard during the game. You need to hurry!

To avoid the large size of the input, the team and the number of cards of each robot will be generated in your code with some auxiliary arrays.

输入格式

The first line contains one integer nn ( 1n51061 \le n \le 5\cdot 10^6 ) — the number of robots playing this game.

The second line contains one integer mm ( 1mmin(n,200000)1 \le m \le \min(n,200\,000) ).

Each of the next mm line contains four integers pip_i , kik_i , bib_i , wiw_i ( 1pin1 \le p_i \le n , 1ki109+71 \le k_i \le 10^9+7 , 0bi,wi<ki0 \le b_i ,w_i< k_i ). It's guaranteed that pm=np_m=n and pj1<pjp_{j-1}<p_{j} ( 2jn2 \le j \le n ).

Arrays aja_j and tjt_j should be generated by the following pseudo code:

seed = 0
base = 0

function rnd():
    ret = seed
    seed = (seed * base + 233) mod 1000000007
    return ret

p[0] = 0
for i = 1 to m:
    seed = b[i]
    base = w[i]
    for j = p[i - 1] + 1 to p[i]:
        t[j] = (rnd() mod 2) + 1
        a[j] = (rnd() mod k[i]) + 1

输出格式

Print a single integer (i=1n((ansii2)+1))mod109+7\left( \prod_{i=1}^{n} ((ans_i \oplus i^2)+1)\right) \bmod 10^9+7 , where \oplus denotes the bitwise XOR operation.

输入输出样例

  • 输入#1

    3
    3
    1 5 2 3
    2 7 1 2
    3 2 1 1

    输出#1

    100
  • 输入#2

    5000000
    2
    1919810 998244353 114514 19260817
    5000000 233333333 623532 7175

    输出#2

    800210675
  • 输入#3

    1
    1
    1 1 0 0

    输出#3

    1

说明/提示

In the first test case a=[5,5,1]a=[5,5,1] and t=[1,2,2]t=[1,2,2] .

The robot 11 discards the card first.

Then robot 22 discards the card next. Robot 33 doesn't discard the card next because dist(1,2)<dist(1,3)dist(1,2)<dist(1,3) .

Then robot 11 discards the card next. Robot 33 doesn't discard the card next because t2=t3t_2=t_3 .

If we write down the index of the robot who discards a card in time order, it will be the sequence [1,2,1,2,1,2,1,2][1,2,1,2,1,2,1,2] . So robots 11 , 22 and 33 discard 55 , 55 and 00 cards, respectively. And the answer is (((512)+1)×((522)+1)×((032)+1))mod109+7=(5×2×10)mod109+7=100(((5 \oplus 1^2)+1)\times((5 \oplus 2^2)+1)\times((0 \oplus 3^2)+1)) \bmod 10^9+7=(5\times 2 \times 10)\bmod 10^9+7=100 .

首页