POJ 1195 Mobile phones【 二维树状数组 】
题意:基础的二维数组,注意 0 + lowbit(0)会陷入无限循环-----
之前做一道一维的一直tle,就是因为这个--------------------------
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include <cmath>
- #include<stack>
- #include<vector>
- #include<map>
- #include<set>
- #include<queue>
- #include<algorithm>
- using namespace std;
- typedef long long LL;
- const int INF = (<<)-;
- const int mod=;
- const int maxn=;
- int c[][];
- int n;
- int lowbit(int x){ return x & (-x);}
- int sum(int x,int y){
- int ret = ,y1;
- while(x > ){
- y1 = y;
- while( y1 > ){
- ret += c[x][y1];y1 -= lowbit(y1);
- }
- x-=lowbit(x);
- }
- return ret;
- }
- void add(int x,int y,int d){
- int y1;
- while(x <= n){
- y1 = y;
- while(y1 <= n){
- c[x][y1] += d; y1 += lowbit(y1);
- }
- x += lowbit(x);
- }
- }
- int main(){
- int cmd;
- while(scanf("%d %d",&cmd,&n) != EOF){
- memset(c,,sizeof(c));
- while(scanf("%d",&cmd) != EOF && cmd != ){
- if(cmd == ){
- int x,y,d;
- scanf("%d %d %d",&x,&y,&d);x++;y++;
- add(x,y,d);
- }
- else{
- int x,y,xx,yy;
- int ret = ;
- scanf("%d %d %d %d",&x,&y,&xx,&yy);
- x++;y++;xx++;yy++;
- ret = sum(xx,yy) - sum(x-,yy) - sum(xx,y-) + sum(x-,y-);
- printf("%d\n",ret);
- }
- }
- }
- return ;
- }
话说好几天没有写代码了的说啊----
加油↖(^ω^)↗
goooooooooooooooooo----
POJ 1195 Mobile phones【 二维树状数组 】的更多相关文章
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- POJ 1195:Mobile phones 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16893 Accepted: 7789 De ...
- 【poj1195】Mobile phones(二维树状数组)
题目链接:http://poj.org/problem?id=1195 [题意] 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y ...
- POJ 2155 Matrix【二维树状数组+YY(区间计数)】
题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- POJ 2155 Matrix(二维树状数组+区间更新单点求和)
题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...
- POJ 2155 Matrix (二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17224 Accepted: 6460 Descripti ...
- POJ 2155 Matrix 【二维树状数组】(二维单点查询经典题)
<题目链接> 题目大意: 给出一个初始值全为0的矩阵,对其进行两个操作. 1.给出一个子矩阵的左上角和右上角坐标,这两个坐标所代表的矩阵内0变成1,1变成0. 2.查询某个坐标的点的值. ...
- POJ 2155 Matrix (二维树状数组)题解
思路: 没想到二维树状数组和一维的比只差了一行,update单点更新,query求和 这里的函数用法和平时不一样,query直接算出来就是某点的值,怎么做到的呢? 我们在更新的时候不止更新一个点,而是 ...
- POJ 2155:Matrix 二维树状数组
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 21757 Accepted: 8141 Descripti ...
- POJ 2155 Matrix(二维树状数组)
与以往不同的是,这个树状数组是二维的,仅此而已 #include <iostream> #include <cstdio> #include <cstring> # ...
随机推荐
- P2740 [USACO4.2]草地排水Drainage Ditches
题目背景 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水系统来使贝茜的草地免除被大水淹没 ...
- Paper-[arXiv 1710.03144]Island Loss for Learning Discriminative Features in Facial Expression
[arXiv 1710.03144]Island Loss for Learning Discriminative Features in Facial Expression ABSTRACT 作者在 ...
- 第十三章 Python并发编程
并发编程之多进程 python中如果想要充分的利用多核CPU的资源,大部分情况需要使用多进程,python提供了multiprocessing multiprocessing模块用来开启子进程,并在子 ...
- Pyhton学习——Day9(阶段性练习)
# 1.文件内容如下,标题为:姓名,性别,年纪,薪资## egon male 18 3000# alex male 38 30000# wupeiqi female 28 20000# yuanhao ...
- java web 初尝遇到的坑
1. 配置 tomcat 7 + Dynamic web model version 3 发现写 web.xml 导致 tomcat 不能启动. 解决办法:tomcat 7 之后有两种配置 servl ...
- Python笔记27----时间解析
1.将时间字符串解析成真正的时间 time.strptime http://www.runoob.com/python/att-time-strptime.html 代码: import time s ...
- [学习笔记] CS131 Computer Vision: Foundations and Applications:Lecture 4 像素和滤波器
Background reading: Forsyth and Ponce, Computer Vision Chapter 7 Image sampling and quantization Typ ...
- apche本地测试,无法访问此网站
- POI 详细介绍
Apache POI是一个开源的Java读写Excel.WORD等微软OLE2组件文档的项目.目前POI已经有了Ruby版本. 结构: HSSF - 提供读写Microsoft Excel XLS格式 ...
- MRv2 工作机制 、 公平调度器、MR压缩、边数据
对于节点数超过 4000 的大型集群,前一节描述的 MapReduce 系统开始面临着扩展的瓶颈. 2010 年 Yahoo 的团队开始设计下一代的 MapReduce. (Yet Another R ...