CF835 C 前缀和
100*100规模上第一象限坐标系上有1e5规模的点,每个点随时间在同一个值域内(最大10)周期递增,但初始值不同,给出一个矩阵和时间询问此时范围内点的值的和。
预处理初始时刻不同权值下的二维前缀和,对于每个询问再次遍历所有权值,累计和就好了。
/** @Date : 2017-08-12 10:28:03
* @FileName: C.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; int n, q, c;
LL f[11][110][110];
int main()
{
while(cin >> n >> q >> c)
{
MMF(f);
for(int i = 0; i < n; i++)
{
int x, y, s;
scanf("%d%d%d", &x, &y, &s);
f[s][x][y]++;
}
for(int k = 0; k <= c; k++/*, cout << endl*/)
for(int i = 1; i <= 100; i++)
{
for(int j = 1; j <= 100; j++)
{
f[k][i][j] += f[k][i][j - 1] + f[k][i - 1][j] - f[k][i - 1][j - 1];
//cout << f[k][i][j] << " ";
}
//cout << endl;
} while(q--)
{
LL t, x1, y1, x2, y2;
scanf("%lld%lld%lld%lld%lld", &t, &x1, &y1, &x2, &y2);
LL ans = 0;
LL tmp = 0;
for(int i = 0; i <= 10; i++)
{
tmp = (f[i][x2][y2] - f[i][x2][y1 - 1] - f[i][x1 - 1][y2] + f[i][x1 - 1][y1 - 1]);
ans += ((i + t) % (c + 1)) * tmp;
}
printf("%lld\n", ans);
}
}
return 0;
}
CF835 C 前缀和的更多相关文章
- HDU1671——前缀树的一点感触
题目http://acm.hdu.edu.cn/showproblem.php?pid=1671 题目本身不难,一棵前缀树OK,但是前两次提交都没有成功. 第一次Memory Limit Exceed ...
- 【手记】注意BinaryWriter写string的小坑——会在string前加上长度前缀length-prefixed
之前以为BinaryWriter写string会严格按构造时指定的编码(不指定则是无BOM的UTF8)写入string的二进制,如下面的代码: //将字符串"a"写入流,再拿到流的 ...
- ASP.NET Core MVC 配置全局路由前缀
前言 大家好,今天给大家介绍一个 ASP.NET Core MVC 的一个新特性,给全局路由添加统一前缀.严格说其实不算是新特性,不过是Core MVC特有的. 应用背景 不知道大家在做 Web Ap ...
- 如何处理CSS3属性前缀
今天闲来无聊,重新来说说CSS3前缀的问题.在春节前和@一丝姐姐说起Sass中有关于gradient的mixins.姐姐说: 为什么还要用mixin呢?为什么不使用Autoprefixer?使用Aut ...
- context:component-scan" 的前缀 "context" 未绑定。
SpElUtilTest.testSpELLiteralExpressiontestSpELLiteralExpression(cn.zr.spring.spel.SpElUtilTest)org.s ...
- 解决adobe air sdk打包 apk后自动在包名前面加上air. (有个点)前缀的问题
早就找到了这个方法,但是一直忙没心思写博客. 默认情况下,所有 AIR Android 应用程序的包名称都带 air 前缀.若不想使用此默认行为,可将计算机环境变量 AIR_NOANDROIDFLAI ...
- adobe air类app 接入腾讯开放平台移动游戏使用带tencent包名前缀的问题
作者:Panda Fang 出处:http://www.cnblogs.com/lonkiss/p/4209159.html 原创文章,转载请注明作者和出处,未经允许不可用于商业营利活动 ------ ...
- [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- [LeetCode] Longest Common Prefix 最长共同前缀
Write a function to find the longest common prefix string amongst an array of strings. 这道题让我们求一系列字符串 ...
随机推荐
- Spark Shuffle之Sort Shuffle
源文件放在github,随着理解的深入,不断更新,如有谬误之处,欢迎指正.原文链接https://github.com/jacksu/utils4s/blob/master/spark-knowled ...
- vsftpd:非常安全的ftp服务端程序
主程序:/usr/sbin/vsftpd 主配置文件:/etc/vsftpd/vsftpd.conf CentOS 6 /etc/rc.d/init.d/vsftpd chkconfig vsftp ...
- C语言文法推导
- PHP qrcode 生成二维码
<?php /* 下载地址 : https://sourceforge.net/projects/phpqrcode/ 这里下载的文件名为 phpqrcode-2010100721_1.1.4 ...
- windows操作系统下载tomcat,并与eclipse进行整合
进入Tomcat官网之后,在左边我们看到,Tomcat的有6,7,8这三个最流行的版本,我们可以点击进去下载想要的版本. 进入里面之后,可以看见有64位的和32位的,就看自己的电脑是多少位的了,如果电 ...
- Java 调用 google 翻译
1.Java代码 public class Translator { public String translate(String langFrom, String langTo, String wo ...
- Spring事务管理Transaction【转】
Spring提供了许多内置事务管理器实现(原文链接:https://www.cnblogs.com/qiqiweige/p/5000086.html): DataSourceTransactionMa ...
- Using the command line to manage files on HDFS--转载
原文地址:http://zh.hortonworks.com/hadoop-tutorial/using-commandline-manage-files-hdfs/ In this tutorial ...
- [cogs1065]绿豆蛙的归宿
1065. [Nescafe19] 绿豆蛙的归宿 [题目描述] 给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度.绿豆蛙从起点出发,走向终点.到达每一个顶点时,如果有K条离开该点的道路, ...
- python基础----封装、封装与扩展性
从封装本身的意思去理解,封装就好像是拿来一个麻袋,把小猫,小狗,小王八,还有egon和alex一起装进麻袋,然后把麻袋封上口子.但其实这种理解相当片面 首先我们要了解 要封装什么 你钱包的有多少钱(数 ...