题目链接就长这样子?

time limit per test

2 seconds

memory limit per test

256 megabytes

 
Description

The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xiyi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c).

Over time the stars twinkle. At moment 0 the i-th star has brightness si. Let at moment t some star has brightness x. Then at moment (t + 1) this star will have brightness x + 1, if x + 1 ≤ c, and 0, otherwise.

You want to look at the sky q times. In the i-th time you will look at the moment ti and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (x1iy1i) and the upper right — (x2iy2i). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.

A star lies in a rectangle if it lies on its border or lies strictly inside it.

Input

The first line contains three integers nqc (1 ≤ n, q ≤ 105, 1 ≤ c ≤ 10) — the number of the stars, the number of the views and the maximum brightness of the stars.

The next n lines contain the stars description. The i-th from these lines contains three integers xiyisi(1 ≤ xi, yi ≤ 100, 0 ≤ si ≤ c ≤ 10) — the coordinates of i-th star and its initial brightness.

The next q lines contain the views description. The i-th from these lines contains five integers tix1iy1ix2iy2i (0 ≤ ti ≤ 109, 1 ≤ x1i < x2i ≤ 100, 1 ≤ y1i < y2i ≤ 100) — the moment of the i-th view and the coordinates of the viewed rectangle.

Output

For each view print the total brightness of the viewed stars.

Examples
input
2 3 3
1 1 1
3 2 0
2 1 1 2 2
0 2 1 4 5
5 1 1 5 5
output
3
0
3
input
3 4 5
1 1 2
2 3 0
3 3 1
0 1 1 100 100
1 2 2 4 4
2 2 1 4 7
1 50 50 51 51
output
3
3
5
0
Note

Let's consider the first example.

At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3.

At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0.

At the third view, you can see both stars. At moment 5 brightness of the first is 2, and brightness of the second is 1, so the answer is 3.


我们可以得到状态cnt[t][x][y]表示在t时刻区间[1,x],[1,y]构成的矩形内星星的总亮度。

那么状态怎么转移呢?

我们还可以知道,第i颗星星在t时刻的亮度为。

由简单的二维dp就可以写出

t很大???模c+1就好啦?

这样子就通过这道题啦。

 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define dbg(x) cout<<#x<<" = "<<x<<endl; int read(){
bool flag=;
int re=;
char ch;
while((ch=getchar())!='-'&&(ch<''||ch>''));
ch=='-'?flag=:re=ch-'';
while((ch=getchar())>=''&&ch<='') re=re*+ch-'';
return flag?-re:re;
} const int maxn=,maxsize=,maxc=;
const int X=,Y=; int n,m,head[maxsize][maxsize],nxt[maxn],s[maxn];
int dp[maxc][maxsize][maxsize],c; int main(){
scanf("%d%d%d",&n,&m,&c); c++;
for(int i=,x,y;i<=n;i++){
scanf("%d%d%d",&x,&y,&s[i]);
nxt[i]=head[x][y];
head[x][y]=i;
}
for(int i=,pos;i<c;i++)
for(int x=;x<=X;x++)
for(int y=;y<=Y;y++){
pos=;
for(int j=head[x][y];j;j=nxt[j])
pos+=(s[j]+i)%c;
dp[i][x][y]=dp[i][x-][y]+dp[i][x][y-]-dp[i][x-][y-]+pos;
// printf("dp[%d][%d][%d] = %d\n",i,x,y,dp[i][x][y]);
}
for(int i=,t,x1,y1,x2,y2;i<m;i++){
scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2); t%=c;
printf("%d\n",dp[t][x2][y2]-dp[t][x1-][y2]-dp[t][x2][y1-]+dp[t][x1-][y1-]);
// printf("%d %d %d %d\n",dp[t][x2][y2],dp[t][x1-1][y2],dp[t][x2][y1-1],dp[t][x1-1][y1-1]);
}
return ;
}

CF Round #427 (Div. 2) C. Star sky [dp]的更多相关文章

  1. 动态规划:Codeforces Round #427 (Div. 2) C Star sky

    C. Star sky time limit per test2 seconds memory limit per test256 megabytes inputstandard input outp ...

  2. Codeforces Round #427 (Div. 2) [ C. Star sky ] [ D. Palindromic characteristics ] [ E. The penguin's game ]

    本来准备好好打一场的,然而无奈腹痛只能带星号参加 (我才不是怕被打爆呢!) PROBLEM C - Star sky 题 OvO http://codeforces.com/contest/835/p ...

  3. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

  4. CF Round #551 (Div. 2) D

    CF Round #551 (Div. 2) D 链接 https://codeforces.com/contest/1153/problem/D 思路 不考虑赋值和贪心,考虑排名. 设\(dp_i\ ...

  5. CF Round #510 (Div. 2)

    前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...

  6. 竞赛题解 - CF Round #524 Div.2

    CF Round #524 Div.2 - 竞赛题解 不容易CF有一场下午的比赛,开心的和一个神犇一起报了名 被虐爆--前两题水过去,第三题卡了好久,第四题毫无头绪QwQ Codeforces 传送门 ...

  7. CF Round #600 (Div 2) 解题报告(A~E)

    CF Round #600 (Div 2) 解题报告(A~E) A:Single Push 采用差分的思想,让\(b-a=c\),然后观察\(c\)序列是不是一个满足要求的序列 #include< ...

  8. CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)

    证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...

  9. cf Round#273 Div.2

    题目链接,点击一下 Round#273 Div.2 ================== problem A Initial Bet ================== 很简单,打了两三场的cf第一 ...

随机推荐

  1. element ui设置表格表头高度和每一行的高度

    填坑记录:今天用element ui的表格组件做用户信息展示,直接拉取的官网的代码过来,发现表头和每一行都太高了,如下: 因为第一次使用element ui的表格组件,不太清楚会遇到这样的坑,以为能轻 ...

  2. 使用jQuery的datetimepicker插件

    因为后台系统要使用年月日时分的设置,又因为使用的Bootstrap框架只有datepicker和timepicker控件.所以在jQuery库中找到轻量级的datetimepicker插件,很好地解决 ...

  3. oracle密码过期,改为原来的密码

    我们都知道Oracle 数据库的用户的密码默认是有有效期限制的,特别是在Cloud上面的DB,有些用户是Cloud自动创建的,我们不知道原来的密码是什么,但是如果密码过期了,如果修改成新的密码,会影响 ...

  4. UPDATE - 更新一个表中的行

    SYNOPSIS UPDATE [ ONLY ] table SET column = { expression | DEFAULT } [, ...] [ FROM fromlist ] [ WHE ...

  5. MYSQL分数排名

    编写一个 SQL 查询来实现分数排名.如果两个分数相同,则两个分数排名(Rank)相同.请注意,平分后的下一个名次应该是下一个连续的整数值.换句话说,名次之间不应该有“间隔”. +----+----- ...

  6. 小程序怎样将字符串转化为html

    在小程序中通过rich-text 标签,使用nodes将字符串转化为html <rich-text class="allAnswer "  nodes='<span c ...

  7. echarts点击柱状图时触发点击事件

    项目需求:1.通过echarts把数据展示为柱状图2.点击对应的柱状图 显示对应的弹窗 主要用到的时 echarts中的 "click" 事件, 使用demo: var myCha ...

  8. bzoj1008题解

    [题意分析] 求长度为n,元素大小在[1,m]∩N的序列中,有多少个序列中存在相同的相邻元素. [解题思路] 小学奥数题.. 总序列数:S=mn 不存在相同的相邻元素的序列数:T=m*(m-1)n-1 ...

  9. CF 622F (拉格朗日插值)

    传送门 解题思路 比较经典的一道题目.第一种方法是差分,就是假设\(k=3\),我们打一个表. 0 1 9 36 100 225 1 8 27 64 125 7 19 37 61 12 18 24 6 ...

  10. NX二次开发-UFUN设置工程图PNG图片长度UF_DRF_set_image_width

    #include <uf.h> #include <uf_drf.h> UF_initialize(); //插入PNG char* file_name = "D:\ ...