- Time limit 5000 ms
- Memory limit 524288 kB
- OS Windows
Problem-solving ideas
Because the upgrade can only rise stage by stage, so expect to meet the desires of nature plus range, you can count stage by stage, and then seek the prefix and the output (bad state, the Pro blog Tiling, I do not know said)
Then throw link (left pit)
- This blog pushes formula when it seems some places subscript a little wrong, and push the process save a lot of formulas (fog) https://blog.csdn.net/toohandsomeIeaseId/article/details/99357608
- This formula is the direction to push me good novel, non-integer times of krypton gold, so do not Sike infinite series of ...... (my monkey sort essay can also be calculated hurry up) HTTPS: // blog.csdn.net/qq_41785863/article/details/99347386
Source
Reference blog written by someone else, I feel like a copy of the same
#include<stdio.h>
const int mod=1e9+7;
const int MAXN=5e5+5;
int T;
int n,m;
long long inv(long long x)//快速幂求逆元 inv[a]=a^(p-2)
{
long long res=1LL;
long long b=mod-2;
while(b){
if(b&1) res=res*x%mod;
x*=x;
x%=mod;
b>>=1;
}
return res%mod;
}
long long sum[MAXN];
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
sum[0] = 0;
for(int i = 1; i <= n; ++i)
{
long long r, s, x, a;
scanf("%lld%lld%lld%lld", &r, &s, &x, &a);
long long p = r * inv(s) % mod;
sum[i] = (sum[i - 1] + (a + (1 - p + mod) % mod * (a + sum[i - 1] - sum[x - 1] + mod) % mod * inv(p) % mod) % mod + mod) % mod;//关键就是这个了
}
while(m--)
{
int l, r;
scanf("%d%d", &l, &r);
long long ans = (sum[r - 1] - sum[l - 1] + mod) % mod;//这里为啥来着……
printf("%lld\n", ans);
}
}
return 0;
}