三维裸的做法是一维排序,剩下树套树,可我好像还没写过树套树
先说cdq分治吧,先对一维排序,相当于原来修改询问里的时间线
在这上面分治、划分,计算前半部分对后半部分的影响,显然可以按第二维的顺序维护树状数组

 type node=record
a,b,c,s,p:longint;
end; var a,b,q:array[..] of node;
ans,c:array[..] of longint;
n,m,i,t,j:longint; procedure swap(var a,b:node);
var c:node;
begin
c:=a;
a:=b;
b:=c;
end; function cmp(a,b:node):boolean;
begin
if a.a<b.a then exit(true);
if a.a>b.a then exit(false);
if (a.b<b.b) or (a.b=b.b) and (a.c<b.c) then exit(true);
exit(false);
end; procedure sorta(l,r:longint);
var i,j:longint;
x:node;
begin
i:=l;
j:=r;
x:=a[(l+r) shr ];
repeat
while cmp(a[i],x) do inc(i);
while cmp(x,a[j]) do dec(j);
if not(i>j) then
begin
swap(a[i],a[j]);
inc(i);
dec(j);
end;
until i>j;
if l<j then sorta(l,j);
if i<r then sorta(i,r);
end; function lowbit(x:longint):longint;
begin
exit(x and (-x));
end; procedure add(x,w:longint);
begin
while x<=m do
begin
inc(c[x],w);
x:=x+lowbit(x);
end;
end; function ask(x:longint):longint;
begin
ask:=;
while x> do
begin
ask:=ask+c[x];
x:=x-lowbit(x);
end;
end; procedure cdq(l,r:longint);
var m,i,j,l1,l2:longint;
begin
if l=r then exit;
m:=(l+r) shr ;
cdq(l,m);
cdq(m+,r);
j:=l;
for i:=m+ to r do
begin
while (j<=m) and (b[j].b<=b[i].b) do
begin
add(b[j].c,b[j].p);
inc(j);
end;
inc(b[i].s,ask(b[i].c));
end;
for i:=l to j- do
add(b[i].c,-b[i].p);
l1:=l; l2:=m+;
for i:=l to r do
if ((l1<=m) and (b[l1].b<b[l2].b)) or (l2>r) then
begin
q[i]:=b[l1];
inc(l1);
end
else begin
q[i]:=b[l2];
inc(l2);
end;
for i:=l to r do
b[i]:=q[i];
end; begin
readln(n,m);
for i:= to n do
readln(a[i].a,a[i].b,a[i].c);
sorta(,n);
i:=;
while i<n do
begin
inc(i);
j:=i+;
while (a[j].a=a[i].a) and (a[j].b=a[i].b) and (a[j].c=a[i].c) do inc(j); //这步不能少,因为要保证后半部分序列对前半部分没有影响
inc(t);
b[t]:=a[i];
b[t].p:=j-i;
i:=j-;
end;
cdq(,t);
for i:= to t do
inc(ans[b[i].s+b[i].p-],b[i].p);
for i:= to n- do
writeln(ans[i]);
end.
05-11 17:03