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 ...
随机推荐
- Java 实现日期 Date 的赋值
关键的语句也就三句话: (1) SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd"); (2) Date ...
- jsp四种属性范围
在JSP提供了四种属性的保存范围.所谓的属性保存范围,指的就是一个设置的对象,可以在多个页面中保存并可以继续使用.它们分别是:page.request.session.appliction. 1.pa ...
- oracle备份和还原
用exp命令即可完成,但要看具体的备份方式. 1. 导出一个完整数据库 exp system/manager file=bible_db log=dible_db full=y 2. 导出数据库定义而 ...
- day66—angularJS学习笔记-表达式
转行学开发,代码100天——2018-05-21 angular的变量数据初始化: ng-init="quantity=1;cost=30;student={firstName:'李',la ...
- Android下Native的so编译:使用ndk-build.cmd/.sh
最近将一个DLL库移植至安卓下,编译出so文件. 经历makefile.cmake等等的入门到放弃..... 最后还是使用android的ndk编译命令来解决 每个NDK文件下,均包含的是所有工具链. ...
- Windows下GIT的用户密码修改
Windows下GIT的用户密码修改
- map根据属性排序、取出map前n个
/** * map根据value排序 * flag = 1 正序 * flag = 0 倒序 * * @param map * @param flag * @return */ public stat ...
- Jmeter JDBC请求---把数据库结果参数化传递到其他请求
摘要: 最近一个场景进行压力测试:生成商品id进行上下架和购买,记录写脚本的一个过程 1.在商品上架前需要准备商品ID,商品ID生成需要从数据库读取商品类别,从而生成商品ID,下面是从数据库:读取商品 ...
- springboot(3) 页面到服务器
第一讲实现了spring boot 环境的下载及配置. 第二讲实现了,从服务器,到页面. 第三讲打算从页面到服务器. 比如,我们希望 从页面,点击一个按钮,传递信息到服务器. 就拿传递用户名和密码来简 ...
- IDEA激活—免费永久激活(lookdiv.com)
网址: http://lookdiv.com/ 钥匙就是网址 钥匙:lookdiv.com 亲测有效!非常好用.