hdu4267A Simple Problem with Integers 线段树
来源:互联网 发布:pathfinder软件价格 编辑:程序博客网 时间:2024/04/26 01:56
// 1 a b k c 在区间[a,b]内满足条件 (i - a) % k == 0的位置加c//2 a 位置a的数//由于k<=10,所以可以开55棵线段树,存下相隔几个数取一个树,且这棵树的起点#include<cstdio>#include<cstring>#include<iostream>using namespace std ;const int maxn = 5e4+10 ;#define inf 0x7fffffff#define left v<<1#define right v<<1|1struct node{ int l ; int r ; int lazy ;}tree[12][12][maxn<<2] ;void build(int x , int y , int l , int r , int v){ tree[x][y][v].l = l; tree[x][y][v].r = r ; tree[x][y][v].lazy = 0 ; if(l == r)return ; int mid = (l + r) >> 1 ; build(x , y , l , mid , left) ; build(x , y , mid+1 , r , right) ;}void push_down(int x , int y , int v){ tree[x][y][left].lazy += tree[x][y][v].lazy ; tree[x][y][right].lazy += tree[x][y][v].lazy ; tree[x][y][v].lazy = 0 ;}void update(int x , int y , int l , int r , int c , int v){ if(l <= tree[x][y][v].l && tree[x][y][v].r <= r) { tree[x][y][v].lazy += c ; return ; } push_down(x , y , v) ; int mid = (tree[x][y][v].l + tree[x][y][v].r) >> 1 ; if(l <= mid)update(x , y , l , r , c , left) ; if(r > mid)update(x , y , l , r , c , right) ;}int query(int x , int y , int pos , int v){ if(tree[x][y][v].l == tree[x][y][v].r) return tree[x][y][v].lazy ; push_down(x , y , v) ; int mid = (tree[x][y][v].l + tree[x][y][v].r) >> 1 ; if(pos <= mid)return query(x , y , pos , left) ; else return query(x , y , pos , right) ;}int aa[maxn] ;int main(){ //freopen("in.txt" , "r" , stdin) ; int n ; while(~scanf("%d" , &n)) { for(int i = 1;i <= n;i++) scanf("%d" , &aa[i]) ; for(int i = 1;i <= 10;i++) for(int j = 1;j <= i;j++) build(i , j , 1 , (n+i-1)/i,1) ; int op , a , b , c , k,pos ; int q ; scanf("%d" , &q) ; while(q--) { scanf("%d" , &op) ; if(op == 1) { scanf("%d%d%d%d" , &a , &b , &k , &c) ; update(k , a%k+1, (a+k-1)/k, (b-a)/k+(a+k-1)/k, c , 1) ; } else { scanf("%d" , &pos) ; int ans = aa[pos] ; for(int i = 1;i <= 10;i++) ans += query(i , pos%i+1, (pos+i-1)/i , 1) ; printf("%d\n" , ans) ; } } } return 0 ;}
0 0
- hdu4267A Simple Problem with Integers 线段树
- A Simple Problem with Integers(线段树)
- poj3468A Simple Problem with Integers 线段树
- POJ3468A Simple Problem with Integers线段树
- A Simple Problem with Integers----线段树
- 线段树_poj_3468_A Simple Problem with Integers
- 线段树 A Simple Problem with Integers
- 线段树 A Simple Problem with Integers
- poj3468 Simple Problem with Integers (线段树)
- hdu4267A Simple Problem with Integers【树状数组区间更新/单点查询】
- POJ 3468 A Simple Problem with Integers(线段树)
- [PKU] 3468 A Simple Problem with Integers -- 线段树
- POJ 3468 A Simple Problem with Integers (线段树)
- pku -- 3468 A Simple Problem with Integers(线段树)
- POJ 3468 A SIMPLE PROBLEM WITH INTEGERS(线段树)
- poj 3468 A Simple Problem with Integers 基础线段树
- POJ 3468 A Simple Problem with Integers 线段树
- POJ 3468 A Simple Problem with Integers【线段树】
- Android内核sysfs中switch类使用实例
- 更换phpcms后台编辑器自动添加的<div>标签为<P>标签
- 第6周—项目4 数制转换
- 1.3.5 head.s开始执行(3)
- spring 使用spel
- hdu4267A Simple Problem with Integers 线段树
- Hibernate 不同数据库的连接及SQL方言
- 位,字节,字的区别
- LeetCode(79) Word Search
- ZOJ 1115
- hdu4293Groups dp
- C#实现的等额本息法、按月付息到期还本法、一次性还本付息法
- Longest Common Prefix
- 33、lamp安装