当前位置:网站首页>Uoj 553 [unr 4] caproic acid set [computational geometry (points in circle → points in half plane)]
Uoj 553 [unr 4] caproic acid set [computational geometry (points in circle → points in half plane)]
2022-06-11 07:30:00 【Master. Yi】
Title Description
Two dimensional plane n n n A little bit ( x i , y i ) (x_i,y_i) (xi,yi), Q Q Q Query distance ( 0 , z ) (0,z) (0,z) Less than or equal to R R R The number of points .
n ≤ 12000 , Q ≤ 1 0 6 , ∣ x i ∣ , ∣ y i ∣ , ∣ z i ∣ , R ≤ 1 0 9 n\le12000,Q\le10^6,|x_i|,|y_i|,|z_i|,R\le10^9 n≤12000,Q≤106,∣xi∣,∣yi∣,∣zi∣,R≤109
Topic analysis
x 2 + ( y − z ) 2 ≤ R 2 x^2+(y-z)^2\le R^2 x2+(y−z)2≤R2
x 2 + y 2 ≤ R 2 − z 2 + 2 y z x^2+y^2\le R^2-z^2+2yz x2+y2≤R2−z2+2yz
( x , y ) → ( y , x 2 + y 2 ) (x,y)\to(y,x^2+y^2) (x,y)→(y,x2+y2)
y ′ ≤ k x ′ + b , k = 2 z , b = R 2 − z 2 y'\le kx'+b,k=2z,b=R^2-z^2 y′≤kx′+b,k=2z,b=R2−z2
The problem is to find the number of points under a line in the plane . Maintain the partial order relationship of each element under the slope determination , Asking can be based on b b b Two points. .
y − x k ≤ b y-xk\le b y−xk≤b
If for a certain k k k, x 1 x_1 x1 be better than x 2 x_2 x2, x 1 < x 2 x_1<x_2 x1<x2
be y 1 − x 1 k ≤ y 2 − x 2 k y_1-x_1k\le y_2-x_2k y1−x1k≤y2−x2k
namely y 1 − y 2 ≤ k ( x 1 − x 2 ) * y 1 − y 2 x 1 − x 2 ≥ k y_1-y_2\le k(x_1-x_2) \Longleftrightarrow \frac {y_1-y_2}{x_1-x_2}\ge k y1−y2≤k(x1−x2)*x1−x2y1−y2≥k
Initially, it was assumed that k = − ∞ k=-\infty k=−∞, k k k Gradually increase .
if x 1 = x 2 x_1=x_2 x1=x2, be y y y Small henggengyou .
So the initial sorting is based on x x x For the first keyword , y y y For the second keyword .
Maintain such a partially ordered sequence , When k k k Reach a certain value ( ≤ n ( n − 1 ) / 2 \le n(n-1)/2 ≤n(n−1)/2 Secondary exchange ) when , Exchange the order of the elements .
If the swapped position is not adjacent , It means that they coincide with the exchange time of the intermediate elements , The operation of time coincidence can be switched arbitrarily . Cross out the preceding paragraph , fake .
This is equivalent to saying that if you change the exchange process of a selection sort in reverse order to n ( n − 1 ) / 2 n(n-1)/2 n(n−1)/2 The exchange of sub random order can still be arranged in reverse order ( Obviously false , such as 1 2 3 4 If you swap (1,2),(1,3),(3,4), that 1 It's impossible to get to the end ).
Therefore, when the exchange operation time is the same, it needs to ensure that it is a process similar to the selection sorting process , That is, operations with the same exchange time are sorted by the first dimension , And then sort by the second dimension .
Note that in this way, we still cannot guarantee that the adjacent two bits are exchanged each time , Because there may be multiple points distributed in two coordinates , But sorting is normal .
This section can be understood as a rotating scanning line , What needs to be considered is the case of multi-point collinearity and multi-point co coordinates .
The complexity of doing it directly is O ( n 2 log n + Q log n ) O(n^2\log n+Q\log n) O(n2logn+Qlogn)
If the point is divided into several blocks , The size of the score block is S S S, Then the complexity becomes O ( ( S 2 + Q ) log n ∗ n S ) O((S^2+Q)\log n*\frac nS) O((S2+Q)logn∗Sn)
S = Q S=\sqrt Q S=Q Best when , O ( n Q log n ) O(n\sqrt Q\log n) O(nQlogn)
PS: If the coordinates of the center of the circle can be taken arbitrarily , The problem becomes counting points in the three-dimensional half plane ( However, it seems that the author said that he would not ? Manual formation )
Code:
#include<bits/stdc++.h>
#define maxn 12005
#define maxq 1000005
#define LL long long
using namespace std;
char cb[1<<20],*cs,*ct;
#define getc() (cs==ct&&(ct=(cs=cb)+fread(cb,1,1<<20,stdin),cs==ct)?0:*cs++)
template<class T>void read(T &a){
char c;bool f=0;while(!isdigit(c=getc())) c=='-'&&(f=1);
for(a=c-'0';isdigit(c=getc());a=a*10+c-'0'); f&&(a=-a);
}
inline void write(int x){
if(x>=10) write(x/10);
putchar(x%10+48);
}
const int S = 1000;
int n,Q,ans[maxq];
struct node{
LL x,y; int id;
void init1(){
read(y),read(x),y=x*x+y*y;}// x<=1e9
void init2(int i){
read(x),read(y),y=y*y-x*x,x*=2,id=i;}// x<=2e9
bool operator < (const node &p)const{
return x^p.x?x<p.x:y<p.y;}
}a[maxn],q[maxq],b[maxn];
struct change{
double t;
int x,y;
bool operator < (const change &p)const{
return t==p.t?x^p.x?x<p.x:y<p.y:t<p.t;}
}C[S*S]; int Cn;
int pos[maxn];
void mdf(int i,int j){
if(pos[i]>pos[j]) return;
//assert(pos[j]-pos[i]==1); assert failed.
swap(b[pos[i]],b[pos[j]]);
swap(pos[i],pos[j]);
}
void solve(node *a,int n){
sort(a+1,a+1+n);
Cn=0;
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++) if(a[i].x!=a[j].x){
double t=1.0*(a[i].y-a[j].y)/(a[i].x-a[j].x); if(t>=q[Q].x) continue;
C[++Cn]=(change){
t,i,j};
}
sort(C+1,C+1+Cn);
for(int i=1;i<=n;i++) pos[i]=i;
for(int i=1,j=1;i<=Q;i++){
for(;j<=Cn&&C[j].t<q[i].x;j++) mdf(C[j].x,C[j].y);
int l=0,r=n,mid;
while(l<r) mid=(l+r+1)>>1,a[mid].y-a[mid].x*q[i].x<=q[i].y?l=mid:r=mid-1;
ans[q[i].id]+=l;
}
}
int main()
{
read(n),read(Q);
for(int i=1;i<=n;i++) a[i].init1();
for(int i=1;i<=Q;i++) q[i].init2(i);
sort(q+1,q+1+Q);
for(int i=1;i<=n;i+=S){
for(int j=1;j<=S&&i+j-1<=n;j++) b[j]=a[i+j-1];
solve(b,min(S,n-i+1));
}
for(int i=1;i<=Q;i++) write(ans[i]),putchar('\n');
}
边栏推荐
- 【AtCoder1981】Shorten Diameter(图论思维)
- 【AtCoder2000】Leftmost Ball (DP+组合数)
- Compound RateModel合约解析
- 2022 melting welding and thermal cutting exam exercises and answers
- Configuration software -- control import
- QObject usage skills -- control function class
- 2022 low voltage electrician test questions and online simulation test
- Interview question 02.06 Palindrome linked list
- [STL source code analysis] summary notes (12): functors and adapters
- 黑群晖DSM7.0.1物理机安装教程
猜你喜欢

QObject usage skills -- control function class

Summary of classic interview questions

Classification of MNIST datasets with keras

2022 melting welding and thermal cutting exam exercises and answers

QT table display data
![[STL source code analysis] summary note (2): overview of containers](/img/66/60fba564ae6020dfb503c7fdf78529.jpg)
[STL source code analysis] summary note (2): overview of containers

【Oracle 数据库】奶妈式教程day04 排序查询

Niuke wrong question 3.1

Software testing weekly (issue 75): only when you look down, can you see your true self.

If you want to save an IP address, what data type is better? 99% of people will answer wrong!
随机推荐
C memory alignment
MS office level II wrong question record [10]
【CF#262 (Div. 2)】 A. Vasya and Socks
Mobile console Gobang (first draft of detailed design)
Pointer to a two-dimensional array
Android和iOS逆向分析/安全检测/渗透测试框架
[STL source code analysis] summary notes (12): functors and adapters
JVM学习记录(七)——类加载过程与双亲委派模型
Sdl-4 PCM playback
Leetcode-9. Palindrome Numbber
Paper size and book size
Leetcode-141. Linked List Cycle
【CF#388 (Div. 2)】A. Bachgold Problem
CRMEB/V4.4标准版打通版商城源码小程序公众号H5+App商城源码
Cartland number application
JVM learning record (VII) -- class loading process and parental delegation model
C language judging big end and small end [consortium or pointer] big end and small end conversion
What is the lifecycle of automated testing?
Nosqlzoo question brushing-1
JVM tuning