// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #include <x86intrin.h>
#include <bits/stdc++.h>
#include <chrono>
#include <random>
// @author: Vlapos
namespace operators
{
template <typename T1, typename T2>
std::istream &operator>>(std::istream &in, std::pair<T1, T2> &x)
{
in >> x.first >> x.second;
return in;
}
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, std::pair<T1, T2> x)
{
out << x.first << " " << x.second;
return out;
}
template <typename T1>
std::istream &operator>>(std::istream &in, std::vector<T1> &x)
{
for (auto &i : x)
in >> i;
return in;
}
template <typename T1>
std::ostream &operator<<(std::ostream &out, std::vector<T1> &x)
{
for (auto &i : x)
out << i << " ";
return out;
}
template <typename T1>
std::ostream &operator<<(std::ostream &out, std::set<T1> &x)
{
for (auto &i : x)
out << i << " ";
return out;
}
}
// name spaces
using namespace std;
using namespace operators;
// end of name spaces
// defines
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define uint unsigned int
#define all(vc) vc.begin(), vc.end()
// end of defines
// usefull stuff
void boost()
{
ios_base ::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
inline int getbit(int &x, int &bt) { return (x >> bt) & 1; }
const int dx4[4] = {-1, 0, 0, 1};
const int dy4[4] = {0, -1, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy8[8] = {-1, -0, 1, -1, 1, -1, 0, 1};
const ll INF = (1e18) + 500;
const int BIG = (1e9) * 2 + 100;
const int MAXN = (1e5) + 5;
const int MOD7 = (1e9) + 7;
const int MOD9 = (1e9) + 9;
const uint MODFFT = 998244353;
// #define int ll
struct test
{
vector<vector<pii>> D1, D2, xs, ys;
vector<pii> els;
vector<int> d1, d2, X, Y, deleted;
int n;
void doArray(vector<deque<int>> &a, vector<vector<pii>> &b)
{
a.resize(b.size());
for (int i = 0; i < b.size(); ++i)
for (auto [bf, el] : b[i])
a[i].push_back(el);
}
pii canBeInfected(pii curinf, int v)
{
if (v == -1)
return {-1, -1};
auto [x1, y1] = els[curinf.f];
int dir = curinf.s;
auto [x2, y2] = els[v];
// const int dx4[4] = {-1, 0, 0, 1};
// const int dy4[4] = {0, -1, 1, 0};
if (dir == 0 and y1 >= y2)
{
if (x1 == x2)
return {(y2 - y1) / 2, 3};
else if (x1 < x2)
return {x2 - x1, 1};
else
return {x1 - x2, 2};
}
else if (dir == 3 and y2 >= y1)
{
if (x1 == x2)
return {(y2 - y1) / 2, 0};
else if (x1 < x2)
return {x2 - x1, 1};
else
return {x1 - x2, 2};
}
else if (dir == 1 and x2 <= x1)
{
if (y1 == y2)
return {(x1 - x2) / 2, 0};
else if (y1 < y2)
return {y2 - y1, 0};
else
return {y1 - y2, 3};
}
else if (dir == 2 and x1 <= x2)
{
if (y1 == y2)
return {(x2 - x1) / 2, 0};
else if (y1 < y2)
return {y2 - y1, 0};
else
return {y1 - y2, 3};
}
return {-1, -1};
}
int getFront(deque<int> &a)
{
while (a.size() and deleted[a.front()])
a.pop_front();
return a.size() ? a.front() : -1;
}
int getBack(deque<int> &a)
{
while (a.size() and deleted[a.back()])
a.pop_back();
return a.size() ? a.back() : -1;
}
int solve(int st, int dir)
{
deleted.assign(n, 0);
vector<deque<int>> elsD1, elsD2, elsx, elsy;
doArray(elsD1, D1);
doArray(elsD2, D2);
doArray(elsx, xs);
doArray(elsy, ys);
priority_queue<pair<int, pii>> els, toels;
els.push({0, {0, dir}});
deleted[0] = 1;
auto add = [&](int cur, pii v, int tm) -> bool
{
pii curtm = canBeInfected(v, cur);
if (curtm.f >= tm)
{
toels.push({-curtm.f, {cur, curtm.s}});
return true;
}
else
return false;
};
auto doJob = [&](deque<int> &A, pii v, int tm) -> void
{
{
int to = getFront(A);
while (add(to, v, tm))
{
deleted[to] = 1;
to = getFront(A);
}
}
{
int to = getBack(A);
while (add(to, v, tm))
{
deleted[to] = 1;
to = getBack(A);
}
}
};
int cnt = 0;
while (true)
{
while (els.size())
{
auto [tm, v] = els.top();
tm = -tm;
cnt++;
els.pop();
doJob(elsD1[d1[v.f]], v, tm);
doJob(elsD2[d2[v.f]], v, tm);
doJob(elsx[X[v.f]], v, tm);
doJob(elsy[Y[v.f]], v, tm);
}
if (!toels.size())
break;
swap(els, toels);
}
return cnt;
}
void solve(int testcase)
{
boost();
cin >> n;
els.resize(n);
d1.resize(n);
d2.resize(n);
X.resize(n);
Y.resize(n);
cin >> els;
vector<int> d1vals, d2vals, xvals, yvals;
for (auto &[x, y] : els)
{
x *= 2;
y *= 2;
d1vals.pb(x + y);
d2vals.pb(x - y);
xvals.pb(x);
yvals.pb(y);
}
sort(all(d1vals));
d1vals.erase(unique(all(d1vals)), d1vals.end());
sort(all(d2vals));
d2vals.erase(unique(all(d2vals)), d2vals.end());
sort(all(xvals));
xvals.erase(unique(all(xvals)), xvals.end());
sort(all(yvals));
yvals.erase(unique(all(yvals)), yvals.end());
D1.resize(d1vals.size());
D2.resize(d2vals.size());
xs.resize(xvals.size());
ys.resize(yvals.size());
for (int i = 0; i < n; ++i)
{
auto [x, y] = els[i];
d1[i] = lower_bound(all(d1vals), x + y) - d1vals.begin();
d2[i] = lower_bound(all(d2vals), x - y) - d2vals.begin();
X[i] = lower_bound(all(xvals), x) - xvals.begin();
Y[i] = lower_bound(all(yvals), y) - yvals.begin();
D1[d1[i]].pb({x, i});
D2[d2[i]].pb({x, i});
xs[X[i]].pb({y, i});
ys[Y[i]].pb({x, i});
}
for (int i = 0; i < n; ++i)
{
if (i < D1.size())
sort(all(D1[i]));
if (i < D2.size())
sort(all(D2[i]));
if (i < xs.size())
sort(all(xs[i]));
if (i < ys.size())
sort(all(ys[i]));
}
int res = 1;
for (int i = 1; i < 2; ++i)
res = max(solve(0, i), res);
cout << res << "\n";
}
};
main()
{
boost();
int q = 1;
// cin >> q;
for (int i = 0; i < q; i++)
{
test t;
t.solve(i);
}
return 0;
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//
// //
// Coded by Der_Vlἀpos //
// //
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//
Compilation message
fever.cpp: In member function 'void test::doArray(std::vector<std::deque<int> >&, std::vector<std::vector<std::pair<int, int> > >&)':
fever.cpp:105:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for (int i = 0; i < b.size(); ++i)
| ~~^~~~~~~~~~
fever.cpp: In member function 'void test::solve(int)':
fever.cpp:287:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
287 | if (i < D1.size())
| ~~^~~~~~~~~~~
fever.cpp:289:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
289 | if (i < D2.size())
| ~~^~~~~~~~~~~
fever.cpp:291:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
291 | if (i < xs.size())
| ~~^~~~~~~~~~~
fever.cpp:293:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
293 | if (i < ys.size())
| ~~^~~~~~~~~~~
fever.cpp: At global scope:
fever.cpp:304:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
304 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |