1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
| type list=object a:array[0..1000000] of longint; n:longint; procedure init(); procedure add(x:longint); procedure sort(l,r:longint); procedure merge(); procedure sort(); function find(x:longint):longint; end; procedure list.init(); begin n:=0; end; procedure list.add(x:longint); begin inc(n); a[n]:=x; end; procedure list.sort(l,r:longint); var i,j,x,y:longint; begin i:=l; j:=r; x:=a[l+random(r-l+1)]; repeat while a[i]<x do inc(i); while x<a[j] do dec(j); if not(i>j) then begin y:=a[i]; a[i]:=a[j]; a[j]:=y; inc(i); j:=j-1; end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; procedure list.merge(); var i,cur:longint; begin cur:=1; for i:=2 to n do if a[i]<>a[cur] then begin inc(cur); a[cur]:=a[i]; end; n:=cur; end; procedure list.sort(); begin sort(1,n); merge(); end; function list.find(x:longint):longint; var left,right,mid:longint; begin left:=1; right:=n; while true do begin mid:=(left+right)>>1; if a[mid]=x then exit(mid); if x>a[mid] then left:=mid+1 else right:=mid-1; end; end; type atype=record x,y,tp,where:longint; end; var p,d:array[0..200010] of atype; procedure sort(l,r: longint); var i,j: longint; x,y:atype; begin i:=l; j:=r; x:=d[l+random(r-l+1)]; repeat while (d[i].x<x.x)or((d[i].x=x.x)and(d[i].tp=1)and(x.tp=0)) do inc(i); while (x.x<d[j].x)or((d[j].x=x.x)and(x.tp=1)and(d[j].tp=0)) do dec(j); if not(i>j) then begin y:=d[i]; d[i]:=d[j]; d[j]:=y; inc(i); j:=j-1; end; until i>j; if l<j then sort(l,j); if i<r then sort(i,r); end; function cmp(const a,b:atype):boolean; begin if a.x<>b.x then exit(a.x<b.x); if a.y<>b.y then exit(a.y<b.y); exit((a.tp=0)and(b.tp=1)); end; procedure sort2(l,r: longint); var i,j: longint; x,y:atype; begin i:=l; j:=r; x:=p[l+random(r-l+1)]; repeat while cmp(p[i],x) do inc(i); while cmp(x,p[j]) do dec(j); if not(i>j) then begin y:=p[i]; p[i]:=p[j]; p[j]:=y; inc(i); j:=j-1; end; until i>j; if l<j then sort2(l,j); if i<r then sort2(i,r); end; type pack=array[1..3] of extended; var ans:array[0..200000] of pack; a:array[0..524288] of record left,right,mid:longint; max:pack; end; ninit,Q,PW:longint; w:array[0..200000] of longint; function mg(const a,b:pack):pack; var i,i1,i2:longint; begin i1:=1; i2:=1; for i:=1 to 3 do if a[i1]>b[i2] then begin mg[i]:=a[i1]; inc(i1); end else begin mg[i]:=b[i2]; inc(i2); end; end; function mgs(const a,b:pack):pack; var i,i1,i2:longint; begin i1:=1; i2:=1; for i:=1 to 3 do if a[i1]<b[i2] then begin mgs[i]:=a[i1]; inc(i1); end else begin mgs[i]:=b[i2]; inc(i2); end; end; procedure build(i,bg,ed:longint); begin with a[i] do begin left:=bg; right:=ed; mid:=(bg+ed)>>1; max[1]:=-1e100; max[2]:=-1e100; max[3]:=-1e100; if bg=ed then exit; build(i<<1,bg,mid); build(i<<1 or 1,mid+1,ed); end; end; procedure serere(i,where,dt:longint); var temp:pack; begin with a[i] do begin if left=right then begin temp[1]:=dt; temp[2]:=-1e100; temp[3]:=-1e100; max:=mg(max,temp); exit; end; if where<=mid then serere(i<<1,where,dt) else serere(i<<1 or 1,where,dt); max:=mg(a[i<<1].max,a[i<<1 or 1].max); end; end; function query(i,bg,ed:longint):pack; var r1,r2:pack; begin with a[i] do begin if (bg<=left)and(right<=ed) then exit(max); if ed<=mid then exit(query(i<<1,bg,ed)); if mid<bg then exit(query(i<<1 or 1,bg,ed)); r1:=query(i<<1,bg,ed); r2:=query(i<<1 or 1,bg,ed); exit(mg(r1,r2)); end; end; var yl:list; procedure doit(all:longint); var i,j:longint; tmp:pack; begin sort(1,all); yl.init(); for i:=1 to all do yl.add(d[i].y); yl.sort(); build(1,1,yl.n); for i:=1 to all do if d[i].tp=0 then serere(1,yl.find(d[i].y),d[i].x+d[i].y) else begin tmp:=query(1,1,yl.find(d[i].y)); for j:=1 to 3 do tmp[j]:=d[i].x+d[i].y-tmp[j]; ans[d[i].where]:=mgs(ans[d[i].where],tmp); end; end; procedure solve(lt,rt:longint); var i,mid,all:longint; f:boolean; begin if rt<=ninit then exit; if lt=rt then exit; mid:=(lt+rt)>>1; solve(lt,mid); solve(mid+1,rt); all:=0; for i:=lt to mid do if p[i].tp=0 then begin inc(all); d[all]:=p[i]; end; if all=0 then exit; f:=false; for i:=mid+1 to rt do if p[i].tp=1 then begin inc(all); f:=true; d[all]:=p[i]; d[all].where:=i; end; if not f then exit; doit(all); end; procedure brute_force(); var min:pack; i,x,y,j:longint; ch:char; z:extended; begin for i:=1 to ninit do readln(p[i].x,p[i].y); for i:=1 to Q do begin repeat read(ch); until ch in ['A','Q']; readln(x,y); if ch='Q' then begin min[1]:=1e100; min[2]:=1e100; min[3]:=1e100; for j:=1 to ninit do begin z:=sqrt(int64(x-p[j].x)*(x-p[j].x)+int64(y-p[j].y)*(y-p[j].y)); if z<min[1] then begin min[3]:=min[2]; min[2]:=min[1]; min[1]:=z; end else if z<min[2] then begin min[3]:=min[2]; min[2]:=z; end else if z<min[3] then min[3]:=z; end; for j:=1 to PW-1 do write(min[j]:0:4,' '); writeln(min[PW]:0:4); end else begin inc(ninit); p[ninit].x:=x; p[ninit].y:=y; end; end; end; procedure lemon(); var MODE,i,j,x,y,cur,last:longint; ch:char; flag:boolean; begin readln(ninit,Q,MODE,PW); if MODE=2 then begin brute_force(); exit; end; for i:=1 to ninit do begin readln(p[i].x,p[i].y); p[i].tp:=0; end; for i:=ninit+1 to ninit+Q do begin repeat read(ch); until ch in ['A','Q']; readln(p[i].x,p[i].y); if ch='Q' then p[i].tp:=1 else p[i].tp:=0; end; for i:=1 to ninit+Q do ans[i,1]:=1e100; ans[i,2]:=1e100; ans[i,3]:=1e100; for j:=1 to 4 do begin solve(1,ninit+Q); for i:=1 to ninit+Q do begin x:=p[i].x; y:=p[i].y; p[i].x:=-y; p[i].y:=x; end; end; for i:=1 to ninit+Q do p[i].where:=i; sort2(1,ninit+Q); cur:=1; while cur<=ninit+Q do begin flag:=(p[cur].tp=0); last:=cur; inc(cur); while (cur<=ninit+Q)and(p[cur].x=p[last].x)and(p[cur].y=p[last].y) do begin if (flag)and(p[last].where<=p[cur].where) then begin ans[p[cur].where,3]:=ans[p[cur].where,2]; ans[p[cur].where,2]:=ans[p[cur].where,1]; ans[p[cur].where,1]:=0; end; inc(cur); end; end; for i:=1 to ninit+Q do if p[i].tp=1 then w[p[i].where]:=1; for cur:=1 to ninit+Q do begin i:=w[cur]; if i>0 then begin for j:=1 to PW-1 do write(ans[cur,j]:0:4,' '); writeln(ans[cur,PW]:0:4); end; end; end; begin lemon(); end.
|