D. Flowers
time limit per test

1.5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red.

But, for a dinner to be tasty, there is a rule: Marmot wants to eat white flowers only in groups of size k.

Now Marmot wonders in how many ways he can eat between a and b flowers. As the number of ways could be very large, print it modulo1000000007 (109 + 7).

Input

Input contains several test cases.

The first line contains two integers t and k (1 ≤ t, k ≤ 105), where t represents the number of test cases.

The next t lines contain two integers ai and bi (1 ≤ ai ≤ bi ≤ 105), describing the i-th test.

Output

Print t lines to the standard output. The i-th line should contain the number of ways in which Marmot can eat between ai and bi flowers at dinner modulo 1000000007 (109 + 7).

 

大水,话说这比noip还简单些吧,果然做cf要按x率来做么?\(f[i]=f[i-1]+f[i-k]\)
#include <cstdio>
#include <cstring> const int maxn = 1e5 + ;
const int mod = 1e9 + ; int f[maxn], sum[maxn]; int main() {
int t, k;
scanf("%d%d", &t, &k);
for(int i = ; i < k; ++i) {
f[i] = ;
}
for(int i = k; i <= ; ++i) {
f[i] = f[i - ] + f[i - k];
if(mod <= f[i]) f[i] -= mod;
}
for(int i = ; i <= ; ++i) {
sum[i] = sum[i - ] + f[i];
if(mod <= sum[i]) sum[i] -= mod;
}
while(t--) {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", (sum[b] - sum[a - ] + mod) % mod);
} return ;
}

CF474D. Flowers的更多相关文章

  1. CF474D Flowers 题解

    题目:CF474D Flowers 传送门 DP?递推? 首先可以很快看出这是一道 DP 的题目,但与其说是 DP,还不如说是递推. 大家还记得刚学递推时教练肯定讲过的一道经典例题吗?就是爬楼梯,一个 ...

  2. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

  3. poj 3262 Protecting the Flowers

    http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  4. Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)

    B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...

  5. poj1157LITTLE SHOP OF FLOWERS

    Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...

  6. CF459B Pashmak and Flowers (水

    Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...

  7. 线段树或树状数组---Flowers

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Description As is known to all, the blooming tim ...

  8. sgu 104 Little shop of flowers 解题报告及测试数据

    104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...

  9. 【CodeForces 621C】Wet Shark and Flowers

    题 There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such tha ...

随机推荐

  1. python【数据类型:集合】

  2. K8S发布解释型语言应用的最佳实践

    说明 我们知道,k8s在发布编译型语言的应用时,几乎不用多考虑,就会选择将编译好jar/war包(java语言)或者二进制文件(golang/c++)直接打到镜像当中,生成新的应用镜像,然后将镜像推到 ...

  3. [理论篇]一.JavaScript中的死连接`javascript:void(0)`和空连接`javascript:;`

    void 运算符 void 运算符会对给定的表达式进行求值,然后直接返回 undefined void 运算符通常只用于获取 undefined 的原始值,一般使用 void(0)(等同于 void ...

  4. Tomcat假死排查方案

    使用Tomcat作为Web服务器的时候偶尔会遇到Tomcat停止响应的情况,通过netstat查看端口情况会发现tomcat的端口出现大量的CLOSE_WAIT,此时Tomcat会停止响应前端请求,同 ...

  5. xpath定位中详解id 、starts-with、contains、text()和last() 的用法

    1.XPATH使用方法 使用XPATH有如下几种方法定位元素(相比CSS选择器,方法稍微多一点): a.通过绝对路径定位元素(不推荐!) WebElement ele = driver.findEle ...

  6. Java并发编程原理与实战四十一:重排序 和 happens-before

    一.概念理解 首先我们先来了解一下什么是重排序:重排序是指编译器和处理器为了优化程序性能而对指令序列进行重新排序的一种手段. 从Java源代码到最终实际执行的指令序列,会分别经历下面3种重排序,如下图 ...

  7. js检测上传文件大小

    前言: 项目中经常用到需要上传文件.照片等功能,同时需要限制所上传文件的大小.很多插件都会采用后台请求验证,前端Js校验比较少.本篇介绍一个前端JS便捷判断上传文件大小的方法. 代码很简单,关键就是怎 ...

  8. CSS3实战之background篇

    在CSS3中,background可以添加多个背景图像组,背景图像之间通过逗号进行分隔. 每个背景图像层都可以包含下面的值 background-image 定义背景图像 background-col ...

  9. Spring Data JPA原生SQL查询

    package com.test.cms.dao.repository;import org.springframework.stereotype.Repository;import javax.pe ...

  10. C++ Rule of Three

    Rule of Three The rule of three (also known as the Law of The Big Three or The Big Three) is a rule ...