线段树结点上保存一个一般的sum值,再同一时候保存一个fbsum,表示这个结点表示的一段数字若为斐波那契数时的和

当进行3操作时,仅仅用将sum = fbsum就可以

其它操作照常进行,仅仅是单点更新的时候也要先向下更新

#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <fstream>
using namespace std;
//LOOP
#define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
//OTHER
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
#define all(x) (x).begin(),(x).end()
//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define RS(s) scanf("%s", s)
//OUTPUT
#define WI(n) printf("%d\n", n)
#define WS(n) printf("%s\n", n) #define sqr(x) (x) * (x)
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
const double eps = 1e-9;
const int MOD = 1000000007;
const double PI = acos(-1.0);
//const int INF = 0x3f3f3f3f;
const int maxn = 100010;
const LL INF = 0x3f3f3f3f3f3f3f3fLL; #define ll rt << 1
#define rr rt << 1 | 1 struct Node{
int l, r, m;
LL sum, fbsum;
bool f;
}t[maxn * 4];
LL fb[10000];
int fbcnt; void init()
{
fb[1] = 1, fb[0] = 1;
for (int i = 2; ; i++)
{
fb[i] = fb[i - 1] + fb[i - 2];
if (fb[i] > INF)
{
fbcnt = i - 1;
return;
}
}
return;
} void push_up(int rt)
{
t[rt].sum = t[ll].sum + t[rr].sum;
t[rt].fbsum = t[ll].fbsum + t[rr].fbsum;
t[rt].f = t[ll].f & t[rr].f;
} LL get(LL x)
{
int pos = lower_bound(fb, fb + fbcnt, x) - fb;
if (pos && abs(fb[pos - 1] - x) <= abs(fb[pos] - x))
return fb[pos - 1];
return fb[pos];
} void push_down(int rt)
{
if (t[rt].f)
{
t[ll].sum = t[ll].fbsum;
t[rr].sum = t[rr].fbsum;
t[rr].f = t[ll].f = 1;
t[rt].f = 0;
}
} void build(int l, int r, int rt)
{
t[rt].l = l, t[rt].r = r, t[rt].m = (l + r) >> 1;
if (l == r)
{
t[rt].sum = 0;
t[rt].fbsum = 1;
t[rt].f = 0;
return;
}
build(l, t[rt].m, ll);
build(t[rt].m + 1, r, rr);
push_up(rt);
} void update(int x, int add, int rt)
{
if (x == t[rt].l && t[rt].r == x)
{
t[rt].sum += add;
t[rt].fbsum = get(t[rt].sum);
t[rt].f = 0;
return;
}
push_down(rt);
if (x <= t[rt].m)
update(x, add, ll);
else
update(x, add, rr);
push_up(rt);
} void updatefb(int l, int r, int rt)
{
if (l <= t[rt].l && r >= t[rt].r)
{
t[rt].sum = t[rt].fbsum;
t[rt].f = 1;
return;
}
push_down(rt);
if (l <= t[rt].m)
updatefb(l, r, ll);
if (r > t[rt].m)
updatefb(l, r, rr);
push_up(rt);
} LL query(int l, int r, int rt)
{
if (l <= t[rt].l && r >= t[rt].r)
return t[rt].sum;
push_down(rt);
LL ans = 0;
if (l <= t[rt].m)
ans += query(l, r, ll);
if (r > t[rt].m)
ans += query(l, r, rr);
return ans;
} int main()
{
init();
int n, m;
while (~RII(n, m))
{
build(1, n, 1);
int x, y, op;
while (m--)
{
RIII(op, x, y);
if (op == 1)
update(x, y, 1);
else if (op == 2)
printf("%I64d\n", query(x, y, 1));
else
updatefb(x, y, 1);
}
}
return 0;
}
/*
5 4
3 1 3
2 1 3
1 3 3
2 1 3 5 2
3 1 3
2 1 2
*/

hdu4893 Wow! Such Sequence!的更多相关文章

  1. HDU4893:Wow! Such Sequence!(段树lazy)

    Problem Description Recently, Doge got a funny birthday present from his new friend, Protein Tiger f ...

  2. Wow! Such Sequence!(线段树4893)

    Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...

  3. HDU 4893 Wow! Such Sequence! (线段树)

    Wow! Such Sequence! 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4893 Description Recently, Doge ...

  4. 线段树 + 区间更新: HDU 4893 Wow! Such Sequence!

    Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  5. 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区间上的所以数变成 ...

  6. Wow! Such Sequence! (线段树) hdu4893

    http://acm.hdu.edu.cn/showproblem.php?pid=4893 先贴上一份还没过的代码,不知道拿出错了  1 // by caonima ; ; ],col[MAX< ...

  7. HDU 4893 Wow! Such Sequence!(2014 Multi-University Training Contest 3)

    题意: 有三种操作: 1 x y: 表示给x位置加上y 2 x y:查询[x,y]的区间和 3 x y:将 [x,y] 区间上的数变为最接近的 Fibonacci. 思路: 1 操作按正常单调更新,区 ...

  8. HDOJ 4893 Wow! Such Sequence!

    题意是这样的,给定一个n个元素的数组,初始值为0,3种操作: 1 k d将第k个数增加d: 2 l r 询问区间l...r范围内数之和: 3 l r 表示将区间l...r内的数变成离他最近的斐波那契数 ...

  9. 2014多校3 Wow! Such Sequence!段树

    主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4893 这个问题还真是纠结啊--好久不写线段树的题了.由于这几天学伸展树.然后认为线段树小case了. ...

随机推荐

  1. SQL表连接查询(inner join(join)、full join、left join、right join、cross join)

    下面列出了您可以使用的 JOIN 类型,以及它们之间的差异. JOIN: 如果表中有至少一个匹配,则返回行(join=inner join) LEFT JOIN: 即使右表中没有匹配,也从左表返回所有 ...

  2. display:none和visibility:hidden区别

    <!-- display:none和visible:hidden都能把网页上某个元素隐藏起来,但两者有区别: --> <!-- display:none 不为被隐藏的对象保留其物理空 ...

  3. webapp通用选择器:iosselect

    1,这个组件解决什么问题 在IOS系统中,safari浏览器的select标签默认展示样式和iOS-UIPickerView展示方式一致,形如下图: 这个选择器操作方便,样式优美.但是在安卓系统中展示 ...

  4. Postman参数化使用以及中文乱码问题解决

    1.参数化详解 准备工作,数据准备 2.使用csv文件时中文乱码可以通过使用txt文本,json文本改变调用json文件改变文件的编码格式解决 3:参数化数据调用的两种方式通过调用读取文件传入环境变量 ...

  5. WebService--axis

    axis WebService虽然现在已经很少使用,但是还是把它的配置过程写出来,开发环境jdk 1.6 服务端: 1,导入需要jar包,自行下载 2,创建WebService接口 public in ...

  6. Delphi工程版本号修改工具

    自动修改某目录下符合条件的Delphi工程(dproj)版本号, 支持命令行调用支持通配符忽略文件 -p [Path] 在[Path]路径下查询所有dproj文件(可以为空, 默认路径为程序当前路径) ...

  7. nginx-http-concat资源文件合并模块

    网页中引入多个CSS和JS的时候,浏览器会发出很多(css个数+js个数)次网络请求,甚至有的网页中有数十个以上的CSS或JS文件,用户体验特别不好,正好可以利用nginx-http-concat n ...

  8. jenkins~管道Pipeline的使用,再见jenkinsUI

    Pipeline在Jenkins里的作用 最近一直在使用jenkins进行自动化部署的工作,开始觉得很爽,省去了很多重复的工作,它帮助我自动拉服务器的代码,自动还原包包,自动编译项目,自动发布项目,自 ...

  9. sort学习 - LeetCode #406 Queue Reconstruction by Height

    用python实现多级排序,可以像C语言那样写个my_cmp,然后在sort的时候赋给参数cmp即可 但实际上,python处理cmp 是很慢的,因为每次比较都会调用my_cmp:而使用key和rev ...

  10. 泛型里的super和extend

    <? extends T>和<? super T>应该怎么用? 网上看到一些比较难懂的回答,但是在EffectiveJava(2th Edition)遇到简单明了的解释: If ...