#include "nice_lines.h"
#include <bits/stdc++.h>
using namespace std;
template<class T>
struct Point{
T x, y;
Point (T _x=0, T _y=0){
x=_x; y=_y;
}
bool operator<(Point a){ return tie(x, y)<tie(a.x, a.y); }
bool operator==(Point a){ return tie(x, y)==tie(a.x, a.y); }
Point operator+(Point a){ return Point(x+a.x, y+a.y); }
Point operator-(Point a){ return Point(x-a.x, y-a.y); }
Point operator*(T a){ return Point(x*a, y*a); }
Point operator/(T a){ return Point(x/a, y/a); }
T dot(Point a){ return x*a.x+y*a.y; }
T dot(Point a, Point b){ return (a-*this).dot(b-*this); }
T cross(Point a){ return x*a.y-y*a.x; }
T cross(Point a, Point b){ return (a-*this).cross(b-*this); }
T dist2(){ return x*x+y*y; }
long double dist(){ return sqrt(dist2()); }
};
const long double eps=1e-7;
using pt=Point<long double>;
long double line_point_dist(pt a, pt b, pt c){
return abs(a.cross(b, c))/(a-b).dist();
}
mt19937 rng(69420);
long double rand(long double l, long double r){
return uniform_real_distribution<long double>(l, r)(rng);
}
pair<int, int> line_from_points(pt a, pt b){
long double slope=round((b.y-a.y)/(b.x-a.x));
return {(int)(round(slope)), (int)(round(a.y-a.x*slope))};
}
const int X=3e4;
void solve(int subtask_id, int N) {
vector<int> va, vb;
vector<long double> diff;
for (int i=0; i<=(int)X; ++i) diff.push_back((long double)2/sqrtl(i*i+1));
auto insert_line=[&](int x){
int b=x%X;
if (b<0) b+=X;
if (b>1e4) b-=X;
int a=(x-b)/X;
va.push_back(a);
vb.push_back(b);
};
map<int, long double> memo;
auto fake_query=[&](int x) -> long double {
if (memo.count(x)) return memo[x];
return memo[x]=query(X, x);
};
auto get_slope=[&](int x) -> long double {
return fake_query(x+1)-fake_query(x);
};
auto dnc=[&](auto self, int l, int r, long double sl, long double sr){
if (l==r || abs(sr-sl)<eps) return;
for (auto &x:diff){
if (abs(sr-sl-x)<eps){
long double t1=fake_query(l), t2=fake_query(r);
insert_line(round((t2-t1+l*sl-r*sr)/(sl-sr)));
return;
}
}
int mid=(l+r)>>1;
long double smid=get_slope(mid);
self(self, l, mid, sl, smid);
self(self, mid, r, smid, sr);
};
int l=-3.3e8, r=3.3e8;
dnc(dnc, l, r, get_slope(l), get_slope(r));
the_lines_are(va, vb);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1044 KB |
Output is correct |
2 |
Correct |
1 ms |
1232 KB |
Output is correct |
3 |
Correct |
1 ms |
1044 KB |
Output is correct |
4 |
Correct |
1 ms |
1052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1048 KB |
Output is correct |
2 |
Correct |
1 ms |
1044 KB |
Output is correct |
3 |
Correct |
2 ms |
1052 KB |
Output is correct |
4 |
Correct |
1 ms |
1048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1048 KB |
Output is correct |
2 |
Correct |
2 ms |
1052 KB |
Output is correct |
3 |
Correct |
1 ms |
1044 KB |
Output is correct |
4 |
Correct |
2 ms |
1044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1048 KB |
Output is correct |
2 |
Correct |
10 ms |
1308 KB |
Output is correct |
3 |
Correct |
10 ms |
1304 KB |
Output is correct |
4 |
Incorrect |
10 ms |
1060 KB |
Incorrect |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
1048 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1048 KB |
Output is correct |
2 |
Correct |
10 ms |
1308 KB |
Output is correct |
3 |
Correct |
10 ms |
1304 KB |
Output is correct |
4 |
Incorrect |
10 ms |
1060 KB |
Incorrect |
5 |
Halted |
0 ms |
0 KB |
- |