A bunch new problems

This commit is contained in:
2026-03-16 17:09:23 -03:00
parent 41d9ca1dc8
commit 2d314df46f
65 changed files with 9058 additions and 78 deletions

View File

@@ -0,0 +1,302 @@
/* Problem URL: https://codeforces.com/gym/102361/problem/A */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T, class comp = less<>>
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
#define V vector
#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)
#define rep(i, lim) for (int i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;
template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
os << vec[0];
for (size_t i = 1; i < vec.size(); i++) {
os << ' ' << vec[i];
}
os << '\n';
return os;
}
template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
for (auto &i : vec) {
is >> i;
}
return is;
}
template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
for (auto &i : vec) {
os << i[0];
for (size_t j = 1; j < i.size(); j++) {
os << ' ' << i[j];
}
os << '\n';
}
return os;
}
template<class v>
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
for (auto &i : vec) {
for (auto &j : i) {
is >> j;
}
}
return is;
}
const int oo = INT32_MAX >> 1;
const ll OO = INT64_MAX >> 1;
struct pt {
ll x, y;
pt() = default;
pt(ll x, ll y): x(x), y(y) {}
friend istream &operator >> (istream &is, pt &a) {
is >> a.x >> a.y;
return is;
}
ll operator ^ (pt b) {
return x * b.y - y * b.x;
}
ll operator * (pt b) {
return x * b.x + y * b.y;
}
pt operator - (pt b) {
return pt(x - b.x, y - b.y);
}
};
int ccw(pt a, pt b, pt c)
{
ll r = (b - a) ^ (c - a);
return (r > 0) - (r < 0);
}
ll cdot(pt a, pt b, pt c)
{
return (b - a) * (c - a);
}
int quad(pt a)
{
if (a.x == 0 && a.y > 0) {
return 0;
}
if (a.x > 0 && a.y == 0) {
return 1;
}
if (a.x == 0 && a.y < 0) {
return 2;
}
if (a.x < 0 && a.y == 0) {
return 3;
}
static const int q[][2] = {{0, 1}, {3, 2}};
return q[a.x < 0][a.y < 0];
}
bool polar_cmp(pt a, pt b)
{
if (quad(a) != quad(b)) {
return quad(a) != quad(b);
}
return ccw(pt(0, 0), a, b) < 0;
}
void pre()
{
}
#define TEST 0
void solve()
{
int n, q;
cin >> n >> q;
V<pt> pts(n + q);
cin >> pts;
vi p(n + q);
iota(all(p), 0);
auto cmpr = [&](vi &p, int i) {
if (p.empty()) {
return vector<pair<int, ll>>();
}
sort(all(p), [&](int j, int k){return polar_cmp(pts[j] - pts[i], pts[k] - pts[i]);});
V<pair<int, ll>> v;
int c = 1;
nrep(j, 1, p.size()) {
if (ccw(pts[i], pts[p[j]], pts[p[j - 1]]) == 0) {
c++;
continue;
}
v.emplace_back(p[j - 1], c);
c = 1;
}
v.emplace_back(p.back(), c);
return v;
};
vl ans(q);
rep(i, n) {
vvi qp(4);
nrep(j, n, n + q) {
qp[quad(pts[j] - pts[i])].push_back(j);
}
vvi np(4);
rep(j, n) {
if (i == j) {
continue;
}
np[quad(pts[j] - pts[i])].push_back(j);
}
V<V<pair<int, ll>>> cp = {cmpr(np[0], i), cmpr(np[1], i), cmpr(np[2], i), cmpr(np[3], i)};
auto cmp = [&](int j, int k) {
return polar_cmp(pts[j] - pts[i], pts[k] - pts[i]);
};
sort(all(qp[0]), cmp);
sort(all(qp[1]), cmp);
sort(all(qp[2]), cmp);
sort(all(qp[3]), cmp);
auto getcw = [&](vi &p, V<pair<int, ll>> &c) {
int j = 0;
int k = 0;
while (j < p.size() && k < c.size()) {
ll dot = cdot(pts[i], pts[p[j]], pts[c[k].first]);
if (dot == 0) {
ans[p[j] - n] += c[k].second;
j++;
continue;
}
if (dot > 0) {
k++;
continue;
}
j++;
}
};
auto getccw = [&](vi &p, V<pair<int, ll>> &c) {
int j = (int)p.size() - 1;
int k = (int)c.size() - 1;
while (j >= 0 && k >= 0) {
ll dot = cdot(pts[i], pts[p[j]], pts[c[k].first]);
if (dot == 0) {
ans[p[j] - n] += c[k].second;
j--;
continue;
}
if (dot > 0) {
k--;
continue;
}
j--;
}
};
rep(j, 4) {
getcw(qp[j], cp[(j + 1) % 4]);
getccw(qp[j], cp[((j - 1) % 4 + 4) % 4]);
}
}
nrep(i, n, n + q) {
vvi np(4);
rep(j, n) {
np[quad(pts[j] - pts[i])].push_back(j);
}
V<V<pair<int, ll>>> cp = {cmpr(np[0], i), cmpr(np[1], i), cmpr(np[2], i), cmpr(np[3], i)};
auto getcw = [&](V<pair<int, ll>> &p1, V<pair<int, ll>> &p2) {
int j = 0;
int k = 0;
while (j < p1.size() && k < p2.size()) {
ll dot = cdot(pts[i], pts[p1[j].first], pts[p2[k].first]);
if (dot == 0) {
ans[i - n] += p1[j].second * p2[k].second;
j++;
k++;
continue;
}
if (dot < 0) {
j++;
continue;
}
k++;
}
};
rep(j, 4) {
getcw(cp[j], cp[(j + 1) % 4]);
}
}
repv(i, ans) {
cout << i << '\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
int t;
(TEST && cin >> t) || (t = 1);
while (t--) {
solve();
}
}