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-10 15:58
投个小米提前批试试水,先投一个岗位看看形势,不行就再沉淀一下投第二个岗位,莫辜负
Java抽象带篮子:我嘞个骚刚,已经开始研发6g了吗
投递小米集团等公司7个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 11:21
被夸真的超级开心,好可爱的姐姐
码农索隆:老色批们不用脑补了,我把金智妮的图找来了查看图片
点赞 评论 收藏
分享
苍蓝星上艾露:这简历。。。可以试试我写的开源简历优化工具https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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