C. Star sky 二维前缀和
2 seconds
256 megabytes
standard input
standard output
The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinates (xi, yi), a maximum brightness c, equal for all stars, and an initial brightness si (0 ≤ si ≤ c).
Over time the stars twinkle. At moment 0 the i-th star has brightness si. Let at moment t some star has brightness x. Then at moment (t + 1) this star will have brightness x + 1, if x + 1 ≤ c, and 0, otherwise.
You want to look at the sky q times. In the i-th time you will look at the moment ti and you will see a rectangle with sides parallel to the coordinate axes, the lower left corner has coordinates (x1i, y1i) and the upper right — (x2i, y2i). For each view, you want to know the total brightness of the stars lying in the viewed rectangle.
A star lies in a rectangle if it lies on its border or lies strictly inside it.
The first line contains three integers n, q, c (1 ≤ n, q ≤ 105, 1 ≤ c ≤ 10) — the number of the stars, the number of the views and the maximum brightness of the stars.
The next n lines contain the stars description. The i-th from these lines contains three integers xi, yi, si(1 ≤ xi, yi ≤ 100, 0 ≤ si ≤ c ≤ 10) — the coordinates of i-th star and its initial brightness.
The next q lines contain the views description. The i-th from these lines contains five integers ti, x1i, y1i, x2i, y2i (0 ≤ ti ≤ 109, 1 ≤ x1i < x2i ≤ 100, 1 ≤ y1i < y2i ≤ 100) — the moment of the i-th view and the coordinates of the viewed rectangle.
For each view print the total brightness of the viewed stars.
2 3 3
1 1 1
3 2 0
2 1 1 2 2
0 2 1 4 5
5 1 1 5 5
3
0
3
3 4 5
1 1 2
2 3 0
3 3 1
0 1 1 100 100
1 2 2 4 4
2 2 1 4 7
1 50 50 51 51
3
3
5
0
Let's consider the first example.
At the first view, you can see only the first star. At moment 2 its brightness is 3, so the answer is 3.
At the second view, you can see only the second star. At moment 0 its brightness is 0, so the answer is 0.
At the third view, you can see both stars. At moment 5 brightness of the first is 2, and brightness of the second is 1, so the answer is 3.
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
#define MAXN 109
#define N 100
/*
坐标的最大值比较小 开前缀数组求和
*/
LL a[MAXN][MAXN][];
LL n, q, c;
int main()
{
cin >> n >> q >> c;
int t1, t2, t3, t4;
for (LL i = ; i < n; i++)
{
cin >> t1 >> t2 >> t3;
a[t1][t2][t3]++;
}
for(int i =;i<=;i++)
for(int j=;j<=;j++)
for (int k = ; k < c + ; k++)
{
a[i][j][k] += a[i - ][j][k] + a[i][j - ][k] - a[i - ][j - ][k];
}
int T;
int x1, y1, x2, y2;
while (q--)
{
cin >> T >> x1 >> y1 >> x2 >> y2;
LL cnt = , sum = ;
for (int i = ; i < c + ; i++)
{
cnt = a[x2][y2][i] - a[x2][y1 - ][i] - a[x1 - ][y2][i] + a[x1 - ][y1 - ][i];
sum += cnt*((i + T) % (c + ));
}
cout << sum << endl;
}
}
错误的二分代码:
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
#define MAXN 100005
#define N 100
/*
二分查找区域内符合范围的点,取模运算求和
...
*/
struct star
{
LL x, y, s;
bool operator<(const star& rhs)
{
if (x == rhs.x)
return y < rhs.y;
else
return x < rhs.x;
}
}a[MAXN];
LL n, q, c;
LL t, X1, Y1, X2, Y2;
LL sum = ;
void solve(LL l, LL r)
{
if (l > r)
return;
if (l == r)
{
if (a[l].x >= X1&&a[l].x >= Y1&&a[l].x <= X2&&a[l].y <= Y2)
sum += (a[l].s + t) % (c + );
return;
}
LL mid = (l + r) / ;
//cout << mid << endl;
if (a[mid].x > X2)
solve(l, mid - );
else if (a[mid].x < X1)
solve(mid + , r);
else
{
if (a[mid].x >= X1&&a[mid].x >= Y1&&a[mid].x <= X2&&a[mid].y <= Y2)
sum += (a[mid].s + t) % (c + );
solve(l, mid - );
solve(mid + , r);
}
}
int main()
{
scanf("%lld%lld%lld", &n, &q, &c);
for (LL i = ; i < n; i++)
scanf("%lld%lld%lld", &a[i].x, &a[i].y, &a[i].s);
sort(a, a + n);
while (q--)
{
sum = ;
scanf("%lld%lld%lld%lld%lld", &t, &X1, &Y1, &X2, &Y2);
solve(, n-);
printf("%lld\n", sum);
}
return ;
}
C. Star sky 二维前缀和的更多相关文章
- Codeforces 835C - Star sky - [二维前缀和]
题目链接:http://codeforces.com/problemset/problem/835/C 题意: 在天空上划定一个直角坐标系,有 $n$ 颗星星,每颗星星都有坐标 $(x_i,y_i)$ ...
- Star sky 二维前缀和
C. Star sky time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- openjudge1768 最大子矩阵[二维前缀和or递推|DP]
总时间限制: 1000ms 内存限制: 65536kB 描述 已知矩阵的大小定义为矩阵中所有元素的和.给定一个矩阵,你的任务是找到最大的非空(大小至少是1 * 1)子矩阵. 比如,如下4 * 4的 ...
- COGS1752 [BOI2007]摩基亚Mokia(CDQ分治 + 二维前缀和 + 线段树)
题目这么说的: 摩尔瓦多的移动电话公司摩基亚(Mokia)设计出了一种新的用户定位系统.和其他的定位系统一样,它能够迅速回答任何形如“用户C的位置在哪?”的问题,精确到毫米.但其真正高科技之处在于,它 ...
- poj-3739. Special Squares(二维前缀和)
题目链接: I. Special Squares There are some points and lines parellel to x-axis or y-axis on the plane. ...
- Good Bye 2015 C. New Year and Domino 二维前缀
C. New Year and Domino They say "years are like dominoes, tumbling one after the other". ...
- 计蒜客模拟赛D1T1 蒜头君打地鼠:矩阵旋转+二维前缀和
题目链接:https://nanti.jisuanke.com/t/16445 题意: 给你一个n*n大小的01矩阵,和一个k*k大小的锤子,锤子只能斜着砸,问只砸一次最多能砸到多少个1. 题解: 将 ...
- 二维前缀和模板题:P2004 领地选择
思路:就是使用二维前缀和的模板: 先放模板: #include<iostream> using namespace std; #define ll long long ; ll a[max ...
- 二维前缀和好题hdu6514
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; ]; )* ...
随机推荐
- 乐搏讲自动化测试-python语言特点及优缺点(5)
相信小伙伴们都知道,随着软件测试行业的发展和进步自动化测试已经成为必然.在竞争日益激烈的市场环境中也是你升职加薪的利器. 所以,小编决定从今天起!将要系统.连续.高质量的持续更新「整套自动化测试」文章 ...
- c++ isdigit函数
函数名:isdigit 函数所需头文件:#include<cstdio> 函数格式:isdigit(字符) 函数作用:判断括号内是否为1~9的数字. 例:isdigit(4) 就是true ...
- 1.2打印ASCII码
描述 输入一个除空格以外的可见字符(保证在函数scanf中可使用格式说明符%c读入),输出其ASCII码. 输入一个除空格以外的可见字符.输出一个十进制整数,即该字符的ASCII码.样例输入 A 样例 ...
- EasyUI tree 异步树与采用扁平化实现的同步树
所谓好记性不如烂笔头,为了以防忘记,才写下这篇博客,废话不多.. 异步树: tips: 可以采用easyui里的原始数据格式,也可以采用扁平化的数据格式. 使用场景: 当菜单模块数量庞大或者无限极 ...
- Linux shell命令之cat
cat:查看文件的内容.连接文件.创建一个或多个文件和重定向输出到终端或文件 用法:cat [选项] [文件] 1. $ cat hello.txt 显示hello.txt文本文件中的内容 2. $ ...
- JavaScript(七)数组
Array类型 1.创建数组 字面量 var arr = [];//不要在低版本的浏览其中创建字面量的时候最后 //一个item后面加 逗号 低版本会 再新建一个空的item 构造函数 var arr ...
- 【Python-2.7】换行符和制表符
在Python中换行符“\n”表示接下来的内容将会换到下一行显示,制表符“\t”表示下面的内容显示时在前面留出空白,如打印如下内容: Dear: I love you forever! 上面的一段话分 ...
- 安卓app测试之内存监控
一.通过Dumpsys 来取值 1.adb shell dumpsys meminfo 获取的所有进程的内存信息,以及总内存,剩余内存,使用的内存等信息. 2.想获得某一进程内存的详细信息,在后面加上 ...
- 梦想CAD控件安卓界面控制
CAD控件界面上所有元素都可以控制显示或隐藏,下面将逐一介绍详细用法. 设置工具文件 MxFunction.setToolFile 设置工具文件.详细说明如下: 参数 说明 String sFile ...
- js实现字符串反转
方案1: var str = "abcdef"; console.log( str.split("").reverse().join("") ...