E-just a HookTime
limit:2000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64 U DescriptionIn the game of DotA, Pudge ' s meat hook is actually the most horrible thing for the very most of the heroes. The hook is made to several consecutive metallic sticks which is of the same length.
Now Pudge wants to do some operations on the hook.
Let us number the consecutive metallic sticks of the hooks from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver s Ticks or golden sticks.
The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows:
For each cupreous stick, the value is 1.
For each of the silver stick, the value is 2.
For each golden stick, the value is 3.
Pudge wants to know the total value of the hook after performing the operations.
Consider the original hook is a made up of cupreous sticks.
Input
The input consists of several test cases. The first line of the input is the number of the cases. There is no more than cases.
For each case, the first line contains a integer N, 1<=n<=100,000, which is the number of the sticks of Pudge ' s MEA T Hook and the second line contains a integer Q, 0<=q<=100,000, which is the number of the operations.
Next Q lines, each line contains three integers X, Y, 1<=x<=y<=n, Z, 1<=z<=3, which defines an operation:c Hange the sticks numbered from X to Y into the metal kind Z, where z=1 represents the Cupreous kind, z=2 represents the SI Lver Kind and z=3 represents the golden kind.
Output
For each case, print a number with a line representing the total value of the hook after the operations. Use the format in the example.
Sample Input
11021 5 25) 9 3
Sample Output
Case 1:the total value of the hook is 24.
1#include"iostream"2#include"algorithm"3#include"Cstdio"4#include"CString"5#include"Cmath"6 #defineMax (A, b) a>b?a:b7 #defineMin (A, b) a<b?a:b8 #defineMX 100000+100009 #defineINF 0x3f3f3f3fTen #defineLson l,m,rt<<1 One #defineRson m+1,r,rt<<1|1 A using namespacestd; - intsum[mx<<2],lazy[mx<<2]; - intLl,n,a,b,val; the voidPushup (intRT) { -sum[rt]=sum[rt<<1]+sum[rt<<1|1]; - } - + //The key to this problem lies in the sinking of the lazy array, and I read it several times before the report was written. - voidPushdown (intRtintm) { + if(lazy[rt]!=INF) { Alazy[rt<<1]=lazy[rt<<1|1]=LAZY[RT];//The lazy tag moves down atsum[rt<<1]= (M-(m>>1)) *lazy[rt];//half of the points -sum[rt<<1|1]= (m>>1)*Lazy[rt]; -Lazy[rt]=inf;//mark lazy as empty - } - } - in voidBuild (intLintRintRT) { -Lazy[rt]=inf;//Lazy Sign tosum[rt]=1;//each node is labeled 1; + if(r==l) { - return; the } * intM= (r+l) >>1; $ Build (Lson);Panax Notoginseng Build (Rson); - pushup (RT); the } + A voidUpdata (intLintRintValintLintRintRT) { the if(r<=r&&l<=l) { +Lazy[rt]=val;//Assigning a value to a lazy array -sum[rt]=val* (r-l+1);//because the value is directly overwritten, the value of the node is multiplied by the length of the lazy. $ return ; $ } -Pushdown (rt,r-l+1); - intM= (r+l) >>1; the if(l<=m) Updata (L,r,val,lson); - if(r>m) updata (L,r,val,rson);Wuyi pushup (RT); the } - Wu intMain () { - intT; About while(~SCANF ("%d",&T)) $ for(intqq=1; qq<=t; qq++) { -scanf"%d%d",&ll,&n); -Build (1, LL,1); - for(intI=1; i<=n; i++) { Ascanf"%d%d%d",&a,&b,&val); +Updata (A,b,val,1, LL,1); the } -printf"Case%d:the Total value of the hook is%d.\n", qq,sum[1]); $ } the return 0; the}
View Code
Acm:just A Hook Problem solving report-line tree