Test instructions
Mars has $n$ a line of robots, the first $i$ robot position is $x_{i}$, the field of vision is $r_{i}$, IQ is $q_{i}$. We think that the position $i$ robot can see is $[x_{i}-r_{i},x_{i}+r_{i}]$. If a pair of robots can see each other, and their IQ $q_{i}$ is less than $k$, they will start chatting. To prevent them from arguing, please calculate how many pairs of bots may be chatting.
Exercises
First film, big Guy, here.
We first sort by the field of view in descending order, such a consideration, if the back can see the front, the front will certainly see the back
So, for each robot, in front of him there are several IQ in $[q-k,q+k]$, position in $[x-r,x+r]$
So take this thing as a rectangular overlay.
And then because the IQ of this dimension is very small, we can open a dynamic open point segment tree for each IQ, and then one by one sweep the past statistical answers can be
1 //Minamoto2#include <iostream>3#include <cstdio>4#include <algorithm>5#include <map>6 #definell Long Long7 using namespacestd;8 #defineGetc () (p1==p2&& (p2= (p1=buf) +fread (Buf,1,1<<21,stdin), P1==P2)? eof:*p1++)9 Charbuf[1<< +],*p1=buf,*p2=buf;TenInlineintRead () { One #defineNum ch-' 0 ' A CharChBOOLflag=0;intRes; - while(!isdigit (ch=getc ())) -(ch=='-') && (flag=true); the for(Res=num;isdigit (Ch=getc ()); res=res*Ten+num); -(flag) && (res=-res); - #undefNum - returnRes; + } - Const intn=1e5+5; + intn,k,m,b[n*3];ll Res; Amap<int,int> rt;intl[n<<5],r[n<<5],sum[n<<5],cnt=0; at voidUpdateintPintLintRintx) { -++SUM[P];if(L==R)return; - intMid= (l+r) >>1; - if(x<=mid) update (L[p]=l[p]? l[p]:++cnt,l,mid,x); - ElseUpdate (R[p]=r[p]? R[p]:++cnt,mid+1, r,x); - } in intQueryintPintLintRintQlintqr) { - if(ql<=l&&qr>=r| | p==0)returnSum[p]; to intMid= (l+r) >>1, res=0; + if(Ql<=mid) res+=query (L[P],L,MID,QL,QR); - if(Qr>mid) Res+=query (r[p],mid+1, R,QL,QR); the returnRes; * } $InlinevoidInsintQintx) {Panax Notoginseng if(Rt.count (q) = =0) rt[q]=++CNT; -Update (RT[Q],1, m,x); the } +Inlineint Get(intQintQlintqr) { A if(Rt.count (q) = =0)return 0; the returnQuery (Rt[q],1, M,QL,QR); + } - structnode{ $ intx,r,q; $ node () {} -NodeintXintRintq): X (x), R (R), q (q) {} -InlineBOOL operator< (ConstNode &b)Const the{returnR>B.R;} - }a[n];Wuyi intMain () { the //freopen ("testdata.in", "R", stdin); -N=read (), k=read (); Wu for(intI=1; i<=n;++i) { - intX=read (), R=read (), q=read (); Abouta[i]=node (x,r,q); $b[++m]=x,b[++m]=x-r,b[++m]=x+R; - } -Sort (b +1, B +1+M), M=unique (b +1, B +1+M)-b-1; -Sort (A +1, A +1+n); A for(intI=1; i<=n;++i) { + intL=lower_bound (b +1, B +1+M,A[I].X-A[I].R)-b; the intR=lower_bound (b +1, B +1+M,A[I].X+A[I].R)-b; - intX=lower_bound (b +1, B +1+m,a[i].x)-b; $ for(intj=a[i].q-k;j<=a[i].q+k;++j) theres+=Get(j,l,r); the ins (a[i].q,x); the } theprintf"%lld\n", res); - return 0; in}
cf1045g AI Robots (dynamic open point segment tree)