The first line is an integer T, indicating that there are T groups of data. The first line of each group of data is a positive integer N (N <= 50000), indicating that the enemy has N barracks, followed by N positive integers, the I positive integer ai represents an ai individual (1 <= ai <= 50) at the beginning of the I barracks ). Next, each line has a command in four forms: (1) Add I j, I and j are positive integers, indicating that j individuals are added to camp I (j cannot exceed 30) (2) Sub I j, I and j are positive integers, indicating that j individuals are reduced in camp I (j cannot exceed 30); (3) Query I j, I and j are positive integers. I <= j indicates the total number of users from camp I to Camp j. (4) End indicates the End. This command appears at the End of each group of data; each group of data can have up to 40000 commands --> direct BIT, just like a template question. [Cpp] # include <iostream> # include <cstdio> # include <cstring> using namespace std; const int maxn = 50000 + 10; int a [maxn], lowerbit [maxn], C [maxn], N; int sum (int x) // The first x items of the BIT and {int ret = 0; while (x> 0) {ret + = C [x]; x-= lowerbit [x];} return ret;} void add (int x, int d) // BIT modification -- add {while (x <= N) {C [x] + = d; x + = lowerbit [x] ;}} void sub (int x, int d) // BIT modification -- minus {while (x <= N) {C [x]-= D; x + = lowerbit [x] ;}} int main () {int T, cnt = 1, I, j; for (I = 0; I <maxn; I ++) lowerbit [I] = I & (-I); scanf ("% d", & T); while (T --) {memset (C, 0, sizeof (C); scanf ("\ n % d \ n", & N); for (I = 1; I <= N; I ++) {scanf ("% d", & a [I]); add (I, a [I]);} char s [7]; printf ("Case % d: \ n ", cnt ++); while (~ Scanf ("% s", s) {if (strcmp (s, "End") = 0) break; scanf ("% d", & I, & j); if (strcmp (s, "Query") = 0) printf ("% d \ n", sum (j)-sum (I-1 )); else if (strcmp (s, "Add") = 0) add (I, j); else sub (I, j) ;}} return 0 ;}