hdu4267 A Simple Problem with Integers
A Simple Problem with Integers
Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2571 Accepted Submission(s): 837
The first line contains an integer N. (1 <= N <= 50000)
The second line contains N numbers which are the initial values of A1, A2, ... , AN. (-10,000,000 <= the initial value of Ai <= 10,000,000)
The third line contains an integer Q. (1 <= Q <= 50000)
Each of the following Q lines represents an operation.
"1 a b k c" means adding c to each of Ai which satisfies a <= i <= b and (i - a) % k == 0. (1 <= a <= b <= N, 1 <= k <= 10, -1,000 <= c <= 1,000)
"2 a" means querying the value of Aa. (1 <= a <= N)
1 1 1 1
14
2 1
2 2
2 3
2 4
1 2 3 1 2
2 1
2 2
2 3
2 4
1 1 4 2 1
2 1
2 2
2 3
2 4
1
1
1
1
3
3
1
2
3
4
1
#include <string.h>
#include <iostream>
#include <stdio.h>
using namespace std;
#define MAXN 50005
#define lnum num<<1
#define rnum num<<1|1 struct node
{
int color,prime,listadd[55];
}tree[4*MAXN];
#define inf 0
int modleft[11][11];
void build(int num ,int l,int r)
{
memset(tree[num].listadd,0,sizeof(tree[num].listadd));
tree[num].color=0;
int mid=(l+r)>>1;
if(l>=r)
{
scanf("%d",&tree[num].prime);
return ;
}
build(lnum,l,mid);
build(rnum,mid+1,r);
}
void pushdown(int num)
{
int i;
if(tree[num].color!=inf)
{ tree[lnum].color=tree[num].color;
tree[rnum].color=tree[num].color;
tree[num].color=inf;//还原标记 for(i=0;i<55;i++)
{ tree[lnum].listadd[i]+=tree[num].listadd[i];
tree[rnum].listadd[i]+=tree[num].listadd[i];
tree[num].listadd[i]=0; }
}
}
void update(int s,int e,int a,int b,int num,int amk,int k,int c )
{
int i; if(a<=s&&b>=e)
{
tree[num].color=k;//需要更新
tree[num].listadd[modleft[k][amk]]+=c;
return ;
}
pushdown(num);
int mid=(s+e)>>1;
if(mid>=a)
update(s,mid,a,b,lnum,amk,k,c);
if(mid<b)
update(mid+1,e,a,b,rnum,amk,k,c);
}
int query(int s,int e,int num,int x)//充分利用这个延时标记
{
int i; if(s>=e)
{
int temp=tree[num].prime;
for(i=1;i<=10;i++)
{
temp+=tree[num].listadd[modleft[i][x%i]];
tree[num].listadd[modleft[i][x%i]]=0;
}
tree[num].prime=temp;//更新为新的值
return temp;
}
pushdown(num);
int mid=(s+e)>>1;
if(x>mid)
return query(mid+1,e,rnum,x);
else
{
return query(s,mid,lnum,x);
}
}
int main()
{
int asknum,num12,x,a,b,n,k,c;
int i,j,cnt=0;
for(i=1;i<=10;i++)
for(j=0;j<i;j++)
{
modleft[i][j]=cnt++;//省了一半的空间
}
while(scanf("%d",&n)!=EOF)
{
build(1,1,n); scanf("%d",&asknum);
while(asknum--)
{ scanf("%d",&num12);
if(num12==1)
{
scanf("%d%d%d%d",&a,&b,&k,&c); update(1,n,a,b,1,a%k,k,c);
}
else{
scanf("%d",&x);
printf("%d\n",query(1,n,1,x));
} }
}
return 0;
}
hdu4267 A Simple Problem with Integers的更多相关文章
- A Simple Problem with Integers(树状数组HDU4267)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...
- POJ 3468 A Simple Problem with Integers(线段树/区间更新)
题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Description Yo ...
- poj 3468:A Simple Problem with Integers(线段树,区间修改求和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 58269 ...
- ACM: A Simple Problem with Integers 解题报告-线段树
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
- poj3468 A Simple Problem with Integers (线段树区间最大值)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92127 ...
- POJ3648 A Simple Problem with Integers(线段树之成段更新。入门题)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 53169 Acc ...
- BZOJ-3212 Pku3468 A Simple Problem with Integers 裸线段树区间维护查询
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1278 Sol ...
- POJ 3468 A Simple Problem with Integers(线段树区间更新区间查询)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92632 ...
随机推荐
- C++ Primer 学习笔记_77_模板与泛型编程 --实例化
模板与泛型编程 --实例化 引言: 模板是一个蓝图,它本身不是类或函数.编译器使用模板产生指定的类或函数的特定版本号.产生模板的特定类型实例的过程称为实例化. 模板在使用时将进行实例化,类模板在引用实 ...
- ViewPager顶部标题控件PagerSlidingTabStrip
最近搞一个项目,要求做一个和网易新闻顶部菜单的滑动效果,如图: 顶部标题中下面有个红色的矩形小条,左右滑动时会跟随手势动态滑动,效果很绚丽,唉,特效啊! 自己搞了一上午无果,还是是github上找大神 ...
- const与define的异同
1. DEFINE是预处理指令,是简单的文字替换:而const是关键字,用于变量声明的修饰. 2. DEFINE替换的结果可以是数值.表达式.字符串.甚至是一个程序:而const只能限定变量为不可修改 ...
- 多路复用I/O select()
select(),poll(),epoll()的总结:http://www.cnblogs.com/Anker/p/3265058.html 在socket编程中,仅仅使用connect,accept ...
- C#基础:C#4.0权威指南 杂笔一
1.c#中数组初始化的几种不同用法 int[] name = new int[NUM]; int[] name = {1, 2, 3, 4, 5, 6}; int[] ...
- [jQuery] 使用jQuery printPage plugin打印其他頁面內容
目標: 點選按鈕後可以打印其他頁面的內容,可用於套版.內部表單套印...等等. 程式碼: 1.View(HTML布局) <h2>維修申請單</h2> <form id=& ...
- 后台js
Response.Write("<script>alert('该用户名不存在或密码错误或未参加教学活动,请重新输入!');history.back()</script> ...
- 华为oj - 统计大写字母个数
练手而已. 给初学者参考 #include <stdio.h> #include <string.h> int main(void) { char string[200]={' ...
- PHP上传文件DEMO
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"> <html> <head> ...
- python之6-4装饰器.md
装饰器看的说实话真心郁闷,群里一伙计说了好一会,听得一愣一愣的,查了点资料,又自己试了下,算是明白了一些,记录记录=.=更郁闷的是,博客园的markdown标记支持怎么和为知的不匹配,这转过来的文章很 ...