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 ...
随机推荐
- Android批量验证渠道、版本号(windows版)
功能:可校验单个或目录下所有apk文件的渠道号.版本号,此为windows版,稍后整理Linux版使用说明:1.copy需要校验的apk文件到VerifyChannelVersion目录下2.双击运行 ...
- 报错:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1
错误现象: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-com ...
- aspose.cells 插入图片
,,"d:\\1.jpg"); Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[iIndex]; pic.Placeme ...
- FileMaker应用场景思考
大型企业有自己强大的IT队伍,但一些小需求没人理,小企业只有网管或没有专门的IT. 一般个人记录或处理数据时,Excel很够用了,但一个Team,Excel就明显有问题了,比如共享.权限控制?最简单的 ...
- python学习笔记之四-多进程&多线程&异步非阻塞
ProcessPoolExecutor对multiprocessing进行了高级抽象,暴露出简单的统一接口. 异步非阻塞 爬虫 对于异步IO请求的本质则是[非阻塞Socket]+[IO多路复用]: & ...
- 第24课 可变参数模板(5)_DllHelper和lambda链式调用
1. dll帮助类 (1)dll的动态链接 ①传统的调用方式:先调用LoadLibrary来加载dll,再定义函数指针类型,接着调用GetProcAddress获取函数地址.然后通过函数指针调用函数, ...
- Excel清除无用数据行和数据列
http://jingyan.baidu.com/article/6525d4b13ae608ac7c2e9478.html ctrl+shift+↓ ctrl+- ctrl+shift+→ ctrl ...
- 使用css实现时间轴
本文将使用css来实现一个左右交叉布局的时间轴,效果如下: 使用的都是一些常用的css,代码如下: <!DOCTYPE> <html> <head> <tit ...
- 用Jedis调用Lua脚本来完成redis的数据操作
1.先完成一个简单的set/get操作 package com.example.HnadleTaskQueue; import redis.clients.jedis.Jedis; import ja ...
- ASCS HA
Please let us know what do you mean by "the PAS can not be accessed", what error did you f ...