codeforces 835C Star sky(二维树状数组)
来源:互联网 发布:两电一邮 知乎 编辑:程序博客网 时间:2024/06/06 08:33
比较裸的二维树状数组,有一个思维点在于需要取模。每次查询的值不一样,但是因为c最多只有10,所以记录下0-10分别是哪个值即可。
#include <algorithm>#include <cstdio>#include <cmath>#include <map>using namespace std;const int MAXN=110;int a[11][MAXN][MAXN];int lowbit(int i){ return i&-i;}int c;int nn=100;int t;int tt;void add(int x,int y,int num){ for(int i=x;i<=nn;i+=lowbit(i)){ for(int j=y;j<=nn;j+=lowbit(j)){ a[tt][i][j]+=(num+tt)%(c+1); } }}int sum(int i, int j){ int result = 0; for(int x = i; x > 0; x -= lowbit(x)) { for(int y = j; y > 0; y -= lowbit(y)) { result += a[tt][x][y]; } } //printf("%d %d %d\n",i,j,result); return result;}int main(){ int n,q; scanf("%d%d%d",&n,&q,&c); for(int i=0;i<n;i++){ int x,y,z; scanf("%d%d%d",&x,&y,&z); for(tt=0;tt<=c;tt++){ add(x,y,z); } } for(int i=0;i<q;i++){ int x1,y1,x2,y2; scanf("%d%d%d%d%d",&t,&x1,&y1,&x2,&y2); tt=t%(c+1); printf("%d\n",sum(x2,y2)+sum(x1-1,y1-1)-sum(x1-1,y2)-sum(x2,y1-1)); }}
阅读全文
0 0
- codeforces 835C Star sky(二维树状数组)
- codeforces 835C Star sky (二维数组前缀和)
- Codeforces 835C-Star sky
- codeforces 835 C Star sky
- Codeforces 835 C Star sky
- CodeForces 835C Star sky
- codeforces 835c Star sky
- C. Star sky Codeforces
- Codeforces #835C: Star Sky 题解
- 【Codeforces 835 C. Star sky】+ dp
- CodeForces 835 C.Star sky(水~)
- Codeforces 853C Star sky(二维前缀和)
- Codeforces 835C Star sky【思维+暴力预处理二维前缀和】
- codeforces Star sky(二维前缀和)
- codeforces 835-C. Star sky(dp+前缀和)
- Codeforces 835 C Star sky(前缀和)
- Codeforces Round #427 (Div. 2)-C. Star sky(二维前缀和)
- Codeforces Round #427 (Div. 2) C. Star sky 二维前缀和
- python 操作数据库插入语句占位符问题
- (2017多校训练第二场)HDU
- [CTF]python求crc32值的方法
- Codeforces Round #427 (Div. 2)C. Star sky 暴力D. Palindromic characteristics
- Linux安装ftp组件
- codeforces 835C Star sky(二维树状数组)
- extends,with关键字的区别
- Linux下的常用命令(三)-scp,lsof
- Codeforces 835C
- MySQL插入中文字符不成功问题解决
- 基于AspectJ实现AOP
- 设计模式之策略模式
- webpack性能优化
- 数据结构顺序表的“增删改查”功能实现