题目链接: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. MOBA英雄AI设计分享

    转自:http://www.gamelook.com.cn/2018/07/333877 文/wataloo 1  设计概要 1.1  设计原则和目的 英雄AI的目的主要有: 1.新手过渡局,让玩家刚 ...

  2. windows下安装Kettle

    先下载kettle稳定版本https://community.hitachivantara.com/docs/DOC-1009855 下载后并且解压 安装kettle必须安装jdk在你的电脑上,ket ...

  3. (Android第一行代码实验一)活动的最佳实践

    活动的最佳实践    1.知晓当前是在哪一个活动         这个技巧将教会你,如何根据程序当前的界面就能判断出这是哪一个活动.  首先需要新建一个 BaseActivity 继承自 Activi ...

  4. Struts vs spring mvc

    1. 机制.spring mvc 的入口是servlet, 而struts是filter(这里要指出,filter和servlet是不同的.以前认为filter是servlet的一种特殊),这样就导致 ...

  5. VS2010 永久配置OpenCv2.4.9 及转换到COFF 期间失败:文件无效或损坏,解决方法

    1.下载OpenCv2.4.9(win pack):http://opencv.org/releases.html 下载完成后,进行解压(win7 64位系统) 2.环境配置,配置如下图所示: 找到p ...

  6. tesseract_vs2015工具包使用

    在vs中配置tesseract4.0: 新建一个空的控制台程序.并找到下图位置 双击.x64.user出现如下图: 单击VC++目录,将tesseract-2015/include/tesseract ...

  7. MANIPULATION

    MANIPULATION Generalizations Congratulations! You learned how to use the command line to view and ma ...

  8. 保存xml报错 'UTF_8' is not a supported encoding name

    ArgumentException: 'UTF_8' is not a supported encoding name. For information on defining a custom en ...

  9. 双网卡Iptables端口转发

    当前场景如下 跳板机A是双网卡,有一个内网IP和一个公网IP 内网IP: 10.0.10.30 外网IP:  58.68.255.123 内网机器:10.0.30.88,可以和10.0.10.30通讯 ...

  10. react-native 新手爬坑经历(Could not connect to development server.)

    来,先说下报错出现场景,刚跑完项目加载完是好的,但是双击R后就开始耍小脾气了-红屏出现,如下图 首先检查包服务器是否运行正常.在项目文件夹下输入react-native start或者npm star ...