Submission #776505

# Submission time Handle Problem Language Result Execution time Memory
776505 2023-07-08T02:58:13 Z maomao90 Dragon 2 (JOI17_dragon2) C++17
100 / 100
3649 ms 9988 KB
#include <bits/stdc++.h>
using namespace std;

#define REP(i, j, k) for (int i = (j); i < (k); i++)
#define RREP(i, j, k) for (int i = (j); i >= (k); i--)

template <class T>
inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}

typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005;
const int MAXN = 60005;

struct Point {
	int x, y;
	friend Point& operator+=(Point &l, const Point &r) {
		l.x += r.x;
		l.y += r.y;
		return l;
	}
	friend Point& operator-=(Point &l, const Point &r) {
		l.x -= r.x;
		l.y -= r.y;
		return l;
	}
	Point operator+(const Point &o) const {
		Point res = *this;
		return res += o;
	}
	Point operator-(const Point &o) const {
		Point res = *this;
		return res -= o;
	}
	friend istream& operator>>(istream &is, Point &o) {
		return is >> o.x >> o.y;
	}
	friend ostream& operator<<(ostream &os, const Point &o) {
		return os << "(" << o.x << ", " << o.y << ")";
	}
};
ll cross(const Point &l, const Point &r) {
	return (ll) l.x * r.y - (ll) l.y * r.x;
}
ll dot(const Point &l, const Point &r) {
	return (ll) l.x * r.x + (ll) l.y * r.y;
}
int side(const Point &p) {
	if (p.y > 0 || (p.y == 0 && p.x >= 0)) {
		return 0;
	}
	return 1;
}

int n, m;
Point pt[MAXN];
vi grp[MAXN];
Point p[2];
int ord[2][MAXN];
int pos[MAXN][2];
vii rg[MAXN][2];
int q;

auto cmp(const Point &p) {
	return [&] (int l, int r) {
		Point lp = pt[l] - p, rp = pt[r] - p;
		if (side(lp) != side(rp)) {
			return side(lp) < side(rp);
		}
		return cross(lp, rp) > 0;
	};
}

int main() {
#ifndef DEBUG
	ios::sync_with_stdio(0), cin.tie(0);
#endif
	cin >> n >> m;
	REP (i, 0, n) {
		int c; cin >> pt[i] >> c;
		grp[c].pb(i);
	}
	cin >> p[0] >> p[1];
	REP (z, 0, 2) {
		iota(ord[z], ord[z] + n, 0);
		sort(ord[z], ord[z] + n, cmp(p[z]));
		REP (i, 0, n) {
			ord[z][i + n] = ord[z][i];
		}
	}
	REP (z, 0, 2) {
		REP (i, 0, n) {
			pos[ord[z][i]][z] = i;
		}
	}
	REP (z, 0, 2) {
		vi top, btm;
		int r = 0;
		REP (i, 0, n) {
			Point cp = pt[ord[z][i]];
			if (cross(cp - p[z], p[z ^ 1] - p[z]) > 0) {
				mxto(r, i);
				while (r + 1 < i + n && cross(cp - p[z], pt[ord[z][r + 1]] - p[z]) > 0) {
					r++;
				}
				if (r < n) {
					rg[ord[z][i]][z].pb({i, r});
				} else {
					rg[ord[z][i]][z].pb({i, n - 1});
					rg[ord[z][i]][z].pb({0, r - n});
				}
			}
		}
		int l = 2 * n;
		RREP (i, n - 1, 0) {
			Point cp = pt[ord[z][i]];
			if (cross(cp - p[z], p[z ^ 1] - p[z]) < 0) {
				mnto(l, i + n);
				while (l - 1 > i && cross(cp - p[z], pt[ord[z][l - 1]] - p[z]) < 0) {
					l--;
				}
				if (l >= n) {
					rg[ord[z][i]][z].pb({l - n, i});
				} else {
					rg[ord[z][i]][z].pb({l, n - 1});
					rg[ord[z][i]][z].pb({0, i});
				}
			}
		}
		cerr << z << '\n';
		REP (i, 0, n) {
			cerr << ' ' << i << '\n';
			for (auto [l, r] : rg[i][z]) {
				cerr << "  " << l << ' ' << r << '\n';
			}
		}
	}
	cin >> q;
	while (q--) {
		int f, g; cin >> f >> g;
		int ans = 0;
		for (int i : grp[f]) {
			for (int j : grp[g]) {
				bool bad = 0;
				REP (z, 0, 2) {
					bool gd = 0;
					for (auto [l, r] : rg[i][z]) {
						if (l <= pos[j][z] && pos[j][z] <= r) {
							gd = 1;
							break;
						}
					}
					if (!gd) {
						bad = 1;
						break;
					}
				}
				ans += !bad;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4880 KB Output is correct
2 Correct 31 ms 4872 KB Output is correct
3 Correct 39 ms 4880 KB Output is correct
4 Correct 33 ms 5044 KB Output is correct
5 Correct 24 ms 5056 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 4 ms 4948 KB Output is correct
8 Correct 7 ms 4820 KB Output is correct
9 Correct 8 ms 4820 KB Output is correct
10 Correct 11 ms 4820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1559 ms 7800 KB Output is correct
2 Correct 3021 ms 8208 KB Output is correct
3 Correct 82 ms 8184 KB Output is correct
4 Correct 28 ms 8204 KB Output is correct
5 Correct 23 ms 8716 KB Output is correct
6 Correct 844 ms 8184 KB Output is correct
7 Correct 851 ms 8184 KB Output is correct
8 Correct 386 ms 8172 KB Output is correct
9 Correct 422 ms 7892 KB Output is correct
10 Correct 383 ms 7984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4880 KB Output is correct
2 Correct 31 ms 4872 KB Output is correct
3 Correct 39 ms 4880 KB Output is correct
4 Correct 33 ms 5044 KB Output is correct
5 Correct 24 ms 5056 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 4 ms 4948 KB Output is correct
8 Correct 7 ms 4820 KB Output is correct
9 Correct 8 ms 4820 KB Output is correct
10 Correct 11 ms 4820 KB Output is correct
11 Correct 1559 ms 7800 KB Output is correct
12 Correct 3021 ms 8208 KB Output is correct
13 Correct 82 ms 8184 KB Output is correct
14 Correct 28 ms 8204 KB Output is correct
15 Correct 23 ms 8716 KB Output is correct
16 Correct 844 ms 8184 KB Output is correct
17 Correct 851 ms 8184 KB Output is correct
18 Correct 386 ms 8172 KB Output is correct
19 Correct 422 ms 7892 KB Output is correct
20 Correct 383 ms 7984 KB Output is correct
21 Correct 1524 ms 8176 KB Output is correct
22 Correct 3003 ms 8244 KB Output is correct
23 Correct 3019 ms 8344 KB Output is correct
24 Correct 876 ms 9340 KB Output is correct
25 Correct 59 ms 9608 KB Output is correct
26 Correct 49 ms 9988 KB Output is correct
27 Correct 23 ms 9292 KB Output is correct
28 Correct 23 ms 9244 KB Output is correct
29 Correct 3477 ms 9696 KB Output is correct
30 Correct 76 ms 9548 KB Output is correct
31 Correct 46 ms 9808 KB Output is correct
32 Correct 79 ms 9836 KB Output is correct
33 Correct 841 ms 9656 KB Output is correct
34 Correct 56 ms 9768 KB Output is correct
35 Correct 44 ms 9828 KB Output is correct
36 Correct 47 ms 9832 KB Output is correct
37 Correct 46 ms 9940 KB Output is correct
38 Correct 1125 ms 9652 KB Output is correct
39 Correct 1070 ms 9944 KB Output is correct
40 Correct 829 ms 9832 KB Output is correct
41 Correct 3649 ms 9716 KB Output is correct
42 Correct 2430 ms 9860 KB Output is correct
43 Correct 2195 ms 9608 KB Output is correct
44 Correct 2453 ms 8616 KB Output is correct
45 Correct 1248 ms 8652 KB Output is correct
46 Correct 995 ms 8592 KB Output is correct
47 Correct 1224 ms 8704 KB Output is correct
48 Correct 892 ms 8720 KB Output is correct
49 Correct 629 ms 8620 KB Output is correct