Problem 3039 --Kejin Player

3039: Kejin Player

"
Time Limit $5$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $1$ 正确数量 $1$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Cuber QQ always envies those Kejin players, who pay a lot of RMB to get a higher level in the game. So he worked so hard that you are now the game designer of this game. He decided to annoy these Kejin players a little bit, and give them the lesson that RMB does not always work. 

This game follows a traditional Kejin rule of "when you are level ii, you have to pay aiai RMB to get to level i+1i+1". Cuber QQ now changed it a little bit: "when you are level ii, you pay aiai RMB, are you get to level i+1i+1 with probability pipi; otherwise you will turn into level xixi (xi≤ixi≤i)". 

Cuber QQ still needs to know how much money expected the Kejin players needs to ``ke'' so that they can upgrade from level ll to level rr, because you worry if this is too high, these players might just quit and never return again. 
The first line of the input is an integer tt, denoting the number of test cases. 

For each test case, there is two space-separated integers nn (1≤n≤500 0001≤n≤500 000) and qq(1≤q≤500 0001≤q≤500 000) in the first line, meaning the total number of levels and the number of queries. 

Then follows nn lines, each containing integers ririsisixixiaiai (1≤ri≤si≤1091≤ri≤si≤1091≤xi≤i1≤xi≤i0≤ai≤1090≤ai≤109), space separated. Note that pipi is given in the form of a fraction risirisi

The next qq lines are qq queries. Each of these queries are two space-separated integers ll and rr (1≤l<r≤n+11≤l<r≤n+1). 

The sum of nn and sum of qq from all tt test cases both does not exceed 106106.
For each query, output answer in the fraction form modulo 109+7109+7, that is, if the answer is PQPQ, you should output P⋅Q−1P⋅Q−1 modulo 109+7109+7, where Q−1Q−1 denotes the multiplicative inverse of QQ modulo 109+7109+7
1
3 2
1 1 1 2
1 2 1 3
1 3 3 4
1 4
3 4
22
12
Huge IO (Over 40MB)! IO optimization is preferred.

推荐代码 查看3039 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$1160 $ms] 淡意的温柔 591119 2020-06-06 08:11:40
内存最少[$13740 $KB] 淡意的温柔 591119 2020-06-06 08:11:40
第一AC 淡意的温柔 591119 2020-06-06 08:11:40
第一挑战 淡意的温柔 591119 2020-06-06 08:11:40

赛题来源/所属竞赛 2019 Multi-University Training Contest 7 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛