http://acm.hdu.edu.cn/showproblem.php?pid=4893
At the beginning, I pressed the double mark, WA had an afternoon, and I was using the two Mark add--to indicate that there is a value change in the current node, flag, Fibonacci's lazy tag, but I guess I handled the problem, has been wrong
Reference to other people's code, writing is still very good, add variable maintenance is, completely into the Fibonacci and,---back I write again
#include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <
iostream> #include <cmath> #include <map> #include <queue> using namespace std; #define LS (RT) rt*2 #define RS (RT) rt*2+1 #define LL Long Long #define REP (i,s,e) for (int i=s;i<e;i++) #define REPE (i,s , e) for (int i=s;i<=e;i++) #define CL (A, B) memset (A,b,sizeof (a)) #define in (s) freopen (S, "R", stdin) #define OUT (s) Freo
Pen (S, "w", stdin) const int MAXN =100000+100;
ll ff[105];
ll NUM[MAXN];
void Init () {ff[0]=ff[1]=1;
for (int i=2;i<105;i++) ff[i]=ff[i-1]+ff[i-2];
} ll Cal (ll x) {if (x = = 0) return 1;
int Idx=lower_bound (ff,ff+105,x)-ff;
if (ff[idx] = = x | | idx==0) return ff[idx];//if (x-ff[idx-1]<=ff[idx]-x) return ff[idx-1];
else return FF[IDX];
} struct node{int l,r;
ll sum; ll add;//interval A value has been changed, if the FF operation, need to be the current node Dfs int FLAG;//1, the interval has the value over/initial, if there is a fi interval update need to re-update 0--has updated Cheng, do not need to update}NODES[MAXN *];
void build (int rt, int l, int r) {nodes[rt].l=l;
Nodes[rt].r=r;
nodes[rt].sum=0;
nodes[rt].add=1;//has not done fi modification nodes[rt].flag=0;
if (l==r) {num[l]=0;
Return
} int mid= (L+R)/2;
Build (LS (RT), L,mid);
Build (RS (RT), Mid+1,r);
if (NODES[RT].L==NODES[RT].R) return;
Nodes[rt].sum=nodes[ls (RT)].sum+nodes[rs (RT)].sum;
Nodes[rt].add=nodes[ls (RT)].add+nodes[rs (RT)].add; }/*void DFS (int rt) {if (0 = = Nodes[rt].flag) return;//has modified Fibonacci if (0 = = nodes[rt].add) return;//interval value has not been modified no
des[rt].flag=0;//changed nodes[rt].add=0;
if (nodes[rt].l = = NODES[RT].R) {nodes[rt].sum=num[nodes[rt].l]=cal (NUM[NODES[RT].L]);
Return
} DFS (LS (RT));
DFS (RS (RT));
Nodes[rt].sum=nodes[ls (RT)].sum+nodes[rs (RT)].sum; }*/void pushdown (int rt) {if (Nodes[rt].flag && nodes[rt].l==nodes[rt].r) {nodes[rt].sum=nodes[r
T].add;
nodes[rt].flag=0;
Return } if (nodes[Rt].flag) {nodes[ls (RT)].flag=nodes[rs (RT)].flag=1;
Nodes[ls (RT)].sum=nodes[ls (RT)].add;
Nodes[rs (RT)].sum=nodes[rs (RT)].add;
nodes[rt].flag=0;
}} void modify (int rt, int p, ll v) {if (NODES[RT].L==NODES[RT].R) {nodes[rt].sum+=v;
Nodes[rt].add=cal (nodes[rt].sum);
Num[nodes[rt].l]+=v;
nodes[rt].flag=0;
Return
} pushdown (RT);
nodes[rt].add=1;//the interval of the node has been modified, if FF, Dfs int mid= (NODES[RT].L+NODES[RT].R)/2 is required;
if (p<=mid) modify (LS (RT), p,v);
else Modify (RS (RT), p,v);
if (NODES[RT].L==NODES[RT].R) return;
Nodes[rt].sum=nodes[ls (RT)].sum+nodes[rs (RT)].sum; Nodes[rt].add=nodes[ls (RT)].add+nodes[rs (RT)].add;/////////} void update (int rt, int l, int r) {if (Nodes[rt].l==l &
amp;& nodes[rt].r==r) {nodes[rt].flag=1;
Need to modify nodes[rt].sum=nodes[rt].add;
Return
} pushdown (RT);
int mid= (NODES[RT].L+NODES[RT].R)/2; if (r<=mid) update (LS (RT), L,r);
else {if (l>mid) update (RS (RT), L,r);
else {update (LS (RT), L,mid);
Update (RS (RT), Mid+1,r);
}} if (NODES[RT].L==NODES[RT].R) return;
Nodes[rt].sum=nodes[ls (RT)].sum+nodes[rs (RT)].sum;
Nodes[rt].add=nodes[ls (RT)].add+nodes[rs (RT)].add;
} ll query (int rt, int l, int r) {//if (nodes[rt].flag && nodes[rt].add) DFS (RT);
if (NODES[RT].L = = L && nodes[rt].r==r) {return nodes[rt].sum;
} pushdown (RT);
int mid= (NODES[RT].L+NODES[RT].R)/2;
ll ret=0;
if (r<=mid) ret= query (LS (RT), L,r);
else {if (l>mid) ret= query (RS (RT), L,r);
else {ret= query (LS (RT), L,mid) +query (RS (RT), Mid+1,r);
}} if (NODES[RT].L!=NODES[RT].R) {nodes[rt].sum=nodes[ls (RT)].sum+nodes[rs (RT)].sum;
Nodes[rt].add=nodes[ls (RT)].add+nodes[rs (RT)].add;
} return ret; } int MaIn () {//in ("hdu4893.txt");
int n,m,op,l,r;
Init ();
while (~SCANF ("%d%d", &n,&m)) {build (1,1,n);
while (m--) {scanf ("%d", &op);
scanf ("%d%d", &l,&r);
if (op = = 1) {modify (1,L,R);
} if (op = = 3) {update (1,L,R);
} if (op = = 2) {printf ("%i64d\n", Query (1,l,r));
}}} return 0;
}