HDU- 6656 Kejin Player

Kejin Player

Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1901 Accepted Submission(s): 789

Problem Description
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 i, you have to pay ai RMB to get to level i+1”. Cuber QQ now changed it a little bit: “when you are level i, you pay ai RMB, are you get to level i+1 with probability pi; otherwise you will turn into level xi (xi≤i)”.

Cuber QQ still needs to know how much money expected the Kejin players needs to ``ke’’ so that they can upgrade from level l to level r, because you worry if this is too high, these players might just quit and never return again.

Input
The first line of the input is an integer t, denoting the number of test cases.

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

Then follows n lines, each containing integers ri, si, xi, ai (1≤ri≤si≤109, 1≤xi≤i, 0≤ai≤109), space separated. Note that pi is given in the form of a fraction risi.

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

The sum of n and sum of q from all t test cases both does not exceed 106.

Output
For each query, output answer in the fraction form modulo 109+7, that is, if the answer is PQ, you should output P⋅Q−1 modulo 109+7, where Q−1 denotes the multiplicative inverse of Q modulo 109+7.

Sample Input
1
3 2
1 1 1 2
1 2 1 3
1 3 3 4
1 4
3 4

Sample Output
22
12


题意很简单,就是说一个人可以花钱升一级,但是只有一定概率成功,否则掉会x级。

直接看图:


AC代码:

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+10,p=1e9+7;
int T,n,q,dp[N],r[N],s[N],x[N],a[N],L,R;
inline int qmi(int a,int b=p-2){
	int res=1;
	while(b){if(b&1) res=res*a%p; b>>=1; a=a*a%p;}
	return res;
}
signed main(){
	cin>>T;
	while(T--){
		scanf("%lld %lld",&n,&q);
		for(int i=1;i<=n;i++)
			scanf("%lld %lld %lld %lld",&r[i],&s[i],&x[i],&a[i]);
		for(int i=1;i<=n;i++)
			dp[i+1]=((dp[i]+a[i]-dp[x[i]]+p)%p*s[i]%p*qmi(r[i])%p+dp[x[i]])%p;
		while(q--){
			scanf("%lld %lld",&L,&R);	printf("%lld\n",(dp[R]-dp[L]+p)%p);
		}
	}
	return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 17:10
什么素质,我请问呢,要掉小珍珠了。。。又憋屈又生气
苍蓝星上艾露:给它们能的,一群dinner牛马挥刀向更弱者罢了。我写的开源求职AI co-pilot工具,优化你的简历,找到你匹配的岗位,定制你的简历,并让你做好面试准备https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
大疆在线测评都考什么呀,会考企业概况啥的吗
又被画饼了的做题家很...:不会。刚做完,就是材料分析、态度题、算术题、逻辑题。总共60道。
投递大疆等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务