Wow! Such Sequence! (线段树) hdu4893
http://acm.hdu.edu.cn/showproblem.php?pid=4893
先贴上一份还没过的代码,不知道拿出错了 1 // by caonima
2 // hehe
3 #include <cstring>
4 #include <algorithm>
5 #include <cstdio>
6 #include <queue>
7 #include <stack>
8 #include <vector>
9 #include <map>
10 #include <cmath>
11 #include <set>
12 #include <iostream>
13 #include <string>
14 using namespace std;
15 #define LL __int64
16 const int MAX = 1e6+;
17 const LL inf = 1LL<<;
18 LL sum[MAX<<],col[MAX<<],fib_sum[MAX<<],fib[MAX];
19 int cur=;
20 void init() {
21 fib[]=fib[]=;
22 for(int i=;i<MAX;i++) {
23 if(fib[i-]+fib[i-]>inf) break;
24 fib[i]=fib[i-]+fib[i-];
25 cur++;
26 }
27 return ;
28 }
29 void push_up(int o) {
30 fib_sum[o]=fib_sum[o<<]+fib_sum[o<<|];
31 sum[o]=sum[o<<]+sum[o<<|];
32 }
33 void push_down(int o) {
34 if(col[o]!=-) {
35 col[o<<]=col[o<<|]=col[o];
36 sum[o<<]=fib_sum[o<<];
37 sum[o<<|]=fib_sum[o<<|];
38 col[o]=-;
39 }
40 return;
41 }
42 void build(int L,int R,int o) {
43 if(L==R) {
44 sum[o]=;
45 fib_sum[o]=; col[o]=-;
46 return ;
47 }
48 int mid=(L+R)>>;
49 build(L,mid,o<<);
50 build(mid+,R,o<<|);
51 push_up(o);
52 }
53 void add(int L,int R,int o,int k,int val) {
54 if(L==R) {
55 sum[o]+=(LL)val;
56 int x=(int)(lower_bound(fib,fib+cur,sum[o])-fib);
57 // printf("%I64d %I64d\n",fib[x],fib[x-1]);
58 // printf("%I64d\n",sum[o]);
59
60 if(x==) fib_sum[o]=fib[x];
61 else if((-fib[x]+sum[o])>=(-fib[x-]+sum[o])) fib_sum[o]=fib[x-];
62 else fib_sum[o]=fib[x];
63 // printf("%I64d\n",fib_sum[o]);
64 return ;
65 }
66 push_down(o);
67 int mid=(L+R)>>;
68 if(k<=mid) add(L,mid,o<<,k,val);
69 else add(mid+,R,o<<|,k,val);
70 push_up(o);
71 }
72
73 void Update(int L,int R,int o,int ls,int rs) {
74 if(ls<=L&&rs>=R) {
75 sum[o]=fib_sum[o];
76 col[o]=;
77 return ;
78 }
79 push_down(o);
80 int mid=(L+R)>>;
81 if(ls<=mid) Update(L,mid,o<<,ls,rs);
82 if(rs>mid) Update(mid+,R,o<<|,ls,rs);
83 push_up(o);
84 }
85 LL Query(int L,int R,int o,int ls,int rs) {
86 if(ls<=L&&rs>=R) {
87 return sum[o];
88 }
89 push_down(o);
90 int mid=(L+R)>>;
91 LL res=;
92 if(ls<=mid) res+=Query(L,mid,o<<,ls,rs);
93 if(rs>mid) res+=Query(mid+,R,o<<|,ls,rs);
94 return res;
95
96 }
97 int main() {
98 int n,m,op,ls,rs;
99 init();
while(scanf("%d %d",&n,&m)==) {
build(,n,);
for(int i=;i<m;i++) {
scanf("%d %d %d",&op,&ls,&rs);
if(op==) {
add(,n,,ls,rs);
}
else if(op==) {
printf("%I64d\n",Query(,n,,ls,rs));
}
else {
Update(,n,,ls,rs);
}
}
}
return ;
116 }
Wow! Such Sequence! (线段树) hdu4893的更多相关文章
- Wow! Such Sequence!(线段树4893)
Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- hdu 4893 Wow! Such Sequence!(线段树)
题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸
D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...
- hdu4893Wow! Such Sequence! (线段树)
Problem Description Recently, Doge got a funny birthday present from his new friend, Protein Tiger f ...
- HDU 6047 Maximum Sequence(线段树)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...
- Codeforces 438D The Child and Sequence - 线段树
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at ...
- hdu 5828 Rikka with Sequence 线段树
Rikka with Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5828 Description As we know, Rik ...
- hdu-5805 NanoApe Loves Sequence(线段树+概率期望)
题目链接: NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 ...
- Codeforces 486E LIS of Sequence(线段树+LIS)
题目链接:Codeforces 486E LIS of Sequence 题目大意:给定一个数组.如今要确定每一个位置上的数属于哪一种类型. 解题思路:先求出每一个位置选的情况下的最长LIS,由于開始 ...
随机推荐
- 在Chrome与火狐中,输入框input类型为number时,如何去除掉的自带的上下默认箭头
如何移除input='number'时浏览器自带的上下箭头: CSS样式: /* 去除input[type=number]浏览器默认的icon显示 */ input::-webkit-outer-sp ...
- mycat重启报错Failed to connect to the Wrapper at port解决方法
报错信息 ERROR | wrapper | 2018/05/11 14:01:55 | Startup failed: Timed out waiting for a signal from the ...
- 洛谷P3371 【模板】单源最短路径(弱化版)(SPFA解法)
题目背景 本题测试数据为随机数据,在考试中可能会出现构造数据让SPFA不通过,如有需要请移步 P4779. 题目描述 如题,给出一个有向图,请输出从某一点出发到所有点的最短路径长度. 输入输出格式 输 ...
- 题解报告:poj 3669 Meteor Shower(bfs)
Description Bessie hears that an extraordinary meteor shower is coming; reports say that these meteo ...
- 专题三:自定义Web服务器
前言: 经过前面的专题中对网络层协议和HTTP协议的简单介绍相信大家对网络中的协议有了大致的了解的, 本专题将针对HTTP协议定义一个Web服务器,我们平常浏览网页通过在浏览器中输入一个网址就可以看到 ...
- 使用Micrisoft.net设计方案 第三章Web表示模式 Web模式集群详细介绍 Observer(观察器)
在面向对象的编程中,对象同时包含数据和行为,这两者一起表示业务域的特定方面.使用对象生成应用程序的优点之一是可以将所有数据操作封装在对象内.这样, 就使对象成为独立的单位,并增加了在其他应用程序中重用 ...
- php angular/think angular/php模版引擎
在thinphp5中发现一个好用的模版引擎—think-angular, 此模板引擎主要特点是 不需要额外的标签定义, 全部使用属性定义, 写好的模板文件在IDE格式化代码的时候很整洁, 因为套完的模 ...
- PHP——基本使用(二)
PHP与Apache Apache服务器在接受到客户端请求的时候,根据客户端所请求的文件的类型,然后去问模块能否处理此文件,php作为模块之一有可能可以处理此文件,处理之后将数据再返回给apache, ...
- [Windows Server 2003] 手工创建安全网站
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:手工创建安全站 ...
- ERwin逻辑模型
1.自动排序 Format>>Preferences>>Layout Entire Diagram CA ERwin