QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301483#7511. Planar GraphdefyersWA 1ms4120kbC++204.8kb2024-01-09 22:56:472024-01-09 22:56:47

Judging History

你现在查看的是最新测评结果

  • [2024-01-09 22:56:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4120kb
  • [2024-01-09 22:56:47]
  • 提交

answer

#include "bits/stdc++.h"
#include <algorithm>
#include <ostream>
#include <random>
using namespace std;

using ll = long long;
using LL = long long;
using pii = pair<int, int>;

using ull = unsigned long long;
using int128 = __int128;

template<class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point {
	typedef Point P;
	T x, y;
	Point(T x = 0, T y = 0) : x(x), y(y) {}
	bool operator<(P p) { return tie(x, y) < tie(p.x, p.y); }
	bool operator==(P p) { return tie(x, y) == tie(p.x, p.y); }

	P operator+(P p) { return P(x+p.x, y+p.y); }
	P operator-(P p) { return P(x-p.x, y-p.y); }
	P operator*(T d) { return P(x*d, y*d); }
	P operator/(T d) { return P(x/d, y/d); }

	T dot(P p) { return x*p.x + y*p.y; }
	T cross(P p) { return x*p.y - y*p.x; }
	T cross(P a, P b) { return (a-*this).cross(b-*this); }
	T dist2() { return x*x + y*y; }
	double dist() { return sqrt(double(dist2())); }
	double angle() { return atan2(ll(y), ll(x)); }

	P unit() { return *this / dist(); }
	P perp() { return P(-y, x); }
	P normal() { return perp().unit(); }

	friend ostream& operator<<(ostream& os, P p) {
		return os << "(" << p.x << "," << p.y << ")";
	}
};

using P = Point<int128>;
double eps = 1e-9;

bool onSegment(P s, P e, P p) {
	return p.cross(s, e) == 0 && (s - p).dot(e - p) <= 0;
}

bool inPolygon(vector<P> &p, P a, bool strict = true) {
	int cnt = 0, n = int(size(p));
	for (int i = 0; i < n; i++) {
		P q = p[(i + 1) % n];
		if (onSegment(p[i], q, a)) return !strict;
		cnt ^= ((a.y < p[i].y) - (a.y < q.y)) * a.cross(p[i], q) > 0;
	}
	return cnt;
}

struct Edge {
	int id;
	int u, v;
	double angle;
	bool operator<(const Edge &o) const {
		if (fabs(angle - o.angle) > eps) return angle < o.angle;
		else return v < o.v;
	};
};

void solve(int TC) {
	int n, m, e;
	cin >> n >> m >> e;
	vector<P> baseP(n), sourceP(m);

	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		x *= 2, y *= 2;
		baseP[i] = {x, y};
	}
	for (int i = 0; i < m; i++) {
		ll x, y;
		cin >> x >> y;
		x *= 2, y *= 2;
		sourceP[i] = {x, y};
	}

	vector<vector<Edge>> g(n);
	vector<Edge> edge;
	for (int i = 0; i < e; i++) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		edge.push_back({ 2 * i, u, v, (baseP[v] - baseP[u]).angle() });
		g[u].push_back(edge.back());
		edge.push_back({ 2 * i + 1, v, u, (baseP[u] - baseP[v]).angle() });
		g[v].push_back(edge.back());
	}

	for (int i = 0; i < n; i++) {
		sort(g[i].begin(), g[i].end());
	}

	vector<int> nextedge(2 * e);
	for (int i = 0; i < 2 * e; i++) {
		int v = edge[i].v;
		auto iter = lower_bound(g[v].begin(), g[v].end(), edge[i ^ 1]);
		if (iter == g[v].begin()) iter = g[v].end();
		--iter;
		nextedge[i] = (*iter).id;
	}

	int face = 0;
	vector<vector<P>> facePoly; 
	vector<int> belong(2 * e, -1);
	for (int i = 0; i < 2 * e; i++) {
		if (belong[i] != -1) continue;
		belong[i] = belong[nextedge[i]] = face;
		double area = 0;
		facePoly.push_back({baseP[edge[i].u], baseP[edge[i].v]});
		for (int j = nextedge[i]; edge[j].v != edge[i].u; j = nextedge[j], belong[j] = face) {
			facePoly[face].push_back(baseP[edge[j].v]);
			area += baseP[edge[i].u].cross(baseP[edge[j].u], baseP[edge[j].v]);
		}
		
		if (face <= eps) { // 0 or negative -> non-close polygon
			facePoly[face] = {};
		}

		face++;
	}

	// for (int i = 0; i < 2 * e; i++) {
	// 	cout << i << " : " << belong[i] << endl;
	// }

	vector<P> intervalP(e);
	for (int i = 0; i < e; i++) {
		auto [id, u, v, _] = edge[2 * i];
		intervalP[i] = (baseP[u] + baseP[v]) / 2;
	}


	mt19937_64 rng(42);
	vector<ull> sourcePHash(m), intervalPHash(2 * e);
	for (int i = 0; i < face; i++) {
		// cout << "i: " << i << " --- ";
		// for (auto x: facePoly[i]) {
		// 	cout << x << " ";
		// }
		// cout << "\n";

		if (facePoly[i].empty()) continue;
		ull hash = rng();
		for (int j = 0; j < m; j++) {
			if (inPolygon(facePoly[i], sourceP[j])) {
				sourcePHash[j] ^= hash;
			}
		}
		for (int j = 0; j < e; j++) {
			bool online = false;
			if (belong[2 * j] == i) {
				online = true;
				intervalPHash[2 * j] ^= hash;
			}
			if (belong[2 * j + 1] == i) {
				online = true;
				intervalPHash[2 * j + 1] ^= hash;
			}
			if (!online && inPolygon(facePoly[i], intervalP[j])) {
				intervalPHash[2 * j] ^= hash;
				intervalPHash[2 * j + 1] ^= hash;
			}
		}
	}

	unordered_set<ull> S;
	S.reserve(m * 2);
	for (int i = 0; i < m; i++) S.insert(sourcePHash[i]);

	for (int i = 0; i < e; i++) {
		if (S.count(intervalPHash[2 * i]) || S.count(intervalPHash[2 * i + 1])) {
			cout << "1";
		}
		else {
			cout << "0";
		}
	}
	cout << "\n";
}

int32_t main() {
	cin.tie(0)->sync_with_stdio(0);
	cout << fixed << setprecision(10);

	int t = 1;
	// cin >> t;

	for (int i = 1; i <= t; i++) {
		solve(i);
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3896kb

input:

4 1 3
-2 0
0 2
2 0
0 1
0 3
1 2
2 3
1 3

output:

111

result:

ok single line: '111'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 4120kb

input:

13 35 13
13 12
16 -3
18 4
4 -7
23 -22
9 -23
23 11
12 -1
19 -5
15 -15
5 -15
-17 11
-17 -13
-20 19
11 -12
-10 14
-3 14
7 -4
-10 -23
-19 -12
-13 1
-22 10
-21 -1
18 -9
-8 1
13 22
12 -23
-9 -9
-12 -20
4 -3
-6 17
14 -10
10 13
-5 -2
-4 -12
13 22
-18 -21
19 5
12 -18
4 0
3 -17
5 -2
-2 0
8 0
-8 1
14 -18
3 -9
...

output:

1100100000001

result:

wrong answer 1st lines differ - expected: '1111111111111', found: '1100100000001'