题目链接:https://www.luogu.org/problemnew/show/P3368

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m;
int tree[],a[];
int lowbit(int x)
{
return x&-x;
}
void add(int k,int num)//给k位置的数值加num
{
while(k<=n)
{
tree[k]+=num;
k+=lowbit(k);
}
}
int query(int x)
{
int sum=;
for(int i=x;i>;i-=i&(-i)) sum+=tree[i];
return sum;
} int main()
{
cin>>n>>m;
for(int i=;i<=n;i++) cin>>a[i];
while(m--)
{
int k;
cin>>k;
if(k==)
{
int x,y,z;
cin>>x>>y>>z;
add(x,z); //维护查分数组
add(y+,-z);
}
else
{
int x;
cin>>x;
cout<<a[x]+query(x)<<endl; //query()求的是改变的值,再加上原来的值就可以了
}
}
return ;
}

最新文章

  1. 解决Can&#39;t connect to MySQL server on &#39;localhost&#39; (10048)
  2. JQ_浏览器窗口改变触发
  3. @property? @property?说说他身后的事情。
  4. 在filter中使用spring的service bean
  5. c# 垮线程调用控件
  6. MySQL配置
  7. C# 参考之方法参数关键字:params、ref及out
  8. 20145235李涛 《Java程序设计》第3周学习总结
  9. BZOJ 3199 escape
  10. 事件日志ID 2511:服务器服务无法重新创建 &lt;sharename&gt; 共享关系,因为 &lt;address&gt; 目录已不再存在
  11. Connection to https://dl-ssl.google.com refused 解决方案
  12. transfrom属性
  13. Qweb报表中的Reload from Attachment参数
  14. tinkphp5.0 traits 的引入
  15. ORACLE 本地数据库存储过程 调用远程数据库存储过程
  16. Sublime Text 3 快捷键总结(拿走)
  17. 不要在对抽象类接口abstract virtual什么的混淆不清了
  18. cookie、session、sessionid ,jsessionid 的区别
  19. JQ 使用模板
  20. BZOJ4010: [HNOI2015]菜肴制作(拓扑排序 贪心)

热门文章

  1. Coursera 机器学习 第6章(上) Advice for Applying Machine Learning 学习笔记
  2. js 标签属性与导航
  3. jqGrid随窗口大小变化自适应宽度
  4. Unity3D第二课之通过键盘、鼠标移动物体
  5. js之闭包
  6. vuex深入浅出
  7. 对象大小对比之Comparable与Comparator
  8. Vue中使用eslint
  9. jsonp跨域&amp;百度下拉
  10. 有关ie9 以下不支持placeholder属性以及获得焦点placeholder的移除