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的更多相关文章

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

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

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

  3. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  4. 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 ...

  5. hdu4893Wow! Such Sequence! (线段树)

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

  6. HDU 6047 Maximum Sequence(线段树)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (J ...

  7. 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 ...

  8. hdu 5828 Rikka with Sequence 线段树

    Rikka with Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5828 Description As we know, Rik ...

  9. hdu-5805 NanoApe Loves Sequence(线段树+概率期望)

    题目链接: NanoApe Loves Sequence Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 262144/131072 ...

  10. Codeforces 486E LIS of Sequence(线段树+LIS)

    题目链接:Codeforces 486E LIS of Sequence 题目大意:给定一个数组.如今要确定每一个位置上的数属于哪一种类型. 解题思路:先求出每一个位置选的情况下的最长LIS,由于開始 ...

随机推荐

  1. bzoj 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富【记忆化搜索+剪枝】

    c[x][y]为从(x,y)到(n,m)的最大值,记忆化一下 有个剪枝是因为y只能+1所以当n-x>m-y时就算x也一直+1也是走不到(n,m)的,直接返回0即可 #include<ios ...

  2. bzoj 1629: [Usaco2007 Demo]Cow Acrobats【贪心+排序】

    仿佛学到了贪心的新姿势-- 考虑相邻两头牛,交换它们对其他牛不产生影响,所以如果交换这两头牛能使这两头牛之间的最大值变小,则交换 #include<iostream> #include&l ...

  3. Akka源码分析-Cluster-Metrics

    一个应用软件维护的后期一定是要做监控,akka也不例外,它提供了集群模式下的度量扩展插件. 其实如果读者读过前面的系列文章的话,应该是能够自己写一个这样的监控工具的.简单来说就是创建一个actor,它 ...

  4. 贪心 Codeforces Round #135 (Div. 2) C. Color Stripe

    题目传送门 /* 贪心:当m == 2时,结果肯定是ABABAB或BABABA,取最小改变量:当m > 2时,当与前一个相等时, 改变一个字母 同时不和下一个相等就是最优的解法 */ #incl ...

  5. ACM_Fibonacci数(同余)

    Fibonacci数 Time Limit: 2000/1000ms (Java/Others) Problem Description: 斐波那契数列定义如下:f(0)=0,f(1)=1,f(n+2 ...

  6. 转:python中使用txt文本保存和读取变量

    问题: 在python中需要经常有需要提前生成复杂的计算结果变量的需求减少程序计算运行时间的需求,因此这里把变量存在txt文本文件中. 解决方法: 使用两个函数解决问题,一个函数把变量保存到文本文件中 ...

  7. Xml学习笔记(2)

    不同的xml文档构可能要用到不同的方法进行解析这里用到的是例如<student name="张三" id="1" sex="男"/&g ...

  8. C# 访问mongodb数据库

    1.引用四个mongodb动态库MongoDB.Bson.dll,MongoDB.Driver.Core.dll,MongoDB.Driver.dll,MongoDB.Driver.Legacy.dl ...

  9. CSS动画持续汇总中

    一:向上的动态箭头------------------http://www.5599.com/88lz/up_direct.html

  10. 构建一个.net的干货类库,以便于快速的开发 - 工具类

    相信每一个开发的框架都会有一个工具类,工具类的作用有很多,通常我会将最常用的方法放在工具类里 取得用户IP 取得网站根目录的物理路径 枚举相关 非法关键字检查 绝对路径改为相对路径 获取小数位(四舍五 ...