2014多校3 Wow! Such Sequence!段树
主题链接:http://acm.hdu.edu.cn/showproblem.php?
pid=4893
这个问题还真是纠结啊……好久不写线段树的题了。由于这几天学伸展树。然后认为线段树小case了。没想到栽在这题上了。尼玛……
自己把自己给搞晕了……想复杂了。都不懂得预处理一下,唉……还得怒刷几十道啊!
!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <ctype.h>
#include <algorithm>
#include <string>
#include <set>
#define PI acos(-1.0)
#define MM 500015
#define INF 0x7fffffff
#define mem(a,b) memset(a,b,sizeof(a))
#define eps 1e-8
#define lson i<<1,l,mid
#define rson i<<1|1,mid+1,r
typedef long long ll;
typedef unsigned long long ULL;
using namespace std;
long long Fib[91],sum[MM],fib[MM];
int val[MM];
int n;
void init()
{
Fib[0]=1;
Fib[1]=1;
for(int i=2; i<92; i++)
Fib[i]=Fib[i-1]+Fib[i-2];
}
void pushUp(int i)
{
sum[i]=sum[i<<1]+sum[i<<1|1];
fib[i]=fib[i<<1]+fib[i<<1|1];
}
void pushDown(int i)
{
if(val[i])
{
val[i<<1]=1,val[i<<1|1]=1;
sum[i<<1]=fib[i<<1],sum[i<<1|1]=fib[i<<1|1];
val[i]=0;
}
}
void update(int i,int l,int r,int L,int v)
{
if(l==r&&l==L)
{
sum[i]+=v;
if(sum[i]<=1) {fib[i]=1;return;}
int ii=lower_bound(Fib,Fib+92,sum[i])-Fib;
if(Fib[ii]-sum[i]>=sum[i]-Fib[ii-1])
fib[i]=Fib[ii-1];
else fib[i]=Fib[ii];
return ;
}
int mid=(l+r)>>1;
pushDown(i);
if(L>mid) update(rson,L,v);
else update(lson,L,v);
pushUp(i);
}
void update1(int i,int l,int r,int L,int R)
{
if(L<=l&&r<=R)
{
sum[i]=fib[i];
val[i]=1;
return ;
}
int mid=(l+r)>>1;
pushDown(i);
if(R>mid) update1(rson,L,R);
if(L<=mid) update1(lson,L,R);
pushUp(i);
}
ll query(int i,int l,int r,int L,int R)
{
if(L<=l&&r<=R) return sum[i];
ll ans=0;
int mid=(l+r)>>1;
pushDown(i);
if(R>mid) ans+=query(rson,L,R);
if(L<=mid) ans+=query(lson,L,R);
return ans;
}
void build(int i,int l,int r)
{
if(l==r)
{
sum[i]=val[i]=0;
fib[i]=1;
return ;
}
int mid=(l+r)>>1;
build(lson);build(rson);
pushUp(i);
val[i]=0;
}
int main()
{
int m;
init();
while(~scanf("%d%d",&n,&m))
{
build(1,1,n);
while(m--)
{
int a,l,r;
scanf("%d%d%d",&a,&l,&r);
if(a==1) update(1,1,n,l,r);
else if(a==2) printf("%I64d\n",query(1,1,n,l,r));
else if(a==3) update1(1,1,n,l,r);
}
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
2014多校3 Wow! Such Sequence!段树的更多相关文章
- HDU4893:Wow! Such Sequence!(段树lazy)
Problem Description Recently, Doge got a funny birthday present from his new friend, Protein Tiger f ...
- 2016暑假多校联合---Rikka with Sequence (线段树)
2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...
- 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区间上的所以数变成 ...
- 线段树 + 区间更新: HDU 4893 Wow! Such Sequence!
Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- HDU 4893 Wow! Such Sequence! (线段树)
Wow! Such Sequence! 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4893 Description Recently, Doge ...
- 牛客多校第四场sequence C (线段树+单调栈)
牛客多校第四场sequence C (线段树+单调栈) 传送门:https://ac.nowcoder.com/acm/contest/884/C 题意: 求一个$\max {1 \leq l \le ...
- 计蒜客 28315.Excellent Engineers-线段树(单点更新、区间最值) (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 E)
先写这几道题,比赛的时候有事就只签了个到. 题目传送门 E. Excellent Engineers 传送门 这个题的意思就是如果一个人的r1,r2,r3中的某一个比已存在的人中的小,就把这个人添加到 ...
- HDU 1394 Minimum Inversion Number (数据结构-段树)
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
随机推荐
- BZOJ 1509: [NOI2003]逃学的小孩( 树形dp )
树形dp求出某个点的最长3条链a,b,c(a>=b>=c), 然后以这个点为交点的最优解一定是a+2b+c.好像还有一种做法是求出树的直径然后乱搞... ----------------- ...
- 一周学会Mootools 1.4中文教程:(5)Ajax
ajax在我们前台的开发中是非常重要的,所以我们单独拿出一节课来讲述,首先我们看一下mootools的ajax构成 语法: var myRequest=new Request([参数]); 参数: u ...
- 从零开始PHP学习 - 第五天
写这个系列文章主要是为了督促自己 每天定时 定量消化一些知识! 同时也为了让需要的人 学到点啥~! 本人技术实在不高!本文中可能会有错误!希望大家发现后能提醒一下我和大家! 偷偷说下 本教程最后的目 ...
- 树的判断(poj nyoj hduoj)
题目: http://ac.jobdu.com/problem.php?pid=1481 http://acm.nyist.net/JudgeOnline/problem.php?pid=129 ht ...
- Spring jdbctemplate学习笔记
/*List<?> config = getDB(" select t.datavalue from sys_config t where t.configid = '15' & ...
- mysql常见错误码
1062 - Duplicate entry '1' for key 1 唯一性错误
- cocos2dx CCControlSlider
有的同学建议先上图,好吧,先上效果图 再看代码,创建了两个CCControlSlider在主窗口中 // on "init" you need to initialize your ...
- 也许有用(也谈VC中ModifyStyle&ModifyStyleEx无法改变控件的Style)
一个View中用到了一个CListCtrl,在OnInitialUpdate函数里面他调用了m_listCtrl.ModifyStyleEx(0, LVS_EX_FULLROWSELECT);但是结 ...
- cluster maintain manager Software群集管理软件
1,ocfs2 2,crmsh(cluster management shell,)==crm shell [pacemaker OpenAIS,heartbeat,corosync,crmsh] 3 ...
- How can I get an object's absolute position on the page in Javascript?
How can I get an object's absolute position on the page in Javascript? How can I get an object's abs ...