【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 缩完点之后加边注意别写错. 也可以不用建两个图,可以在一张图上判断是否 ...
随机推荐
- springMVC静态资源访问
springMVC默认是访问不到静态资源的,如css,js等,需要在xml里进行配置 保证已经配置好了 web.xml, <!-- Spring MVC servlet --> <s ...
- BNU4299——God Save the i-th Queen——————【皇后攻击,找到对应关系压缩空间】
God Save the i-th Queen Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO format: %lld ...
- POST 还是 GET?
POST 还是 GET? 浏览器使用 method 属性设置的方法将表单中的数据传送给服务器进行处理.共有两种方法:POST 方法和 GET 方法. 如果采用 POST 方法,浏览器将会按照下面两步来 ...
- git每次提交都输入密码
打开gitbash执行即可 git config --global credential.helper store 长期储存密码,因为git默认是不储存密码的,不执行这条命令的话每次更新代码,或者提交 ...
- Razor语句(VIew)小知识
1.可以写后台语句 例如:
- FileUpload一键自动上传
背景 源程序二次修改 传统的Asp.net WebForm开发 上传控件样式可自定义 分析 不能用第三方插件,因为源程序开发模式对异步的支持不友好而第三方插件大都是针对异步编程的 兼容IE8及以上和其 ...
- 调试.NET程序OutOfMemoryException (转载)
原文地址:http://blog.csdn.net/directionofear/article/details/8009427 应用程序调试,需要有个常规的调试思路,应对各类问题最基本的调试手段是什 ...
- Spring-boot2.0.1.BUILD-SNAPSHOT整合Elasticsearch报failed to load elasticsearch nodes错误解决办法
spring-boot整合es的application.properties的默认配置为: spring.data.elasticsearch.cluster-nodes=localhost:9200 ...
- Nginx管理(一)
一.Nginx介绍 Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务. 1.Nginx历史和特性 Nginx是由伊戈尔·赛索耶夫为俄罗斯 ...
- 汽车后市场SWOT分析
客户接待系统SWOT分析 版本 V0.1 所有人: 王超 S 客户接待系统符合市场的目前阶段需求.填补了市场的空白部分. W 市场推广的力度差异,市场由蓝海编成红海,多种厂商参与,创业团队不断进入 ...