Codeforces Round #427 (Div. 2) - C
题目链接:http://codeforces.com/contest/835/problem/C
题意:在二维坐标里,有n个星星,m个询问,星星的最大亮度c。然后输入n个星星的坐标和初始亮度,对于每个询问你需要回答对于左下角(x1,y1)和右上角(x2,y2)的矩形区域中的星星中,经过t秒后亮度和是多少? 对于一个星星如果在第t秒亮度为x,那么在t+1秒亮度将变成x+1(x+1<=c时)或0(x+1>c)。
思路:由于c<=10.所以对于一个矩形区域只需要统计初始每个亮度出现的数量,假设初始亮度为i的数目有cnt[i]个,那么经过t秒后的对于总亮度的共享为 cnt[i]*(i+t)%(c+1)。 然后我们定义val[i][j][k]表示坐标(i,j)中亮度为k的有多少个,然后统计一个前缀和计算即可。 还有另外一种方法是维护10个二维树状数组,然后枚举亮度后用二维树状数组统计矩形区域的和。
注意坑点:存在多个星星在同一个位置,并且可能亮度也相同。
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<time.h>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long int LL;
const int MAXN = + ;
const int INF = 1e9;
const int mod = 1e9 + ;
int n, q, c;
LL val[MAXN][MAXN][], tmpc[];
int main(){
#ifdef kirito
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
while (~scanf("%d%d%d", &n, &q, &c)){
memset(val, , sizeof(val));
for (int i = ; i <= n; i++){
int x, y, s;
scanf("%d%d%d", &x, &y, &s);
val[x][y][s]++;
}
for (int i = ; i <= ; i++){
for (int j = ; j <= ; j++){
for (int k = ; k <= ; k++){
val[i][j][k] += val[i][j - ][k];
}
}
}
for (int i = ; i <= q; i++){
int x1, y1, x2, y2, t;
scanf("%d%d%d%d%d", &t, &x1, &y1, &x2, &y2);
memset(tmpc, , sizeof(tmpc));
for (int j = x1; j <= x2; j++){
for (int k = ; k <= ; k++){
tmpc[k] += (val[j][y2][k] - val[j][y1 - ][k]);
}
}
LL res = ;
for (int k = ; k <= ; k++){
res = res + (1LL * tmpc[k] * ((k + t) % (c + )));
}
printf("%lld\n", res);
}
}
return ;
}
Codeforces Round #427 (Div. 2) - C的更多相关文章
- 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) 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 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 ...
- 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) B. The number on the board
引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...
- Codeforces Round #427 (Div. 2)—A,B,C,D题
A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...
- Codeforces Round #427 (Div. 2)——ABCD
http://codeforces.com/contest/835 A.拼英语水平和手速的签到题 #include <bits/stdc++.h> using namespace std; ...
- 【Codeforces Round #427 (Div. 2) D】Palindromic characteristics
[Link]:http://codeforces.com/contest/835/problem/D [Description] 给你一个字符串; 让你在其中找到1..k阶的回文子串; 并统计它们的数 ...
- 【Codeforces Round #427 (Div. 2) A】Key races
[Link]:http://codeforces.com/contest/835/problem/A [Description] [Solution] 傻逼题. [NumberOf WA] [Revi ...
随机推荐
- Comparable接口与Comparator接口的比较————总结
之前的两篇文章主要学习了Comparable接口和Comparator接口的学习.既然已经学习完了,现在就趁热打铁,进行总结吧! Comparable接口和Comparator接口的共同点: 1. 都 ...
- CentOS7修改计算机名!
https://www.cnblogs.com/acgpiano/p/4170546.html sudo hostnamectl set-hostname <host-name>
- 基于RANSAC的点云面分割算法
该算法在RANSAC和空间检索树的基础上实现的. 算法思路: 1.点云抽希.法线估计 2.出局点索引存储声明 3.平面检测 for (size_t i = 0; i < cloudTemp-&g ...
- SetWindowsHookEx失败
使用下面代码hook鼠标 res = SetWindowsHookEx(WH_MOUSE_LL, _mouseHookProcedure, Marshal.GetHINSTANCE(System.Re ...
- 搭建第一个netty程序
来自action In netty 自己修改一点点 主要依赖 <dependencies> <dependency> <groupId>io.netty</g ...
- 解决samlexception-inresponsetofield-of-the-response-doesnt-correspond-to-sent-mess
sp在校验samlresponse 根据id在session中的samlrequestid 取出,两者进行对比,这里如果做idp-init的话 可以注释掉. 1第一种方法 WebSSOProfileC ...
- 阶段3 1.Mybatis_07.Mybatis的连接池及事务_1 今日课程内容介绍
- 机器学习【一】K最近邻算法
K最近邻算法 KNN 基本原理 离哪个类近,就属于该类 [例如:与下方新元素距离最近的三个点中,2个深色,所以新元素分类为深色] K的含义就是最近邻的个数.在sklearn中,KNN的K值是通过n ...
- 【MM系列】SAP MM模块-货物移动对标准价的影响
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-货物移动对标准价的 ...
- python每日一练:0014题
第 0014 题: 纯文本文件 student.txt为学生信息, 里面的内容(包括花括号)如下所示: { "1":["张三",150,120,100], &q ...