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 coordinates (xi, yi), 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 (x1i, y1i) and the upper right — (x2i, y2i). 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.
The first line contains three integers n, q, c (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 xi, yi, si (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 ti, x1i, y1i, x2i, y2i (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.
For each view print the total brightness of the viewed stars.
2 3 3 1 1 1 3 2 0 2 1 1 2 2 0 2 1 4 5 5 1 1 5 5
3 0 3
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
3 3 5 0
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.
题目大意 天空中有一些星星,每个星星有一个初始亮度,如果一个星星的初始亮度为s, 那么在时刻t, 它的亮度为(s + t) % (c + 1)。有q个询问,询问在某一时刻天空中某个矩形内所有星星的亮度和。
x, y很小,c很小,而且有趣的是10 * 100 * 100 = 100000,标准cf数据范围。
所以考虑对每种星星的初始亮度搞一个前缀和。这样对于某一时刻,你可以算出某个矩形内亮度为x的星星数目。
于是这道题就很简单了。。
值得高兴的是,终于在考试的时候把C题A掉了。。。好开心。。一直认为C题有毒,每次都会做,每次都挂。
Code
/**
* Codeforces
* Problem#835C
* Accepted
* Time:156ms
* Memory:3700k
*/
#include <bits/stdc++.h>
#ifndef WIN32
#define Auto "%lld"
#else
#define Auto "%I64d"
#endif
using namespace std;
typedef bool boolean;
const signed int inf = (signed)((1u << ) - );
const signed long long llf = (signed long long)((1ull << ) - );
const double eps = 1e-;
const int binary_limit = ;
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
inline boolean readInteger(T& u){
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
return true;
} int n, q, c;
int xs[], ys[], ss[];
int sum[][][]; inline void init() {
scanf("%d%d%d", &n, &q, &c);
for(int i = ; i <= n; i++) {
scanf("%d%d%d", xs + i, ys + i, ss + i);
}
} inline void getPreSum() {
memset(sum, , sizeof(sum));
for(int i = ; i <= n; i++) {
sum[xs[i]][ys[i]][ss[i]]++;
}
for(int i = ; i <= ; i++) {
for(int j = ; j <= ; j++) {
for(int k = ; k <= ; k++)
sum[i][j][k] += sum[i - ][j][k] + sum[i][j - ][k] - sum[i - ][j - ][k];
}
}
} inline int getAns(int x, int y, int t0) {
int rt = ;
for(int i = ; i <= ; i++)
rt += (sum[x][y][i]) * ((i + t0) % (c + ));
return rt;
} inline void solve() {
int t0, x0, y0, x1, y1;
while(q--) {
scanf("%d%d%d%d%d", &t0, &x0, &y0, &x1, &y1);
printf("%d\n", getAns(x1, y1, t0) - getAns(x0 - , y1, t0) - getAns(x1, y0 - , t0) + getAns(x0 - , y0 - , t0));
}
} int main() {
init();
getPreSum();
solve();
return ;
}
Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和的更多相关文章
- Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索
Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...
- Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)
Two boys decided to compete in text typing on the site "Key races". During the competition ...
- 【Codeforces Round #427 (Div. 2) C】Star sky
[Link]:http://codeforces.com/contest/835/problem/C [Description] 给你n个星星的坐标(xi,yi); 第i个星星在第t秒,闪烁值变为(s ...
- Codeforces Round #427 (Div. 2) Problem B The number on the board (Codeforces 835B) - 贪心
Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...
- Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论
n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...
- CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)
s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...
- CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)
证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...
- 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 ...
- Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...
随机推荐
- 在屏幕拖拽3D物体移动
3D物体的拖拽不同于2D的.因为3D物体有x,y,z当然.实际拖拽还是在XZ平面.只是多了几个转换 using UnityEngine; using System.Collections; publi ...
- Struts2第三天
## Struts2第三天 ## ---------- **课程回顾:Struts2框架的第二天** 1. Servlet的API * ActionContext对象 * ServletActionC ...
- POJ 2752 Seek the Name,Seek the Fame(KMP,前缀与后缀相等)
Seek the Name,Seek the Fame 过了个年,缓了这么多天终于开始刷题了,好颓废~(-.-)~ 我发现在家真的很难去学习,因为你还要陪父母,干活,做家务等等 但是还是不能浪费时间啊 ...
- composer----------composer初体验,如何安装,如何下载
最近PHP里面比较火的一款框架laravel,想学一下看下这个框架到底哪里好.这款框架的中文官网激励推荐composer,没办法就去学了一些composer.结果整了半天,还不如看一段短视频学的容易. ...
- html utf-8 中文乱码
刚才用ajax从记事本中读文档的时候,发现在页面上显示是乱码. 页面编码:<meta charset="utf-8"> 搞半天最后发现是记事本编码格式的问题,记事本默认 ...
- [4]传奇3服务器源码分析一 SelGate
1. 2 留存 服务端下载地址: 点击这里
- Msfvenom木马使用及TheFatRat工具
msfvenom –platform windows -p windows/x64/shell/reverse_tcp LHOST=192.168.168.111 LPORT=3333 EXITFUN ...
- Acperience (英语阅读 + 数学推导)
#include<bits/stdc++.h> using namespace std; int main(){ int T,n,m;scanf("%d",&T ...
- uvalive 3887 Slim Span
题意: 一棵生成树的苗条度被定义为最长边与最小边的差. 给出一个图,求其中生成树的最小苗条度. 思路: 最开始想用二分,始终想不到二分终止的条件,所以尝试暴力枚举最小边的长度,然后就AC了. 粗略估计 ...
- 配置开发环境2——eclipse配置
纯手动配置eclipse, Eclipse配置 配置工作空间的编码方式 General—Workspace:改成Other:UTF-8 配置property的编码方式 配置maven Window — ...