Loj 2052 矿区

平面图转对偶图.

先把平面图转成对偶图.

方法是把每条无向边拆成两条有向边,规定每个面都在围成它的有向边的左侧,这样每条有向边就只会被用一次.

对于每个边,按照极角序找它转动后下一条边,这样会形成一个置换.

分解后得到的每个环就对应了每个面,即对偶图中的每个点,再在有公共边的面之间连边即可.

找出面的时候用叉积顺便算一下面积,面积为负数的就是外面无穷大的面.

然后以最外面无穷大的面为根,做一棵生成树出来,询问时按照最外围边对子树和容斥一下即可.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll out = 0, fh = 1;
char jp = getchar();
while ((jp > '9' || jp < '0') && jp != '-')
jp = getchar();
if (jp == '-')
fh = -1, jp = getchar();
while (jp >= '0' && jp <= '9')
out = out * 10 + jp - '0', jp = getchar();
return out * fh;
}
ll Abs(ll x)
{
return x > 0 ? x : -x;
}
const double eps = 1e-10;
const int N = 4e6 + 10;
int n, m, q, rt, cnt, tid[N];
ll sum[N][2];
struct v2
{
int x, y;
v2(int x = 0, int y = 0) : x(x), y(y) {}
v2 operator - (const v2 &rhs) const
{
return v2(x - rhs.x, y - rhs.y);
}
ll operator * (const v2 &rhs) const
{
return 1LL * x * rhs.y - 1LL * y * rhs.x;
}
double angle()
{
return atan2(y, x);
}
} p[N];
double calc(int u, int v)
{
return (p[v] - p[u]).angle();
}
struct Edge
{
int u, v, id;
double slop;
Edge(int u = 0, int v = 0, int id = 0, double slop = 0) :
u(u), v(v), id(id), slop(slop) {}
friend bool operator < (Edge A, Edge B)
{
if (fabs(A.slop - B.slop) > eps)
return A.slop < B.slop;
return A.v < B.v;
}
} E[N];
typedef vector<Edge>::iterator vit;
vector<Edge> vec[N];
namespace DualGraph
{
int ecnt = 1, head[N], to[N], nx[N];
void addedge(int u, int v)
{
++ecnt;
to[ecnt] = v;
nx[ecnt] = head[u];
head[u] = ecnt;
}
int fa[N], vis[N], ontree[N];
void dfs(int u, int F)
{
fa[u] = F, vis[u] = 1;
for (int i = head[u]; i; i = nx[i])
{
int v = to[i];
if (vis[v])
continue;
ontree[i] = ontree[i ^ 1] = 1;
dfs(v, u);
sum[u][0] += sum[v][0], sum[u][1] += sum[v][1];
}
}
int np[N];
void solve()
{
dfs(rt, 0);
ll num = 0, deno = 0;
for (int i = 1; i <= q; ++i)
{
ll c = (read() + num) % n + 1;
for (int j = 1; j <= c; ++j)
{
ll x = (read() + num) % n + 1;
np[j] = x;
}
np[c + 1] = np[1];
num = deno = 0;
for (int j = 1; j <= c; ++j)
{
int x = np[j], y = np[j + 1];
Edge tmp = Edge(x, y, 0, calc(x, y));
vit it = lower_bound(vec[x].begin(), vec[x].end(), tmp);
int a = (*it).id, b = a ^ 1;
if (!ontree[a])
continue;
a = tid[a], b = tid[b];
if (fa[a] == b)
{
deno += sum[a][0];
num += sum[a][1];
}
else if (fa[b] == a)
{
deno -= sum[b][0];
num -= sum[b][1];
}
}
num = Abs(num), deno = Abs(deno);
ll g = __gcd(num, deno);
num /= g, deno /= g;
printf("%lld %lld\n", num, deno);
}
}
}
namespace PlanGraph
{
int ecnt = 1, nx[N];
void addedge(int u, int v)
{
++ecnt;
E[ecnt] = Edge(u, v, ecnt, calc(u, v));
vec[u].push_back(E[ecnt]);
}
void Init()
{
n = read(), m = read(), q = read();
for (int i = 1; i <= n; ++i)
p[i].x = read(), p[i].y = read();
for (int i = 1; i <= m; ++i)
{
int u = read(), v = read();
addedge(u, v);
addedge(v, u);
}
for (int i = 1; i <= n; ++i)
sort(vec[i].begin(), vec[i].end());
for (int i = 2; i <= ecnt; ++i)
{
int v = E[i].v;
vit it = lower_bound(vec[v].begin(), vec[v].end(), E[i ^ 1]);
if (it == vec[v].begin())
it = vec[v].end();
--it;
nx[i] = (*it).id;
}
for (int i = 2; i <= ecnt; ++i)
if (!tid[i])
{
tid[i] = ++cnt;
ll Area = 0;
v2 st = p[E[i].u];
for (int x = nx[i]; x != i; x = nx[x])
{
tid[x] = cnt;
v2 a = p[E[x].u], b = p[E[x].v];
Area += (a - st) * (b - st);
}
if (Area < 0)
rt = cnt;
else
{
sum[cnt][0] = Area * 2;
sum[cnt][1] = Area * Area;
}
}
for (int i = 2; i <= ecnt; ++i)
DualGraph::addedge(tid[i], tid[i ^ 1]);
}
}
int main()
{
PlanGraph::Init();
DualGraph::solve();
return 0;
}