王强怎么这么强啊

王强太强了

二维树状数组

#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. [转]jQuery Validate使用说明

    本文转自:http://www.cnblogs.com/gimin/p/4757064.html jQuery Validate 导入 js 库 <script src="./jque ...

  2. UML建模概述

    UML的组成主要有事物.图.关系. UML中的事物: (1)构件事物:UML模型的静态部分,描述概念或物理元素,包括以下 a. 类:类是对一组具有相同属性.相同操作.相同关系和相同语义的对象的抽象.包 ...

  3. json对象字符串互转

    json对象字符串互转 1.Node.js中 JSON.parse(jsonstr); //可以将json字符串转换成json对象 JSON.stringify(jsonobj); //可以将json ...

  4. 03.枚举和string以及int类型之间的转换

    练习1:   将枚举类型强转成int类型 namespace _04.枚举类型的练习01 { //声明一个QQState类型的枚举 public enum QQState { OnLine, OffL ...

  5. 关于FileFOutputStream应用中的FileNotFoundException问题

    在使用fileoutputstream时经常出现FileNotFoundException问题,即便是同一个程序(可行)改了一下包名再重新编译,就会无缘无故的抛出FileNotFoundExcepti ...

  6. XML再深入

    XML 命名空间 XML 命名空间提供避免元素命名冲突的方法. 使用前缀来避免命名冲突 在 XML 中的命名冲突可以通过使用名称前缀从而容易地避免. 该 XML 携带某个 HTML 表格和某件家具的信 ...

  7. struts2返回结果类型

    在action下还有result标签 1.result不只有name,其实还有type result返回类型在struts-default.xml默认的配置文件中有定义,可以看到有result-typ ...

  8. python 基础 知识

    Python Python 是一种强类型 的解释型 动态型语言Python 对象中的不可变 数字,字符串,元组 ,对于不能改变的会创建一个新的                可变  列表 , 字典   ...

  9. asp.net中<input type=button>无法调用后台函数

    例如:用<input id="bt1" type="button" runat="server" Onclick="btnL ...

  10. sketchup 与 ArcGIS 10 的交互(转)

    来自:http://blog.csdn.net/kikitamoon/article/details/9036347 许多用户在 ArcGIS 9.2 时代习惯于使用 Sketchup 插件,但是,9 ...