这道题真的是好题,让我对线段树有了全新的认识,至少让我真正感受到了线段树的神奇。

题意是就是线段树区间更新,单点询问的问题,不过这个题好就好在它的区间更新的点并不连续!

adding c to each of Ai which satisfies a <= i <= b and (i - a) % k == 0.

关键在于更新的点所满足的条件  1.在区间[a,b]中。 2.关于k的余数与(a%k)相等。

其中第二个条件保证了更新的点不连续(但如果传统的先判断再更新,则线段树失去了优势,因为始终会超时)。

本题突破口在于K的大小(1 <= k <= 10),结合第二个条件,我们可以想到在线段树的 Lazy标记上做文章。

当k==1 余数有 0

当k==2 余数有 0,1

当k==3 余数有 0,1,2

。。。。。

可以看到,只有55种情况,那么我们只需要将线段树的 Lazy标记 扩充为大小55的数组,

然后根据相应的余数情况进行更新与查询即可。

 #include<iostream>
#include<sstream>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cctype>
#include<queue>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r #define inf 0x3f3f3f3f
#define N 50010
#define maxn 10001000
#define mod 1000000007
using namespace std; int a[N];
int b[][]; //用于将55种余数情况一 一 对 应
struct NODE{
int l,r;
int v;
int b[];
int mid(){
return (l+r)>>;
}
}node[N<<]; void build(int root,int l,int r)
{
node[root].l=l;
node[root].r=r;
node[root].v=;
memset(node[root].b,,sizeof(node[root].b));
if(l==r) return;
int mid=node[root].mid();
build(lson);
build(rson);
} void pushdown(int root) //关于pushdown函数,个人觉得只需要询问时调用就行了,而且也过了,应该没问题,有的话请指出,谢谢
{
for(int i=; i<=; ++i)
{
for(int j=; j<i; ++j)
{
node[root<<].b[b[i][j]]+=node[root].b[b[i][j]];
node[root<<|].b[b[i][j]]+=node[root].b[b[i][j]];
}
}
memset(node[root].b,,sizeof(node[root].b));
} void update(int x,int y,int root,int v,int k,int rd)
{
if(node[root].l==x&&node[root].r==y)
{
node[root].b[b[k][rd]]+=v;
node[root].v+=v;
return;
}
int mid=node[root].mid();
if(y<=mid) update(x,y,root<<,v,k,rd);
else if(x>mid) update(x,y,root<<|,v,k,rd);
else
{
update(x,mid,root<<,v,k,rd);
update(mid+,y,root<<|,v,k,rd);
}
} int query(int root,int x)
{
if(node[root].l==x&&node[root].r==x)
{
int ans=;
for(int i=; i<=; ++i)
ans+=node[root].b[b[i][x%i]];
return ans;
}
pushdown(root);
int mid=node[root].mid();
if(x<=mid) return query(root<<,x);
else return query(root<<|,x);
} int main()
{
// freopen("lxx.txt","r",stdin);
int group,figure,i,j,x,y,k,v,num;
int cnt=;
for(i=; i<=; ++i)
for(j=; j<i; ++j)
b[i][j]=cnt++;
while(~scanf("%d",&group))
{
build(,,group);
memset(a,,sizeof(a));
for(i=; i<=group; ++i) scanf("%d",&a[i]);
scanf("%d",&group);
while(group--)
{
scanf("%d",&num);
if(num==)
{
scanf("%d%d%d%d",&x,&y,&k,&v);
update(x,y,,v,k,x%k);
}
else
{
scanf("%d",&figure);
printf("%d\n",query(,figure)+a[figure]);
}
}
}
return ;
}

不过感觉自己的代码风格还不够成熟,继续努力!

HDU4267(2012年长春站)的更多相关文章

  1. Windows server 2012 添加中文语言包(英文转为中文)(离线)

    Windows server 2012 添加中文语言包(英文转为中文)(离线) 相关资料: 公司环境:亚马孙aws虚拟机 英文版Windows2012 中文SQL Server2012安装包,需要安装 ...

  2. Windows Server 2012 NIC Teaming介绍及注意事项

    Windows Server 2012 NIC Teaming介绍及注意事项 转载自:http://www.it165.net/os/html/201303/4799.html Windows Ser ...

  3. 1.初始Windows Server 2012 R2 Hyper-V + 系统安装详细

    干啥的?现在企业服务器都是分开的,比如图片服务器,数据库服务器,redis服务器等等,或多或少一个网站都会用到多个服务器,而服务器的成本很高,要是动不动采购几十台,公司绝对吃不消的,于是虚拟化技术出来 ...

  4. 0.Win8.1,Win10,Windows Server 2012 安装 Net Framework 3.5

    后期会在博客首发更新:http://dnt.dkill.net 网站部署之~Windows Server | 本地部署:http://www.cnblogs.com/dunitian/p/482280 ...

  5. windows 2012 r2 can't find kb2919355

    问题   解决: 1.手动安装了 Windows8.1-KB2919442-x64 2.手动下载 KB2919355 更新成功     Turns out to have been a result ...

  6. Windows Server 2012 磁盘管理之 简单卷、跨区卷、带区卷、镜像卷和RAID-5卷

    今天给客户配置故障转移群集,在Windows Server 2012 R2的系统上,通过iSCSI连接上DELL的SAN存储后,在磁盘管理里面发现可以新建 简单卷.跨区卷.带区卷.镜像卷.RAID-5 ...

  7. VMware下Windows Server 2012添加新磁盘

    系统管理员在VM下新装了一台Windows Server 2012服务器,我在上面安装了SQL Server 2014 Standard版数据库,安装之初,只分配了一个C盘,我想在这台服务器上添加了三 ...

  8. 在Windows Server 2012中如何快速开关桌面上经典的“计算机、我的文档”等通用图标

    我们都知道,在Windows Server 2012系列的服务器版本中都已经引入了Modern的现代界面作为默认的用户交互界面,同时满足视觉一致化,新版的服务器管理程序也做成了扁平化.因此传统的计算机 ...

  9. VmWare平台Windows Server 2012 无响应宕机

    我们生产服务器都部署在VMware ESXi 5.5平台上,最近大半年的时间,偶尔就会出现操作系统为Windows Servre 2012的服务器出现没有任何响应(unresponsive)的情况,出 ...

随机推荐

  1. 学习-短信的上行(MO)和下行(MT)详解

    基础知识: SP服务提供商: 通常是指在移动网内运营增值业务的社会合作单位, 它们建立与移动网络建立相连的服务平台, 为手机用户提供一系列信息服务, 如:娱乐.游戏.短信.彩信.WAP.彩铃.铃声下载 ...

  2. 【前端】JavaScript

    一.JavaScript概述 1.JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名ScriptEa ...

  3. 《C++编程思想》(第二版)第3章 C++中的C(笔记、习题及答案)(二)

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...

  4. LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

    LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt 解决方法: 项目--> ...

  5. navigate是Router类的一个方法,主要用来跳转路由。

    navigate是Router类的一个方法,主要用来跳转路由. 1 2 3 4 5 6 7 8 9 interface NavigationExtras {  relativeTo : Activat ...

  6. Android4.4的zygote进程(上)

    1背景 前些天为了在科室做培训,我基于Android 4.4重新整理了一份关于zygote的文档.从技术的角度看,这几年zygote并没有出现什么大的变化,所以如果有人以前研究过zygote,应该不会 ...

  7. 设计模式_CallBack

    一.基本概念 if you call me, i will call back 什么是回调函数  回调函数(callback Function),顾名思义,用于回调的函数. 回调函数只是一个功能片段, ...

  8. 使用response.setHeader("Content-Disposition","attachment;filename="+fName)下载文件,中文文件名无法显示的问题

    今天遇到这么一个情况,在Action代码中进行文件下载: ActionForm得到file_id,通过file_id进行数据库查询得到file_name以及服务器硬盘上的file_uri,其中file ...

  9. JQuery EasyUI dialog弹出框的 close 和 destroy

    开发项目中(使用JQuery EasyUI),根据业务需要重叠弹出多个提示框的情况,会出现如下情况:页面出现两个div模块调用同一个弹出页面,页面的数据接受框元素不能实时存储数据解决方案: 使用$(t ...

  10. linux学习笔记22---命令diff和diff3

    diff 命令是 linux上非常重要的工具,用于比较文件的内容,特别是比较两个版本不同的文件以找到改动的地方.diff在命令行中打印每一个行的改动.最新版本的diff还支持二进制文件.diff程序的 ...