POJ1195Mobile phones
二维树状数组板子题。
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<cstdlib> 5 #include<algorithm> 6 #include<cmath> 7 #include<vector> 8 using namespace std; 9 #define mem(a,b) memset(a,b,sizeof(a)) 10 #define ll long long 11 #define inf 1000000000 12 #define maxn 40000 13 #define eps 1e-12 14 #define mod 1000000007 15 #define N 3005 16 inline int read() 17 { 18 int x=0,f=1;char ch=getchar(); 19 while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();} 20 while(ch>='0'&&ch<='9') {x=10*x+ch-'0';ch=getchar();} 21 return x*f; 22 } 23 int c[N][N],n; 24 int lowbit(int i) 25 { 26 return i&(-i); 27 } 28 int sum(int x,int y) 29 { 30 int ret=0; 31 for(int i=x;i>0;i-=lowbit(i)) 32 { 33 for(int j=y;j>0;j-=lowbit(j)) 34 ret+=c[i][j]; 35 } 36 return ret; 37 } 38 void add(int x,int y,int d) 39 { 40 for(int i=x;i<=n;i+=lowbit(i)) 41 for(int j=y;j<=n;j+=lowbit(j)) 42 { 43 c[i][j]+=d; 44 } 45 } 46 int main() 47 { 48 int k,op,x,y,i,j; 49 while(~scanf("%d%d",&i,&n)) 50 { 51 mem(c,0); 52 while(1) 53 { 54 op=read(); 55 if(op==3) break; 56 if(op==1) { 57 x=read();y=read();k=read(); 58 add(x+1,y+1,k); 59 } 60 else{ 61 int l,b,r,t; 62 l=read();b=read();r=read();t=read(); 63 l++;b++;r++;t++; 64 printf("%d\n",sum(r,t)-sum(r,b-1)-sum(l-1,t)+sum(l-1,b-1)); 65 } 66 } 67 } 68 return 0; 69 }
转载于:https://www.cnblogs.com/TYH-TYH/p/8903910.html
POJ1195Mobile phones相关推荐
- POJ-1195-Mobile phones
链接:https://vjudge.net/problem/POJ-1195 题意: 给一个S*S的矩阵,有两种操作,给(x,y)位置增加一个值,和求一个内部矩形的和. 思路: 二维树状数组,先对每行 ...
- POJ 1195 Mobile phones
链接:http://poj.org/problem?id=1195 Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Subm ...
- Take a Photo and Upload it on Mobile Phones with HTML5
In my daily life, I enjoy taking photos with my smartphone and uploading them to various websites. S ...
- How to increase sales, in addition to manufacturing different phones
How to increase sales, in addition to manufacturing different phones, there is also a price reductio ...
- 开源软电话 (Open Source Soft Phones)
开源软电话 (Open Source Soft Phones) 名字 描述 ActXPhone An ActiveX-Control SIP Softphone based on the Micros ...
- Planet of the phones手机星球
The smartphone is ubiquitous, addictive and transformative ubiquitous : adj 普通存在的 general addictive ...
- Dynamics 365 for Phones Android APK(v4.3.22042.2)下载
因国内安卓市场没有安卓的Dynamics 365 for Phones,只能从Google play下,但众所周知国内访问不了Google play,所以我下载后上传给有需要的人,会不定时更新,如果版 ...
- 利用多态特性,创建一个手机类Phones,定义打电话的方式call,创建三个子类,并在各自的方法中重写方法,编写程序入口main()方法,实现多种手机打电话...
|--需求说明 利用多态特性,创建一个手机类Phones,定义打电话的方式call,创建三个子类,并在各自的方法中重写方法,编写程序入口main()方法,实现两种手机打电话 |--解题思路 采用简单工 ...
- 【每日论文阅读】Collaborative Visual Inertial SLAM for Multiple Smart Phones
文章目录 论文阅读:Collaborative Visual Inertial SLAM for Multiple Smart Phones 摘要 主要贡献 算法逻辑 算法结果 论文阅读:Collab ...
最新文章
- GDI对象存储和查看lib文件导出函数
- 文巾解题 557. 反转字符串中的单词 III
- mybatis学习笔记(3)—数据库和bean名称不一样处理方案
- delete后加 limit是个好习惯么 ?
- flask中的static_path和static_path_url和static_folder
- xlrd读取所有sheet名_如何在Python对Excel进行读取
- 3.python(第三天日记)
- linux系统国产制图软件,国产操作系统也能用的国产图表绘制软件,替代Visio就用它了...
- 删除进程 linux,linux批量删除进程
- 企业之pacemaker基本概念及其原理
- 题6.12:有一行电文,已按照下面规律翻译成密码: A->Z a->z B->Y b->y C->X c->x即第1个字母编程第26个字母,第i个字母编程第(26-i+1)个字母,非字母字符不变,要求
- SWUN 1431 - 伊邪那美(Ⅱ)
- cobalt strick 4.0 系列教程(4)---监听器和基础设施管理
- 数据结构与算法笔记(青岛大学王卓老师视频)
- 播布客学习视频_C学习笔记_2_打印输出
- 开源!MatrixBench:实时物联网场景的数据压测“兵法秘籍”
- 第三方登录-[微博、微信、qq] java实现
- python排序输出人名_005_015 Python 人名按字母排序,首字母分组 | 学步园
- 完美解决KMplayer无法播放RMVB、RM电影问题
- otc焊接机器人编程模拟软件_OTC弧焊机器人离线编程系统开发.pdf