Title: Codeforces 444C dzy Loves Colors
The main topic: two operations, 1 is the change interval on the L to r above the German value of x,2 is to ask L to r interval Total change value.
Problem-Solving ideas: Line tree template problem.
#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>Using namespace Std;constintMAXN =5*1e5; typedef long Long Ll;lls[MAXN], DEL[MAXN], mark[maxn];void build (intUintLintR) {if(L < R) {intMid = (L + r)/2; Build (U * *, L, mid); Build (U * *+1, mid+1, R); }ElseMark[u] = l;} ll query (intUintLintRint x,int y) {if(y< L | |x> R)return 0;if(x<= L && R <=y)return s[u];intMid = (L + r)/2; ll L = query (u * *, L, Mid,x,y); ll R = query (u * *+1, mid+1Rx,y);returnL + R + max (0, Min (R,y)-Max (L,x) +1) * Del[u];} void Clear (intUintLintRintZ) {if(Mark[u]) {Del[u] + =ABS(mark[u]-z);s[u] + =1LL * (r-l+1) *ABS(mark[u]-z); Mark[u] =0; }Else{if(L = = r)return;intMid = (L + r)/2,LC= u * *, rc = u * *+1; ClearLC, L, Mid, z); Clear (RC, mid+1, R, Z);s[U] =s[LC] +s[RC] +1LL * (r-l+1) * Del[u]; }}void Modify (intUintLintRint x,int y,intZ) {// printf("%d %d%d%d%d%d \ n", U, l, R,x,y, z);if(y< L | |x> R)return;if(x<= L && R <=y) {Clear (U, l, R, Z); Mark[u] = Z;return; }intMid = (L + r)/2,LC= u * *, rc = u * *+1;if(Mark[u]) {mark[LC] = MARK[RC] = Mark[u]; Mark[u] =0; } Modify (LC, L, Mid,x,y, z); Modify (RC, mid+1Rx,y, z);s[U] =s[LC] +s[RC] +1LL * (r-l+1) * Del[u];}intMain () {intNm; scanf"%d%d", &n, &m);/* memset (sum, 0, sizeof (sum)); memset (del, 0, sizeof (DEL)); memset (mark, 0, sizeof (Mark)); */Build1,1, n);intTypex,y, z;; for(inti =0; I <m; i++) {scanf (" %d%d%d", &type, &x, &y);if(Type = =1) {scanf ("%d", &z); Modify1,1Nx,y, z); }Else printf("%lld\ n", Query (1,1Nx,y)); }return 0;}
Codeforces 444C dzy Loves Colors (segment tree)