POJ 1195 Mobile phones【 二维树状数组 】
题意:基础的二维数组,注意 0 + lowbit(0)会陷入无限循环-----
之前做一道一维的一直tle,就是因为这个--------------------------
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<map> 8 #include<set> 9 #include<queue> 10 #include<algorithm> 11 using namespace std; 12 13 typedef long long LL; 14 const int INF = (1<<30)-1; 15 const int mod=1000000007; 16 const int maxn=1000005; 17 18 int c[1055][1055]; 19 int n; 20 21 int lowbit(int x){ return x & (-x);} 22 23 int sum(int x,int y){ 24 int ret = 0,y1; 25 while(x > 0){ 26 y1 = y; 27 while( y1 > 0){ 28 ret += c[x][y1];y1 -= lowbit(y1); 29 } 30 x-=lowbit(x); 31 } 32 return ret; 33 } 34 35 void add(int x,int y,int d){ 36 int y1; 37 while(x <= n){ 38 y1 = y; 39 while(y1 <= n){ 40 c[x][y1] += d; y1 += lowbit(y1); 41 } 42 x += lowbit(x); 43 } 44 } 45 46 int main(){ 47 int cmd; 48 while(scanf("%d %d",&cmd,&n) != EOF){ 49 memset(c,0,sizeof(c)); 50 while(scanf("%d",&cmd) != EOF && cmd != 3){ 51 if(cmd == 1){ 52 int x,y,d; 53 scanf("%d %d %d",&x,&y,&d);x++;y++; 54 add(x,y,d); 55 } 56 else{ 57 int x,y,xx,yy; 58 int ret = 0; 59 scanf("%d %d %d %d",&x,&y,&xx,&yy); 60 x++;y++;xx++;yy++; 61 ret = sum(xx,yy) - sum(x-1,yy) - sum(xx,y-1) + sum(x-1,y-1); 62 printf("%d\n",ret); 63 } 64 } 65 } 66 return 0; 67 }
View Code
话说好几天没有写代码了的说啊----
加油↖(^ω^)↗
goooooooooooooooooo----
转载于:https://www.cnblogs.com/wuyuewoniu/p/4604731.html
POJ 1195 Mobile phones【 二维树状数组 】相关推荐
- hoj 1640 Mobile phones //poj 1195 Mobile phones 二维树状数组
/* (x1,y2) ____________ (x2,y2) | | | | | ...
- POJ_1195 Mobile phones 【二维树状数组】
题目链接:http://poj.org/problem?id=1195 纯纯的二维树状数组,不解释,仅仅须要注意一点,由于题目中的数组从0開始计算,所以维护的时候须要加1.由于树状数组的下标是不能为1 ...
- poj 1195(二维树状数组)
解题思路:这是一道很裸的二维树状数组 AC: #include<stdio.h> #include<string.h> #define N 1100 int c[N][N],n ...
- 二维树状数组 ----2021广东省赛 ----- K - Kera‘s line segment[区间转二维平面+树状数组维护前缀最小最大值]
题目链接 题目大意: 就是一个一维的数轴上面有一堆线段用一个三元组(l,r,val)(l,r,val)(l,r,val)表示. 现在我们有两个操作: 就是往数轴上面添加线段 询问[L,R][L,R][ ...
- szu 寒训第二天 树状数组 二维树状数组详解,以及树状数组扩展应用【求逆序对,以及动态第k小数】
树状数组(Binary Index Tree) 树状数组可以解决可以转化为前缀和问题的问题 这是一类用以解决动态前缀和的问题 (有点像线段树简版) 1.对于 a1 + a2 + a3 + - + an ...
- 【二维树状数组】See you~
https://www.bnuoj.com/v3/contest_show.php?cid=9148#problem/F [题意] 给定一个矩阵,每个格子的初始值为1.现在可以对矩阵有四种操作: A ...
- 洛谷1527(bzoj2738)矩阵乘法——二维树状数组+整体二分
题目:https://www.luogu.org/problemnew/show/P1527 不难想到(?)可以用二维树状数组.但维护什么?怎么查询是难点. 因为求第k小,可以考虑记权值树状数组,把比 ...
- 二维树状数组 BZOJ 1452 [JSOI2009]Count
题目链接 裸二维树状数组 #include <bits/stdc++.h>const int N = 305; struct BIT_2D {int c[105][N][N], n, m; ...
- HDU-4456 Crowd 二维树状数组+坐标转换
题意:给定一个N*N的网格,现在M组操作,一种操作时改变网格上的某个单点的权值,另外一种操作是求到一点曼哈顿距离为小于等于k的所有的权值和,初始化网格所有点的权值为0. 解法:这题如果没有那些特定的条 ...
- hdu 1892二维树状数组
这题我知道是用树状数组,可是好久没打树状数组了,就想用普通方法水过去~~结果--结果--水了好多方法都水不过,出题人真狠呐--我的水方法是对于每一次查询,初始化ans=(x2-x1+1)*(y2-y1 ...
最新文章
- 在HANA里设置后台Job
- jupyter notebook切换到其他配置好的conda虚拟环境
- 哈夫曼树(Huffman Tree)的介绍、画法、哈夫曼树的可视化显示(Python代码实现)
- 处理机和处理器的区别
- 【转】const_cast
- 官网下载mysql安装包
- 新版码支付个人免签支付系统源码+实测成功
- centos7虚拟机网桥模式不通_Centos7虚拟机桥接模式
- phpmyadmin linux 安装,phpMyAdmin安装部署
- python检查验证_Python:在时间、日期之间进行检查。验证日期
- 不得不会的linux账号与权限管理
- iOS真机测试详细步骤及图解
- 古天乐一哭,电影宣传又跪了下来
- 【SAM】51Nod1647 小Z的Trie
- 推送github报错“The remote end hung up unexpectedly”解决办法
- 字符集本地化(locale)与输入法系列讲座-----(3) truetype造字程序详解
- 键盘输入 vs 复制粘贴
- 2019牛客暑期多校训练营(第九场)Quadratic equation(二次剩余
- ilight app android,ilight智能彩灯
- 安装VS2015时出现“安装包丢失或损坏”