三维裸的做法是一维排序,剩下树套树,可我好像还没写过树套树
先说cdq分治吧,先对一维排序,相当于原来修改询问里的时间线在这上面分治、划分,计算前半部分对后半部分的影响,显然可以按第二维的顺序维护树状数组1 type node=record 2 a,b,c,s,p:longint; 3 end; 4 5 var a,b,q:array[0..100010] of node; 6 ans,c:array[0..200010] of longint; 7 n,m,i,t,j:longint; 8 9 procedure swap(var a,b:node); 10 var c:node; 11 begin 12 c:=a; 13 a:=b; 14 b:=c; 15 end; 16 17 function cmp(a,b:node):boolean; 18 begin 19 if a.ab.a then exit(false); 21 if (a.b j) then 36 begin 37 swap(a[i],a[j]); 38 inc(i); 39 dec(j); 40 end; 41 until i>j; 42 if l 0 do 64 begin 65 ask:=ask+c[x]; 66 x:=x-lowbit(x); 67 end; 68 end; 69 70 procedure cdq(l,r:longint); 71 var m,i,j,l1,l2:longint; 72 begin 73 if l=r then exit; 74 m:=(l+r) shr 1; 75 cdq(l,m); 76 cdq(m+1,r); 77 j:=l; 78 for i:=m+1 to r do 79 begin 80 while (j<=m) and (b[j].b<=b[i].b) do 81 begin 82 add(b[j].c,b[j].p); 83 inc(j); 84 end; 85 inc(b[i].s,ask(b[i].c)); 86 end; 87 for i:=l to j-1 do 88 add(b[i].c,-b[i].p); 89 l1:=l; l2:=m+1; 90 for i:=l to r do 91 if ((l1<=m) and (b[l1].b r) then 92 begin 93 q[i]:=b[l1]; 94 inc(l1); 95 end 96 else begin 97 q[i]:=b[l2]; 98 inc(l2); 99 end;100 for i:=l to r do101 b[i]:=q[i];102 end;103 104 begin105 readln(n,m);106 for i:=1 to n do107 readln(a[i].a,a[i].b,a[i].c);108 sorta(1,n);109 i:=0;110 while i