codeforces 835C(二维前缀和)
来源:互联网 发布:seo零基础 编辑:程序博客网 时间:2024/06/05 05:11
题意:给出一些点的值,查询在一个时间点一段区间的值。点的值会随时间每次增加一,然后取(k + 1)的模。
思路:以为k是<=10,所以可以把每个时刻每一段的前缀和弄出来,然后查询的时候就行。
PS:一个点不只是一个值,在这个地方被卡。二维前缀和的构造和维护可以复习一下。
#include<bits/stdc++.h>using namespace std;typedef pair<int,int> P;const int maxn = 100000 + 10;typedef long long ll;#define INF 0x3f3f3f3fint a[12][maxn];P b[maxn];int sum[12][110][110];int maze[12][110][110];int main(){ int n,m,k; while( ~ scanf("%d%d%d",&n,&m,&k)) { memset(sum,0,sizeof(sum)); memset(maze,0,sizeof(maze)); for(int i = 1; i <= n; i ++) { scanf("%d%d%d",&b[i].first,&b[i].second,&a[0][i]); } for(int i = 0; i <= k; i ++) { for(int j = 1; j <= n; j ++) { maze[i][b[j].first][b[j].second] += (a[0][j] + i) % (k + 1); } } for(int ks = 0;ks <= k; ks ++) { for(int i = 1; i < 110; i ++) { for(int j = 1; j < 110; j ++) { sum[ks][i][j] = sum[ks][i][j - 1] + sum[ks][i - 1][j] - sum[ks][i - 1][j - 1] + maze[ks][i][j]; } } } for(int i = 1; i <= m; i ++) { int t,x1,y1,x2,y2;scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2); printf("%d\n",sum[t % (k + 1)][x2][y2] - sum[t % (k + 1)][x2][y1 - 1] - sum[t % (k + 1)][x1 - 1][y2] + sum[t % (k + 1)][x1 - 1][y1 - 1] ); } } return 0;}
阅读全文
0 0
- codeforces 835C(二维前缀和)
- codeforces 835C Star sky (二维数组前缀和)
- 二维前缀和 codeforces 832C
- Codeforces 611C:New Year and Domino 二维前缀和
- Codeforces 611C:New Year and Domino 二维前缀和
- Codeforces 853C Star sky(二维前缀和)
- Codeforces 835C Star sky【思维+暴力预处理二维前缀和】
- codeforces Star sky(二维前缀和)
- Codeforces Round #427 (Div. 2)-C. Star sky(二维前缀和)
- Codeforces Round #427 (Div. 2) C. Star sky 二维前缀和
- Codeforces Round #427 (Div. 2) C.Star sky【模拟、二维前缀和】
- codeforces835 b贪心 c 二维前缀和
- codeforces.contest/835/problem/C(三维前缀和)
- codeforces 835-C. Star sky(dp+前缀和)
- Codeforces 835 C Star sky(前缀和)
- Codeforces 828B Black Square【暴力枚举+二维前缀和】
- Codeforces 846D Monitor(二维前缀和)
- Codeforces 106D Treasure Island【思维+二维前缀和】
- P2P中的NAT穿越方案简介
- 从日常开发说起,浅谈HTTP协议是做什么的
- js的image()循环创建,src始终为最近创建的那个解决办法(给image.onload传参)
- Javascript之Object.assign()
- 第十七章:容器深入研究
- codeforces 835C(二维前缀和)
- 算法-array-6-ReshapetheMatrix
- cmd命令行显示中文乱码
- Java学习笔记---实现文件随机读写-RandomAccessFile
- ASP.NET Web Pages – 文件
- RobotFramework 使用远程测试库
- tomcat报错:严重: The required Server component failed to start so Tomcat is unable to start. org.apache.
- js空连接点击不跳转
- CentOS6.8 SVN服务器管理多项目