多校第三场 7题。。线段树A的

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define Lson l,m,rt<<1
#define Rson m+1,r,rt<<1|1
typedef __int64 ll;
int const MAXN = 100010;
ll f[110];
struct Tree{
int l,r;
ll v,s;
int flag;
int add;
}tree[MAXN*6];
ll abss(ll a){
return a<0? -a:a;
}
inline void PushUp(int rt){
tree[rt].v = tree[rt<<1].v + tree[rt<<1|1].v;
tree[rt].s = tree[rt<<1].s + tree[rt<<1|1].s;
}
inline void PushDown(int rt,int m){
if(tree[rt].add){
tree[rt<<1].add = tree[rt].add;
tree[rt<<1|1].add = tree[rt].add;
tree[rt<<1].flag = tree[rt].add * (m - (m>>1));
tree[rt<<1|1].flag = tree[rt].add * (m>>1);
tree[rt<<1].v = tree[rt<<1].s;
tree[rt<<1|1].v = tree[rt<<1|1].s;
tree[rt].add = 0;
}
}
void Build(int l,int r,int rt){
tree[rt].add = 0;
tree[rt].v = 0;
tree[rt].flag = 0;
if(l == r){
tree[rt].s = 1;
return ;
}
int m = (l + r)>>1;
Build(Lson);
Build(Rson);
PushUp(rt);
}
void Update(int k,int d,int l,int r,int rt){
if(k < l || k > r || rt > (MAXN<<2)) return ;
if(l == r){
if(tree[rt].flag){
tree[rt].v = d + tree[rt].s;
tree[rt].flag = 0;
tree[rt].add = 0;
}
else tree[rt].v += d;
int pos = lower_bound(f,f+90,tree[rt].v) - f;
if(pos == 0)tree[rt].s = 1;
else if(abss(f[pos] - tree[rt].v) < abss(f[pos - 1] - tree[rt].v)){
tree[rt].s = f[pos];
}
else tree[rt].s = f[pos-1];
return ;
}
PushDown(rt,r - l + 1);
int m = (l + r)>>1;
if(k <= m) Update(k,d,Lson);
else Update(k,d,Rson);
PushUp(rt);
}
void Change(int L,int R,int l,int r,int rt){
if(R < l || L > r) return ;
if(L <= l && r <= R){
tree[rt].v=tree[rt].s;
tree[rt].add = 1;
tree[rt].flag = r - l + 1;
return ;
}
PushDown(rt,r - l + 1);
int m = (l + r)>>1;
if(L <= m) Change(L,R,Lson);
if(R > m) Change(L,R,Rson);
PushUp(rt);
}
ll Query(int L,int R,int l,int r,int rt){
if(R < l || L > r) return 0;
if(L <= l && r <= R) return tree[rt].v;
PushDown(rt,r - l + 1);
int m =(l + r)>>1;
ll ret = 0;
if(L <= m) ret += Query(L,R,Lson);
if(R > m) ret += Query(L,R,Rson);
return ret;
}
void Init(){
f[0] = 1;
f[1] = 1;
for(int i = 2;i <= 90;i++){
f[i] = f[i - 1] + f[i - 2];
}
}
int main(){
Init();
int n,m;
while(~scanf("%d%d",&n,&m)){
Build(1,n,1);
for(int i = 1;i <= m;i++){
int x;
scanf("%d",&x);
if(x == 1){
int k,d;
scanf("%d%d",&k,&d);
Update(k,d,1,n,1);
}
else if(x == 2){
int x,y;
scanf("%d%d",&x,&y);
printf("%I64d\n",Query(x,y,1,n,1));
}
else if(x == 3){
int x,y;
scanf("%d%d",&x,&y);
Change(x,y,1,n,1);
}
}
}
return 0;
}
/*
1 1
2 1 1
5 4
1 1 7
1 3 17
3 2 4
2 1 5
*/

hdu 4893Wow! Such Sequence!的更多相关文章

  1. HDU 5860 Death Sequence(死亡序列)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 1711 Number Sequence(数列)

    HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

  3. HDU 1005 Number Sequence(数列)

    HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...

  4. HDU 5860 Death Sequence(递推)

    HDU 5860 Death Sequence(递推) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 Description You ...

  5. HDU 1560 DNA sequence(DNA序列)

    HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K  ...

  6. HDU 1005 Number Sequence(数论)

    HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...

  7. HDU 1711 Number Sequence (字符串匹配,KMP算法)

    HDU 1711 Number Sequence (字符串匹配,KMP算法) Description Given two sequences of numbers : a1, a2, ...... , ...

  8. HDU 6078 - Wavel Sequence | 2017 Multi-University Training Contest 4

    /* HDU 6078 - Wavel Sequence [ DP ] | 2017 Multi-University Training Contest 4 题意: 给定 a[N], b[M] 要求满 ...

  9. HDU 6047 - Maximum Sequence | 2017 Multi-University Training Contest 2

    /* HDU 6047 - Maximum Sequence [ 单调队列 ] 题意: 起初给出n个元素的数列 A[N], B[N] 对于 A[]的第N+K个元素,从B[N]中找出一个元素B[i],在 ...

随机推荐

  1. Merge Intervals——STL的应用

    Given a collection of intervals, merge all overlapping intervals. For example, Given [1,3],[2,6],[8, ...

  2. 【转载】Python: Enum枚举的实现

    转自:http://www.cnblogs.com/codingmylife/archive/2013/05/31/3110656.html   从C系语言过来用Python,好不容易适应了写代码不打 ...

  3. 原生DOM选择器querySelector和querySelectorAll

    在传统的 JavaScript 开发中,查找 DOM 往往是开发人员遇到的第一个头疼的问题,原生的 JavaScript 所提供的 DOM 选择方法并不多,仅仅局限于通过 tag, name, id ...

  4. Java学习笔记(十三)——通过Netbeans开发环境生成oracle数据库中表的对应hibernate映射文件

    [前面的话] 身体慢慢已经快好了,感觉真好,哈哈. 这篇文章要通过Hibernate对数据库进行操作,而Netbeans可以直接通过数据库逆向生成对应的映射文件.基础文章,选择性阅读. [步骤] 1. ...

  5. AC日记——[POI2008]BLO-Blockade 洛谷 [POI2008]BLO-Blockade

    [POI2008]BLO-Blockade 思路: tarjan: 代码: #include <bits/stdc++.h> using namespace std; #define ma ...

  6. Genymotion的2个问题及解决方法

    问题一:Unable to connect to your virtual device 解决方法:基本都是内存不够导致的,在virtualbox中调整对应虚拟机的内存,确保任务管理器中的性能一项中剩 ...

  7. HRBUST 1200 装修

    $dp$. $dp[i]$记录铺满$3*i$的方案数.最后两列铺了$1$个$2*2$的和两个$1*1$的,或者是最后$1$列铺了$3$个$1*1$的. 因此$dp[i]=dp[i-1]+dp[i-2] ...

  8. CodeForces 740A Alyona and copybooks

    完全背包. 直接做个背包容量为$100000$的完全背包,这样就可以避免繁琐的分类讨论了. #pragma comment(linker, "/STACK:1024000000,102400 ...

  9. go chapter 7 - 类型

    任意类型 interface{} 遍历并判断类型 func MyPrintf(args ...interface{}) { for _, arg := range args { switch arg. ...

  10. C++中的error C2662,const的this指针问题

    今天在写C++代码的时候遇到一个错误,涉及到了常量的this指针的问题. 简化后的代码如下: #include <iostream> #include <string> usi ...