【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 缩完点之后加边注意别写错. 也可以不用建两个图,可以在一张图上判断是否 ...
随机推荐
- opensuse13.1 安装 SqliteMan
Sqliteman是一个图形界面的sqliteman客户端 官网 http://www.sqliteman.com/ 1 添加源 http://download.opensuse.org/repos ...
- Android RelativeLayout 属性 转自互联网
// 相对于给定ID控件 android:layout_above 将该控件的底部置于给定ID的控件之上; android:layout_below 将该控件的底部置于给定ID的控件之下; andro ...
- Linux查找命令与find命令详解
一.文件查找之locate命令 locate :非实时的,查找时根据全系统文件数据库进行的,模糊查找,update 手动生成文件数据库速度快 依赖于updatedb数据库 1 2 3 4 5 6 7 ...
- 新建maven工程index.jsp页面报错
引入servlet依赖jar <dependency><groupId>javax.servlet</groupId><artifactId>servl ...
- 【卷土重来之C#学习笔记】(二)c#编程概述
(1)开始C#,一个简单的程序Hello Word 开始 using System; //使用了System的命名空间 using System.Collections.Generic; us ...
- nyoj 1197——你会加吗?——————【快速幂、分治】
你会加吗? 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 给出两个整数A和N,计算(A + A^2 + A^3 + …… + A^(N - 1) + A^N)% 6 ...
- [转]<加密算法c#>——— 3DES加密之ECB模式 和 CBC模式
本文转自:http://www.cnblogs.com/qq278360339/archive/2013/06/05/3119222.html 最近 一个项目.net 要调用JAVA的WEB SERV ...
- [SQL SERVER系列]工作经常使用的SQL整理,实战篇(三)[原创]
工作经常使用的SQL整理,实战篇,地址一览: 工作经常使用的SQL整理,实战篇(一) 工作经常使用的SQL整理,实战篇(二) 工作经常使用的SQL整理,实战篇(三) 接着本系列前面两篇继续讨论. 有时 ...
- java常用API之Calendar类
Calendar是日历类,该类将所有可能用到的时间信息封装为静态成员变量,方便获取. Calendar为抽象类,由于语言敏感性,Calendar类在创建对象时并非直接创建,而是通过静态方法创建,将语言 ...
- 小米3 无法显示日志 Logcat
需要ROOT权限 1. 使用文件浏览器进入 /system/etc/init.d/ 目录 2.使用文本编辑器打开里面的 01Supertweak 这个文件 在最下面找到 rm /dev/lo ...