/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/
#include "nice_lines.h"
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;
const int mxC = 2e4;
const int EmptyLow = mxC + 1;
const int EmptyHigh = 2 * mxC - 1;
const int mod = 3 * mxC;
const long double eps = 1e-4;
struct Point {
long double x, y;
Point(long double x, long double y) : x(x), y(y) {}
friend ostream & operator << (ostream &out, const Point &p) {
return out << "{" << p.x << ", " << p.y << "}" << endl;
}
};
struct Line {
long double a, b;
Line(long double a, long double b) : a(a), b(b) {}
Line(Point p, Point q) {
a = (q.y - p.y) / (q.x - p.x);
b = p.y - a * p.x;
}
bool OnLine(Point p) {
return fabsl(a * p.x + b - p.y) < eps;
}
friend ostream & operator << (ostream &out, const Line &l) {
return out << l.a << "x + " << l.b;
}
};
Point intersectLines(const Line& l1, const Line& l2) {
long double x = (l2.b - l1.b) / (l1.a - l2.a);
long double y = l1.a * x + l1.b;
return Point(x, y);
}
int cnt;
// long double query(long double x, long double y) { return 0.0L; }
long double F(long double x) { return query(mod, x); }
set<int> res;
void dnc(Line ll, Line lr) {
// cout << ll << endl << lr << endl;
// if (++cnt == 2) return;
// cout << ll << " " << lr << endl;
auto inter = intersectLines(ll, lr);
i64 y = round(inter.x);
// cout << y << endl;
i64 rem = (y % mod + mod) % mod;
if (EmptyLow <= rem and rem <= EmptyHigh) {
i64 d1 = rem - (rem - EmptyLow);
i64 d2 = rem + (EmptyHigh - rem);
Line lm(Point(d1, F(d1)), Point(d2, F(d2)));
dnc(ll, lm); dnc(lm, lr);
return;
}
i64 u1 = (rem < EmptyLow ? y + EmptyLow - rem : y + mod + EmptyLow - rem);
i64 u2 = (rem < EmptyHigh ? y + EmptyHigh - rem : y + mod + EmptyHigh - rem);
i64 d1 = u1 - mod, d2 = u2 - mod;
// cout << d1 << " " << u1 << " " << d2 << " " << u2 << endl;
// return;
Point Fd2 = Point(d2, F(d2));
// cout << Fd2 << endl;
if (ll.OnLine(Fd2)) {
Point Fu1 = Point(u1, F(u1));
// cout << Fu1 << endl;
// return;
if (lr.OnLine(Fu1)) res.insert(y);
else dnc(Line(Fu1, Point(u2, F(u2))), lr);
}
else {
// cout << "trolled" << endl;
// return;
Line lm = Line(Point(d1, F(d1)), Fd2);
// cout << lm << endl;
dnc(ll, lm); dnc(lm, lr);
}
}
void solve(int subtask_id, int n) {
cout << fixed << setprecision(9);
i64 l1 = -1ll * mod * mod - mod - EmptyHigh;
// cout << F(l2) << endl;
i64 l2 = -1ll * mod * mod - mod - EmptyLow;
i64 r1 = 1ll * mod * mod + mod + EmptyLow;
i64 r2 = 1ll * mod * mod + mod + EmptyHigh;
dnc(Line(Point(l1, F(l1)), Point(l2, F(l2))), Line(Point(r1, F(r1)), Point(r2, F(r2))));
// long long lowY1 = -1LL * MaxX * MaxX - Rest2;
// long double lowVal1 = query(MaxX, lowY1);
// long long lowY2 = -1LL * MaxX * MaxX - Rest1;
// long double lowVal2 = query(MaxX, lowY2);
// Line lowLine(lowY1, lowVal1, lowY2, lowVal2);
// long long highY1 = 1LL * MaxX * MaxX + Rest1;
// long double highVal1 = query(MaxX, highY1);
// long long highY2 = 1LL * MaxX * MaxX + Rest2;
// long double highVal2 = query(MaxX, highY2);
// Line highLine(highY1, highVal1, highY2, highVal2);
// divide(lowLine, highLine);
vector<int> a, b;
for (auto y : res) {
int bb = y % mod;
if (bb < -mxC) bb += mod;
if (bb > mxC) bb -= mod;
int aa = (y - bb) / mod;
a.push_back(aa);
b.push_back(bb);
}
the_lines_are(a, b);
}
// int main() {
// cout << -1 << endl;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
440 KB |
Output is correct |
4 |
Correct |
0 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
436 KB |
Output is correct |
4 |
Correct |
0 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
72 ms |
2864 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
89 ms |
2308 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
72 ms |
2864 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |