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 ...
随机推荐
- centos7如何查找文件?
参考https://blog.csdn.net/allyli0022/article/details/77989664 一.find 根据文件的属性进行查找,如文件名,文件大小,所有者,所属组,是否为 ...
- bzoj5048: 塌陷的牧场
Description 农夫小Q将他的奶牛们饲养在一个长n宽m的矩形网格牧场中.行从上到下依次编号为1到n,列从左往右依次编号为1 到m.为了防止奶牛们逃跑,小Q在牧场外圈安装了一排电网,只要奶牛走出 ...
- SpringCloud和Springboot
SpringBoot+SpringCloud+SpringMVC+SpringData 我们把这种架构也称之为spring全家桶 什么是SpringCloudSpring Cloud是一系列框架的有序 ...
- Web jsp开发学习——网上直播聊天室的简单开发
整个界面为chat.jsp: 如果用户没有登录,就不能进行聊天. 为将发言的句子传到页面上,要设置一个<iframe></iframe>虚拟框架,将allmessage.jsp ...
- 20165312 2017-2018-2 《JAVA程序设计》第4周学习总结
一.课本五六章知识点总结 1.第五章 继承是一种由已有的类创建新类的机制 子类继承父类的成员变量和方法 子类继承的方法只能操作子类继承和隐藏的成员变量 子类重写或新增的方法只能操作子类继承和新声明的成 ...
- Mysql TIMESTAMPDIFF测试
select TIMESTAMPDIFF(DAY, '2015-04-20 00:00:00', '2015-04-20 23:59:59');# 只要不足24小时 为0天 select TIMEST ...
- gentoo emerge L10N
gentoo 中安装软件的时候 emerge 提示 USE 中有 语言包可选安装,使用 L10N 来设置,设置方法是在USE中使用 l10n_,比如说 l10n_zh_CN 来安装中文支持包.
- profile default1
DEVPISAP01:/sapmnt/ISD/profile # more ISD_J20_SHADEVEAIAP01 SAPSYSTEMNAME = ISD SAPSYSTEM = 20 INSTA ...
- 批量移动AD用户到指定OU
原文链接:http://blog.51cto.com/shubao/1346469 作为域管理员,在日常工作中使用ADUC(AD用户和计算机)工具在图形界面中进行账号管理操作可谓是家常便饭了.然而一个 ...
- Linq(高级查询)
一.条件查 public List<Users> ss(string ids) { List<Users> ulist=new List<Users>(); 声明使 ...