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

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

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. 7.12归来赛_B

    Prime Judge 时间限制 1000 ms 内存限制 65536 KB 题目描写叙述 众所周知.假设一个正整数仅仅能被1和自身整除,那么该数被称为素数.题目的任务非常easy.就是判定一个数是否 ...

  2. python导入模块的两种方式

    第一种 from support import * 这种方式导入后可以直接调用(有命名冲突问题)命名冲突后定义的覆盖前定义的 如果在函数导入前定义 则导入函数覆盖 否则相反 if __name__ = ...

  3. java之TCP(Socket,serverSocket)实例

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import ...

  4. leetcode——Lowest Common Ancestor of a Binary Tree

    题目 Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. 思路 这一次 ...

  5. OPC UA的监控项、订阅、和通知

    MonitoredItem 每个监控项均指明了要监控的项目(item)和用来发送通知的订阅. item可以是一个节点的属性(node attribute). MonitorItem可以监控一个属性,一 ...

  6. js 获取距离顶部的相对高度

    getTop (e) { var offset=e.offsetTop; if(e.offsetParent!=null) offset+=this.getTop(e.offsetParent); r ...

  7. Python 实现字符串转换成列表 实现str转换list

    其中Python strip() 方法用于移除字符串头尾指定的字符 split()就是将一个字符串分裂成多个字符串组成的列表 >>> image ='1.jsp,2.jsp,3.js ...

  8. ubuntu命令改变文档权限和所有者

    chgrp :改变档案所属群组 chown :改变档案拥有者 chmod :改变档案的权限, SUID, SGID, SBIT等等的特性,可读.可写.可执行 1 chgrp 例子 chgrp [-R] ...

  9. 图片onerror事件,为图片加载指定默认图片

    为图片指定加载失败时显示默认图片,js输出的img对象,onerror是事件,不是属性,所以这样写是不起作用的: var img = $(document.createElement("IM ...

  10. 关于Animator获取当前剪辑长度

    通常下意识的肯定用这个接口 GetCurrentAnimatorStateInfo().length 但是存在一个过渡动画的问题,具体看这篇:过渡动画的测试 所以当播新的状态时直接取动画时间,取到的就 ...