C. Star sky
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

求出所有点的前缀和,之后对于每个t,计算sum[t][x2][y2]-sum[t][x1-1][y2]-sum[t][x2][y1-1]+sum[t][x1-1][y1-1]并输出。

AC代码:

 #include<bits/stdc++.h>
using namespace std; const int MAXN=; int sum[][MAXN][MAXN]; int main(){
ios::sync_with_stdio(false);
int n,q,c;
cin>>n>>q>>c;
for(int i=;i<n;i++){
int x,y,s;
cin>>x>>y>>s;
for(int t=;t<=c;t++){
sum[t][x][y]+=(s+t)%(c+);
}
}
for(int i=;i<=c;i++){
for(int x=;x<MAXN;x++){
for(int y=;y<MAXN;y++){
sum[i][x][y]+=sum[i][x-][y]+sum[i][x][y-]-sum[i][x-][y-];
}
}
}
for(int i=;i<q;i++){
int t,x1,y1,x2,y2;
cin>>t>>x1>>y1>>x2>>y2;
t%=(c+);
cout<<sum[t][x2][y2]-sum[t][x1-][y2]-sum[t][x2][y1-]+sum[t][x1-][y1-]<<endl;;
}
return ;
}

CF-835C的更多相关文章

  1. Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

    The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...

  2. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  3. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  4. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  5. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  6. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  7. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  8. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  9. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  10. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

随机推荐

  1. VS2013 自动添加头部注释 -C#开发

    在团队开发中,头部注释是必不可少的.但在开发每次新建一个类都要复制一个注释模块也很不爽,所以得想个办法让开发工具自动生成我们所需要的模板.....操作方法如下: 方法/步骤 1 找你的vs安装目录, ...

  2. HTML5画布(基础篇11-10)

    <script type="text/javascript"> $(function(){ var s = $("#myCanvas")[0]; v ...

  3. protobuf json xml比较

    1 protobuf/xml/json对比 从数据的存储格式的角度进行对比 假如要存储一个键值对: {price:150} 1.1 protobuf的表示方式 message  Test { opti ...

  4. 这种实现方式比使用 += 要更节省内存和 CPU,尤其是要串联的字符串数目特别多的时候。

    这种实现方式比使用 += 要更节省内存和 CPU,尤其是要串联的字符串数目特别多的时候. package main import ( "bytes" "fmt" ...

  5. Python解释器是单线程应用 IO 密集型 计算密集型 GIL global interpreter lock

    [Python解释器是单线程应用] [任意时刻,仅执行一个线程] 尽管Python解释器中可以运行多个线程,但是在任意给定的时刻只有一个线程会被解释器执行. [GIL锁 保证同时只有一个线程运行] 对 ...

  6. varnish代理缓存服务器的安装与使用

    1. 下载解压 cd /usr/local/src/ wget https://codeload.github.com/varnishcache/varnish-cache/zip/master ch ...

  7. Python爬虫--Urllib库

    Urllib库 Urllib是python内置的HTTP请求库,包括以下模块:urllib.request (请求模块).urllib.error( 异常处理模块).urllib.parse (url ...

  8. Elasticsearch基本语法

    match和match_phrase区别 match: 索引中只要有任意一个匹配拆分后词就可以出现在结果中,只是匹配度越高的排越前面 match_phrase: 索引中必须同时匹配拆分后词就可以出现在 ...

  9. 利用wrapper注冊的 java服务起动超时的解决方法

    使用Java Service Wrapper能够把java程序注冊为一个系统服务,可是在启动服务的某些情况下会抛出例如以下错误: ERROR  | wrapper  | 2014/06/11 08:4 ...

  10. terminal中 启动ios模拟器,并安装软件

    启动运行模拟器: xcrun instruments -w 'iPhone 6 Plus' 在已经启动好的模拟器中安装应用: xcrun simctl install booted Calculato ...