이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 30007;
struct Point {
int x, y, c;
Point operator - (Point p) {
return {x - p.x, y - p.y};
}
Point operator + (Point p) {
return {x + p.x, y + p.y};
}
int operator *(Point p) {
return x * p.y - y * p.x;
}
} a[N];
int sign(int x) {
if (x < 0)
return -1;
else if (x == 0)
return 0;
else
return 1;
}
vector <Point> cA[N][2], cB[N][2];
vector <Point> al[N];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i].x >> a[i].y >> a[i].c;
}
Point A, B;
cin >> A.x >> A.y;
cin >> B.x >> B.y;
auto half = [&](Point p) {
int ans = (p - A) * (B - A) > 0;
return ans;
};
for (int i = 1; i <= n; ++i) {
cA[a[i].c][half(a[i])].app(a[i]);
cB[a[i].c][half(a[i])].app(a[i]);
al[a[i].c].app(a[i]);
}
auto compA = [&](Point a, Point b) {
return (a - A) * (b - A) > 0;
};
auto compB = [&](Point a, Point b) {
return (a - B) * (b - B) > 0;
};
for (int i = 1; i <= m; ++i) {
for (int j = 0; j < 2; ++j) {
sort(all(cA[i][j]), compA);
sort(all(cB[i][j]), compB);
}
}
int q;
cin >> q;
while (q--) {
int c1, c2;
cin >> c1 >> c2;
int ans = 0;
for (auto a : al[c1]) {
int t = half(a);
{
int l = -1, r = cA[c2][t^1].size();
auto sim = A + (A - a);
while (l < r - 1) {
int m = (l + r) >> 1;
if (compA(cA[c2][t^1][m], sim))
l = m;
else
r = m;
}
if ((A - a) * (B - a) > 0) {
ans -= r;
}
else {
ans += r;
}
}
{
int l = -1, r = cB[c2][t^1].size();
auto sim = B + (B - a);
while (l < r - 1) {
int m = (l + r) >> 1;
if (compB(cB[c2][t^1][m], sim))
l = m;
else
r = m;
}
if ((A - a) * (B - a) > 0) {
ans += r;
}
else {
ans -= r;
}
}
for (auto b : cA[c2][t]) {
auto l = A - a;
auto r = B - a;
auto v = b - a;
if (sign(l * r) * sign(l * v) > 0 && sign(l * r) * sign(v * r) > 0) {
++ans;
}
}
}
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |