【luogu T34117 打油门】 题解
王强怎么这么强啊
王强太强了
二维树状数组
#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 打油门】 题解的更多相关文章
- 【luogu P5022 旅行】 题解
题目连接:https://www.luogu.org/problemnew/show/P5022 \(NOIP2018 DAY2T1\) 考场上只写了60分,很容易想到当 m = n - 1 时的树的 ...
- 【luogu P2831 愤怒的小鸟】 题解
题目链接:https://www.luogu.org/problemnew/show/P2831 写点做题总结:dp,搜索,重在设计状态,状态设的好,转移起来也方便. 对于一条抛物线,三点确定.(0, ...
- 【luogu P2827 蚯蚓】 题解
题目链接:https://www.luogu.org/problemnew/show/P2827 35分:暴力sortO(mnlogn). 80分:考虑到每次不好维护不被切的点+q,正难则反.改成维护 ...
- 【luogu P3959 宝藏】 题解
题目链接:https://www.luogu.org/problemnew/show/P3959 我只是心血来潮想学SA(考场上骗分总行吧). 这个题可以状压DP.爆搜+剪枝.有意思的还是随机化搜索( ...
- 【luogu P3410 拍照】 题解
题目链接:https://www.luogu.org/problemnew/show/P3410 这个题就是求一个最大权闭合图 在一个图中,一些点构成一个集合,且集合中的出边指向的终点也在这个集合中, ...
- 【luogu P1113 杂务】 题解
题目链接:https://www.luogu.org/problemnew/show/P1113 菜 #include <queue> #include <cstdio> #i ...
- 【luogu P4114 Qtree1】 题解
题目链接:https://www.luogu.org/problemnew/show/P4114 1.把边权转化到点权:选取连接这条边的两个点中较深的一个. 2.查询点到点之间的边权时,要从seg[x ...
- 【luogu P3979 遥远的国度】 题解
题目链接:https://www.luogu.org/problemnew/show/P3979 除了换根操作都是裸的树剖 所以换根时考虑: 1.我查询的根等于换的根:无影响 2.我查询的根是换的根的 ...
- 【luogu P2169 正则表达式】 题解
题目链接:https://www.luogu.org/problemnew/show/P2169 tarjan缩点 + SPFA 缩完点之后加边注意别写错. 也可以不用建两个图,可以在一张图上判断是否 ...
随机推荐
- 015-GenericEncodingFilter模板【解决全局乱码】
package ${enclosing_package}; import java.io.IOException; import java.io.UnsupportedEncodingExceptio ...
- 【算法】K-Means聚类算法(k-平均或k-均值)
1.聚类算法和分类算法的区别 a)分类 分类(Categorization or Classification)就是按照某种标准给对象贴标签(label),再根据标签来区分归类. 举例: 假如你有一堆 ...
- Java简单验证码原理(源代码+步骤操作)
本文章一共分为五个步骤,具体操作流程如下: 一.新建名为:CheckCodeServlet的servlet类; 二.复制以下代码到新建的CheckCodeServlet类中,修改自己的包名: pack ...
- 《C#高效编程》读书笔记02-用运行时常量(readonly)而不是编译期常量(const)
C#有两种类型的常量:编译期常量和运行时常量.两者有截然不同的行为,使用不当的话,会造成性能问题,如果没法确定,则使用慢点,但能保证正确的运行时常量. 运行时常量使用readonly关键字声明,编译期 ...
- mysql多表条件更新
有两张表bas_student.bas_householder, 去除学生表中与家长表重复的手机号 UPDATE bas_student a,bas_householder b SET a.mobil ...
- reload()与reload(true)
如果该方法没有规定参数,或者参数是 false,它就会用 HTTP 头 If-Modified-Since 来检测服务器上的文档是否已 改变.如果文档已改变,reload() 会再次下载该文档.如果文 ...
- [LeetCode]22. Generate Parentheses括号生成
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- 多线程篇四:ThreadLocal实现线程范围内变量共享
1.static实现线程范围内变量共享 package com.test.shareData; import java.util.Random; /** * 多线程范围内的数据共享 * @author ...
- Vue表格中,对数据进行转换、处理
众所周知,后端从Mysql取出的数据,一般是很难单独处理某一个Key的数据的(需要处理的话,可能会浪费大量的性能.而且对页面加载时间有很大的影响),所以,从数据库取出的数据.只能由前端进行处理.但是在 ...
- javascript统计一个字符在一段字符串出现次数
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" ...