Just a Hook
Time limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 23137 Accepted Submission (s): 11600
Problem DescriptionIn The game of DotA, Pudge's Meat hook is actually the most horrible thing for 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.
Inputthe 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.
Outputfor, print a number in a line representing the total value of the hook after the operations. Use the format in the example.
Sample Input11021 5 25 9 3
Sample outputcase 1:the Total value of the hook is 24. test instructions: the input t represents a T set of test data, then a number n represents n heroes, then the number Q represents the next Q line, three integers per line a,b,c, Represents the value of the interval A through B all to C, the final total number of points, note Initial score of 1
#include <stdio.h> #include <string.h> #include <queue> #include <algorithm> #define MAX 100100# Define INF 0x3f3f3fusing namespace Std;int sum[max<<2];int change[max<<2];void pushup (int o) {sum[o]=sum[o <<1]+SUM[O<<1|1];} void pushdown (int o,int m) {if (Change[o]) {Change[o<<1]=change[o<<1|1]=change[o];sum[o<<1]=change [O]* (M-(m>>1)); sum[o<<1|1]=change[o]* (m>>1); change[o]=0;}} void Gettree (int o,int l,int r) {sum[o]=1;change[o]=0;if (l==r) return; int mid= (L+R) >>1;gettree (o<<1,l,mid ); Gettree (o<<1|1,mid+1,r);p ushup (o);} void update (int o,int l,int r,int l,int R,int v) {if (l<=l&&r>=r) {change[o]=v;sum[o]=v* (r-l+1); return;} Pushdown (o,r-l+1), int mid= (r+l) >>1;if (l<=mid) Update (O<<1,L,MID,L,R,V), if (r>mid) update (o< <1|1,MID+1,R,L,R,V); Pushup (o);} int find (int o,int l,int r,int l,int R) {if (l<=l&&r>=r) {return sum[o];} Pushdown (o,r-l+1); int ans=0;int miD= (r+l) >>1;if (l<=mid) ans+=find (o<<1,l,mid,l,r), if (R>mid) ans+=find (o<<1|1,mid+1,r,l,r); return ans;} int main () {int t,k,i,j;int n,m;k=1;scanf ("%d", &t), while (t--) {scanf ("%d%d", &n,&m); int A,b,c;gettree (All , N), while (m--) {scanf ("%d%d%d", &a,&b,&c); update (1,1,N,A,B,C);} printf ("Case%d:the total value of the hook is", k++);p rintf ("%d.\n", Find (1,1,n,1,n));} return 0;}
Hdoj 1689 Just a Hook "segment Tree interval modification"