题目链接: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的更多相关文章

  1. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

  2. Codeforces 835C - Star sky - [二维前缀和]

    题目链接:http://codeforces.com/problemset/problem/835/C 题意: 在天空上划定一个直角坐标系,有 $n$ 颗星星,每颗星星都有坐标 $(x_i,y_i)$ ...

  3. 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 ...

  4. 动态规划:Codeforces Round #427 (Div. 2) C Star sky

    C. Star sky time limit per test2 seconds memory limit per test256 megabytes inputstandard input outp ...

  5. Star sky 二维前缀和

    C. Star sky time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  6. 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 ...

  7. Star sky CodeForces - 835C

    用一个三维数组cnt[x][y][k]表示从(1, 1)到(x, y)亮度为k的个数,然后查询的时候就是对于每一个亮度,计算出这个亮度t秒后的亮度和当前这个亮度的个数,答案就是他们的乘积, 然后遍历每 ...

  8. 【Codeforces Round #427 (Div. 2) C】Star sky

    [Link]:http://codeforces.com/contest/835/problem/C [Description] 给你n个星星的坐标(xi,yi); 第i个星星在第t秒,闪烁值变为(s ...

  9. Codeforces 997 C - Sky Full of Stars

    C - Sky Full of Stars 思路: 容斥原理 题解:http://codeforces.com/blog/entry/60357 注意当i > 1 且 j > 1,是同一种 ...

  10. C. Star sky 二维前缀和

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. 浅读官方代码--ActionManager

    用于管理节点的动作 { CCDirector* pDirector = CCDirector::sharedDirector(); //获得单例 pDirector->getActionMana ...

  2. C++Primer第五版——习题答案详解(五)

    习题答案目录:https://www.cnblogs.com/Mered1th/p/10485695.html 第6章 函数 练习6.4 #include<iostream> using ...

  3. 使用RecyclerView实现聊天界面

    原文地址:https://blog.csdn.net/wang_wy/article/details/79032698

  4. VS2012 C# 连接MySQL数据库

    原则:不安装 1.下载: https://dev.mysql.com/downloads/connector/net/6.8.html#downloads 2.解压 → 3.添加引用(一个MySql. ...

  5. Java 多态的实现机制

    http://my.oschina.net/onlytwo/blog/52222 是父类或接口定义的引用变量可以指向子类或实现类的实例对象,而程序调用的方法在运行期才动态绑定,就是引用变量所指向的具体 ...

  6. UEditor (富文本编译器)

    下载网址:https://ueditor.baidu.com/website/download.html 开发文档:http://fex.baidu.com/ueditor/

  7. dubbo实现原理介绍

      一.什么是dubbo Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合).从服务模型的角度来看,     ...

  8. 解决idea创建Maven项目卡在running tmp archetypexxxtmp

    打开IDEA settings 然后在VM Options内添加-DarchetypeCatalog=internal 运行参数

  9. VS2015+Opencv3.2配置(一次配好)

    对于 VS2015+QT5.8的配置我就不介绍了,由于我配置的比较早,具体有的东西忘掉了,大家可以参考下面这几篇文章. 留白留白留白留白留白(稍后补) 对于Opencv+VS的配置是我重点要说的内容. ...

  10. background url base64

    各自含义:data: ----获取数据类型名称image/gif; -----指数据类型名称base64 -----指编码模式AAAAA ------指编码以后的结果. background-imag ...