2018牛客暑期ACM多校训练营第二场 - A题

A题是道水题……结果没注意到编译器不支持I64d卡了快俩小时……ios

  还要注意的是k=1时不是特例,由于这时候走跟跑仍是不同的……spa


A  runcode

输入描述:
The first line of input contains 2 integers Q and k.Q is the number of queries.(Q<=100000,1<=k<=100000) For the next Q lines,each line contains two integers L and R.(1<=L<=R<=100000)ci


输出描述:
For each query,print a line which contains an integer,denoting the answer of the query modulo 1000000007.get


示例1:
输入
3 3
3 3
1 4
1 5
输出
2
7
11input


#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstdio>
using namespace std;

long long dp[100010];
long long sum[100010] = { 0 };
int k;

void inti()
{
	for (int i = 0; i < k; i++)
		dp[i] = 1;
	dp[k] = 2;

	for (int i = k + 1; i < 100001; i++) 
		dp[i] = (dp[i - 1] + dp[i - k - 1]) % 1000000007;
}

void dosum()
{
	sum[0] = 0;
	for (int i = 1; i < 100001; i++)
		sum[i] = (sum[i - 1] + dp[i]) % 1000000007;
}

int main(void)
{
	int q, l, r;
	cin >> q >> k;
	inti();
	dosum();
	for (int i = 0; i < q; i++) {
		scanf("%d%d", &l, &r);
		printf("%lld\n", (sum[r] - sum[l - 1] + 1000000007) % 1000000007);
	}

	return 0;
}