Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4893
First paste a copy of the code that has not been passed, I do not know the error 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 + 10;
17 const ll INF = 1ll <62;
18 ll sum [max <2], Col [max <2], fig [max <2], FIB [Max];
19 int cur = 2;
20 void Init (){
21 fib [1] = fib [0] = 1;
22 For (INT I = 2; I <Max; I ++ ){
23 if (FIB [I-1] + fib [I-2]> inf) break;
24 fib [I] = fib [I-1] + fib [I-2];
25 cur ++;
26}
27 return;
28}
29 void push_up (int o ){
30 maid [O] = maid [O <1] + maid [O <1 | 1];
31 sum [O] = sum [O <1] + sum [O <1 | 1];
32}
33 void push_down (int o ){
34 if (COL [O]! =-1 ){
35 Col [O <1] = Col [O <1 | 1] = Col [O];
36 sum [O <1] = fig [O <1];
37 sum [O <1 | 1] = maid [O <1 | 1];
38 Col [O] =-1;
39}
40 return;
41}
42 void build (int l, int R, int o ){
43 If (L = r ){
44 sum [O] = 0;
45 fib_sum [O] = 1; Col [O] =-1;
46 return;
47}
48 int mid = (L + r)> 1;
49 build (L, mid, O <1 );
50 build (Mid + 1, R, O <1 | 1 );
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 = 0) maid [O] = fib [x];
61 else if (-fib [x] + sum [O])> = (-fib [x-1] + sum [O]) fiber _ sum [O] = fib [x-1];
62 else maid [O] = fib [x];
63 // printf ("% i64d \ n", fig [O]);
64 return;
65}
66 push_down (O );
67 int mid = (L + r)> 1;
68 if (k <= mid) add (L, mid, O <1, K, Val );
69 else add (Mid + 1, R, O <1 | 1, 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] = maid [O];
76 Col [O] = 1;
77 return;
78}
79 push_down (O );
80 int mid = (L + r)> 1;
81 If (LS <= mid) Update (L, mid, O <1, ls, RS );
82 If (RS> mid) Update (Mid + 1, R, O <1 | 1, 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)> 1;
91 ll res = 0;
92 If (LS <= mid) RES + = query (L, mid, O <1, ls, RS );
93 If (RS> mid) RES + = query (Mid + 1, R, O <1 | 1, ls, RS );
94 return res;
95
96}
97 int main (){
98 int n, m, OP, ls, RS;
99 Init ();
100 while (scanf ("% d", & N, & M) = 2 ){
101 build (1, n, 1 );
102 for (INT I = 0; I <m; I ++ ){
103 scanf ("% d", & OP, & LS, & RS );
104 If (OP = 1 ){
105 add (1, n, 1, ls, RS );
106}
107 else if (OP = 2 ){
108 printf ("% i64d \ n", query (1, n, 1, ls, RS ));
109}
110 else {
111 update (1, n, 1, ls, RS );
112}
113}
114}
115 return 0;
116}