Codeforces 835C-Star sky
题目链接:http://codeforces.com/problemset/problem/835/C
题意:天上有很多星星,每个星星有他自己的坐标和初始亮度,然后每个星星的亮度在一秒内会加一如果大于最大亮度C就会变为0,然后观察星星,给出视野范围(矩形)的左下角和右上角,以及观察的时间,问视野中星星亮度总和是多少。
思路:当时做的时候一看这不是二维树状数组吗?但我没有考虑完,直接求的星星的初始亮度的前缀总和,显然这是错误的。正确的做法是开个三维的数组,一个是存星星的初始亮度(初始亮度最大只有10),另外两个相当于二维树状数组,计算亮度为X的星星的前缀和,然后查询的时候直接计算不同初始亮度在当前的亮度总和就是答案了。当前亮度是(初始+时间)%(C+1)。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX 105
int sky[][][];
int lowbit(int x)
{
return x&(-x);
}
void update_tree(int x,int y,int val)
{
for(int i=x;i<=MAX;i+=lowbit(i))
for(int j=y;j<=MAX;j+=lowbit(j))
sky[i][j][val]+=;
}
int query(int x,int y,int val)
{
int s=;
for (int i=x;i>;i-=lowbit(i))
for (int j=y;j>;j-=lowbit(j))
s+=sky[i][j][val];
return s;
}
int sum(int x,int y,int xx,int yy,int val)
{
x--,y--;
return query(xx,yy,val)-query(xx,y,val)-query(x,yy,val)+query(x,y,val);
}
int main()
{
int n,q,c;
int x,y,s,x1,y1,t;
scanf("%d%d%d",&n,&q,&c);
while(n--)
{
scanf("%d%d%d",&x,&y,&s);
update_tree(x,y,s);
}
while(q--)
{
scanf("%d%d%d%d%d",&t,&x,&y,&x1,&y1);
int ans=;
for(int i=;i<=;i++)
ans+=sum(x,y,x1,y1,i)*((i+t)%(c+));
printf("%d\n",ans);
}
return ;
}
Codeforces 835C-Star sky的更多相关文章
- CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)
s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...
- Codeforces 835C - Star sky - [二维前缀和]
题目链接:http://codeforces.com/problemset/problem/835/C 题意: 在天空上划定一个直角坐标系,有 $n$ 颗星星,每颗星星都有坐标 $(x_i,y_i)$ ...
- 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 #427 (Div. 2) C Star sky
C. Star sky time limit per test2 seconds memory limit per test256 megabytes inputstandard input outp ...
- Star sky 二维前缀和
C. Star sky time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- 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 ...
- Star sky CodeForces - 835C
用一个三维数组cnt[x][y][k]表示从(1, 1)到(x, y)亮度为k的个数,然后查询的时候就是对于每一个亮度,计算出这个亮度t秒后的亮度和当前这个亮度的个数,答案就是他们的乘积, 然后遍历每 ...
- 【Codeforces Round #427 (Div. 2) C】Star sky
[Link]:http://codeforces.com/contest/835/problem/C [Description] 给你n个星星的坐标(xi,yi); 第i个星星在第t秒,闪烁值变为(s ...
- Codeforces 997 C - Sky Full of Stars
C - Sky Full of Stars 思路: 容斥原理 题解:http://codeforces.com/blog/entry/60357 注意当i > 1 且 j > 1,是同一种 ...
- C. Star sky 二维前缀和
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
随机推荐
- python网页爬虫开发之二
1.网站robots robotparser模块首先加载robots.txt文件,然后通过can_fetch()函数确定指定的用户代理是否允许访问网页. 2.识别网站技术 3.下载网页 使用urlli ...
- 【Linux】【Selenium】安装Chrome和ChromeDriver的配置
转自:https://www.cnblogs.com/longronglang/p/8078898.html 1.安装chrome sudo apt-get install libxss1 libap ...
- uni-app开发小程序准备阶段
1.软件安装 开始之前,开发者需先下载安装如下工具: HBuilderX:官方IDE下载地址 下面开发工具根据需求进行安装: 微信小程序开发工具安装 https://developers.weixin ...
- tomcat JRE_HOME
tomcat 不知道什么时候开始需要 JRE_HOME了: D:\java\apache-tomcat-7.0.68\bin>startup.batJAVA_HOME == D:\Progra ...
- spring 之 BeanDefinition & BeanDefinitionParser
xml bean factory 的解析过程的 堆栈大概是这样的: at org.springframework.beans.factory.xml.NamespaceHandlerSupport.f ...
- 简单快捷使用Git
1.简介和安装Git是世界上目前最先进的分布式版本控制系统.安装:https://git-for-windows.github.io下载.设置姓名和email:git config --global ...
- Android开发中常见的设计模式(四)——策略模式
策略模式定义了一些列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变换. 假设我们要出去旅游,而去旅游出行的方式有很多,有步行,有坐火车,有坐飞机等等 ...
- mezzanine的page_menu tag(二)
dict的特性,key可以是None >>> def f(): a=[2,3] return a #函数返回local变量 >>> a=f() >>&g ...
- maven的tomcat插件问题
在dependence中不用加tomcat的jar, 记得在plugin中加入tomcat插件就行. 否则会出问题.
- leetcode279
动态规划 public class Solution { public int NumSquares(int n) { var list = new List<int>(); list.A ...