王强怎么这么强啊

王强太强了

二维树状数组

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int bit[2000][2000], n;
int lowbit(int x)
{
return x&-x;
}
void add(int x, int y, int num)
{
for(int i = x; i <= n; i += lowbit(i))
for(int j = y; j <= n; j += lowbit(j))
bit[i][j] += num;
}
int sum(int x, int y)
{
int res = 0;
for(int i = x; i > 0; i -= lowbit(i))
for(int j = y; j > 0; j -= lowbit(j))
res += bit[i][j];
return res;
}
int query(int a,int b,int c,int d)
{
return sum(c,d)-sum(a-1,d)-sum(c,b-1)+sum(a-1,b-1);
}
int main()
{
scanf("%d",&n);
int a,b,c,d,t;
for(int i=1;;i++)
{
scanf("%d",&t);
if(t==1)
{
scanf("%d%d%d",&a,&b,&c);
add(a+1,b+1,c);
}
if(t==2)
{
scanf("%d%d%d%d",&a,&b,&c,&d);
printf("%d\n",query(a+1,b+1,c+1,d+1));
}
if(t==3) return 0;
}
}

【luogu T34117 打油门】 题解的更多相关文章

  1. 【luogu P5022 旅行】 题解

    题目连接:https://www.luogu.org/problemnew/show/P5022 \(NOIP2018 DAY2T1\) 考场上只写了60分,很容易想到当 m = n - 1 时的树的 ...

  2. 【luogu P2831 愤怒的小鸟】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2831 写点做题总结:dp,搜索,重在设计状态,状态设的好,转移起来也方便. 对于一条抛物线,三点确定.(0, ...

  3. 【luogu P2827 蚯蚓】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2827 35分:暴力sortO(mnlogn). 80分:考虑到每次不好维护不被切的点+q,正难则反.改成维护 ...

  4. 【luogu P3959 宝藏】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3959 我只是心血来潮想学SA(考场上骗分总行吧). 这个题可以状压DP.爆搜+剪枝.有意思的还是随机化搜索( ...

  5. 【luogu P3410 拍照】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3410 这个题就是求一个最大权闭合图 在一个图中,一些点构成一个集合,且集合中的出边指向的终点也在这个集合中, ...

  6. 【luogu P1113 杂务】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1113 菜 #include <queue> #include <cstdio> #i ...

  7. 【luogu P4114 Qtree1】 题解

    题目链接:https://www.luogu.org/problemnew/show/P4114 1.把边权转化到点权:选取连接这条边的两个点中较深的一个. 2.查询点到点之间的边权时,要从seg[x ...

  8. 【luogu P3979 遥远的国度】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3979 除了换根操作都是裸的树剖 所以换根时考虑: 1.我查询的根等于换的根:无影响 2.我查询的根是换的根的 ...

  9. 【luogu P2169 正则表达式】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2169 tarjan缩点 + SPFA 缩完点之后加边注意别写错. 也可以不用建两个图,可以在一张图上判断是否 ...

随机推荐

  1. 虚拟机xp系统中Oracle 10g的安装

    1 安装过程(11步) 2.如果是xp系统可以直接并双击解压目录下的setup.ext,出现安装界面,如下: 3.输入口令和确认口令,如:oracle,点击下一步,出现如下进度条. 注:此口令即是管理 ...

  2. Wireshark使用技巧

    Wireshark使用技巧 在分析网络时,包应该尽量的小,只要能定位问题即可. 1. 只抓包头,在wireshark中可以设置抓包大小. 如果使用tcpdump命令: [root@server_1 / ...

  3. mongodb insert()、save()的区别

    mongodb 的 insert().save()  ,区别主要是:若存在主键,insert()  不做操作,而save() 则更改原来的内容为新内容. 存在数据:  { _id : 1, " ...

  4. How to Configure Tomcat/JBoss and Apache HTTPD for Load Balancing and Failover

    http://java.dzone.com/articles/how-configure-tomcatjboss-and In this post we will see how to setup a ...

  5. keepalive学习之软件设计

    软件架构如下图所示: Keepalived 完全使用标准的ANSI/ISO C写出. 该软件主要围绕一个中央I/O复用分发器而设计,这个I/O复用分发器提供网络实时功能. 主要设计目标着重于从所有的模 ...

  6. IE678不兼容CSS3 user-select:none(不可复制功能),需要JS解决

    [方法一:CSS3实现文本不可复制] .content {-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;-o- ...

  7. HDU 1394——Minimum Inversion Number——————【线段树单点增减、区间求和】

    Minimum Inversion Number Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  8. python 之闭包

    原文 函数作为返回值 高阶函数除了可以接受函数作为参数外,还可以把函数作为结果值返回. 我们来实现一个可变参数的求和.通常情况下,求和的函数是这样定义的: def calc_sum(*args): a ...

  9. SQL Server迭代求和

    drop table t_geovindu create table t_geovindu ( xid int IDENTITY (1, 1), price money, DebitCredit VA ...

  10. 软件项目技术点(2)——Canvas之平移translate、旋转rotate、缩放scale

    AxeSlide软件项目梳理   canvas绘图系列知识点整理 画布操作介绍 画布绘图的环境通过translate(),scale(),rotate(), setTransform()和transf ...