当前位置:网站首页>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');
}
边栏推荐
- RTMP protocol
- 如果要存 IP 地址,用什么数据类型比较好?99%人都会答错!
- C language judging big end and small end [consortium or pointer] big end and small end conversion
- 【编译原理】05-语法制导的语义计算——基于翻译模式的语义计算
- 【CF#693 (Div. 3)】B. Fair Division
- Nim product
- 421. maximum XOR value of two numbers in the array
- I/o multiplexing - select/poll/epoll
- C memory alignment
- webserver
猜你喜欢

【Oracle 数据库】奶妈式教程day02 数据库管理工具SQLPLUS的使用

QT table display data

10 advanced concepts that must be understood in learning SQL
![[Oracle database] mammy tutorial day03 Sorting Query](/img/ea/24c9495a2ef4f1786f7b7852bde321.png)
[Oracle database] mammy tutorial day03 Sorting Query

1、 Sqlserver2008 installation (with password), database creation, C form project test

二、用户登录和注册

2、 User login and registration

The rotation of the earth and the moon (II)

Leetcode-141. Linked List Cycle

Create a form whose client area is 800 pixels by 600 pixels
随机推荐
MS office level II wrong question record [4]
20200730 T3 small B farm [maximum perimeter empty rectangle (monotone stack + line segment tree)] & "ROI 2017 day 2" learning track
QT table display data
Aiop introduction
Regular Expression Matching
【CodeForces1019E】Raining season(边分治+斜率优化)
QT 基于QScrollArea的界面嵌套移动
JVM学习记录(七)——类加载过程与双亲委派模型
[STL source code analysis] summary notes (9): set/multiset and map/multimap
[analysis of STL source code] summary note (4): behind the scenes hero allocator
@Jsonproperty annotation
2022 melting welding and thermal cutting exam exercises and answers
学 SQL 必须了解的10个高级概念
May 30-June 5, 2022 AI industry weekly (issue 100): three years
多线程复习总结之解析Volatile关键字
Tetris preliminary
JVM Learning record (7) - - class Loading Process and parent delegation Model
[STL source code analysis] summary notes (1): Opening
【CF#697 (Div. 3)】 A - Odd Divisor
What is the difference between gaussdb for redis and redis?