Green Lake War
The title describes 2814, the already calm salad Island of rebirth. Because the chief magician of the Republic of Cui found that the trees on the edge of the Green Lake were highly affinity with the emerald magic, the Folk magic Workshop began to use the wood from the lake to refine it. In the face of this phenomenon, the powerful ruler of the Republic of Cui,--xxx, has taken the attitude of not asking, tacitly allowing the people to continue to cut down the trees in the Green Lake Nature Reserve. The magician does not want to see this happen, and then alone to the top of the Cui waterfall altar, summoned out the ancient wizard managed, she heard the news, then summoned out of the lake area in the seclusion of the elves, the establishment of the Green Lakes Kingdom, and will be the Central Emerald Water Magic crystal out, The water in the Cui no longer has magical affinity. XXX Princess heard this news, furious, let Cui Republic's chief General battle organized the Human Coalition to drive the airship from the sky attack. Battle once in several salad Island war led Cui Army repeatedly surprisingly soldier, then some rely on to put out. So he sent the MN-frame airship from the sky to attack the Green Lake Kingdom. He ranked the airship in N columns (1<=n<=32767), each with an M-frame airship. (1<=m<=255). He's going to start a transfer order every time. 1 A B x, that is, from column A to transfer the X-airship to column B. But what he did not know was that the magician managed a crystal ball, and she made it possible for the crystal ball to intercept battle's transfer orders at any time. She wants to be an elf-allied officer. Chalaly to the crystal ball. 2 A B 0, that is, when asked about the number of airships between column A and column B (including A, A and two columns), the crystal Ball will respond immediately. At this time, managed found you, ask you to write a program for the crystal ball to do the above content. The survival of the Green Lake Kingdom is in your hands. Input
The first line inputs three number n,m,c, which represent the number of airship columns, the initial number of each airship and the total number of instructions issued by both parties.
Next line C, enter one instruction per line. Data assurance The first instruction is the transfer instruction of battle, and the last instruction is Chalaly's inquiry instruction.
Output
Output total S-line (S is the number of Chalaly issues). Each line gives an answer to an inquiry instruction from Chalaly.
Sample input
3 6 41 2 3 12 3 3 01 2 1 22 1 2 0
Sample output
711
Tips
For the total number of commands, there are:
For 30% of data,1<=c<=1023;
For 100% of data,1<=c<=32767;
Almost is a naked template problem, ship transfer is the previous column minus x after a column plus x, with a tree array maintenance can be Owo
Code:
#include <cstdio>#include<cstring>using namespacestd;Const intMAXV =33000; intSUM[MAXV], N;intlbintx) {returnX & (-x);}intGetsum (intx) {intAns =0; for(inti = x; i >0; I-=lb (i)) {ans+=Sum[i]; } returnans;}voidAddintXinty) { for(inti = x; I <= N; i + =lb (i)) {Sum[i]+=y; }}intMain () {intm, C; scanf ("%d%d%d", &n, &m, &c); for(inti =1; I <= N; i++) {Add (I, M); } while(c--) { intT, x, y, N; scanf ("%d%d%d%d", &t, &x, &y, &N); if(T = =1{Add (y, n); Add (x,-N); } Else{printf ("%d\n", Getsum (Y)-getsum (X-1)); } } return 0; }
[Tree array] Green Lake War