U683517的题解
分3种情况计算
-
此时 $ \frac{1}{(z-z_i)^k_i} $ 在 $C$ 上解析,由柯西积分定理: $$ \oint_{\partial D} \frac{\mathrm{d}z}{z-z_i} = \oint_{\partial D} \frac{\mathrm{d}z}{(z-z_i)^2} = 0 $$ -
此时积分路径直接经过奇点,故: $$ \oint_{\partial D} \frac{\mathrm{d}z}{z-z_i} , \oint_{\partial D} \frac{\mathrm{d}z}{(z-z_i)^2}均发散 $$ -
此时奇点在积分路径内部,由留数定理: $$ \oint_{\partial D} \frac{\mathrm{d}z}{z-z_i}=2\pi i \quad \oint_{\partial D} \frac{\mathrm{d}z}{(z-z_i)^2}=0 $$
所以,如果矩形边界上有
将输入的点和查询都当作事件进行按先比较
树状数组:BIT 存储的是扫描线当前位置的所有已加入极点在不同
扫描线:遇到点就将其加入 BIT ,遇到查询就计数
容斥原理:对于每个查询事件
对于每次查询,二分查询
由于每个点都是整点,那么统计
可能会有人好奇如果
如果
如果将边界检查单独进行处理,比如哈希表 + 二分,会将常数消耗降低,但本题时间较为宽松
代码如下:
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
int main() {
short t;
scanf("%hd", &t);
for (;t--;) {
int n, q;
scanf("%d%d", &n, &q);
vector<tuple<int, int, short>> point(n);
for (int i = 0;i < n;i++) scanf("%d%d%hd", &get<0>(point[i]), &get<1>(point[i]), &get<2>(point[i]));
sort(point.begin(), point.end(), [](auto& a, auto& b) {return get<0>(a) < get<0>(b) || get<0>(a) == get<0>(b) && get<1>(a) < get<1>(b);});
vector<tuple<int, int, int, short>> check(8 * q);
for (int i = 0;i < q;i++) {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
check[8 * i + 0] = { c,d,i,0 };
check[8 * i + 1] = { a - 1,d,i,1 };
check[8 * i + 2] = { a - 1,b - 1,i,2 };
check[8 * i + 3] = { c,b - 1,i,3 };
check[8 * i + 4] = { c - 1,d - 1,i,4 };
check[8 * i + 5] = { a ,d - 1,i,5 };
check[8 * i + 6] = { a ,b,i,6 };
check[8 * i + 7] = { c - 1,b,i,7 };
}
sort(check.begin(), check.end(), [](auto& a, auto& b) {return get<0>(a) < get<0>(b) || get<0>(a) == get<0>(b) && get<1>(a) < get<1>(b);});
vector<int> clnumber1(q, 0), clnumber2(q, 0), opnumber1(q, 0), opnumber2(q, 0), BIT1(100001, 0), BIT2(100001, 0);
int i1 = 0, i2 = 0;
for (;i1 < n && i2 < 8 * q;) {
if (get<0>(point[i1]) < get<0>(check[i2]) || get<0>(point[i1]) == get<0>(check[i2]) && get<1>(point[i1]) <= get<1>(check[i2])) {
if (get<2>(point[i1]) == 1) for (int j = get<1>(point[i1]);j <= 100000;j += j & -j) BIT1[j]++;
else for (int j = get<1>(point[i1]);j <= 100000;j += j & -j) BIT2[j]++;
i1++;
}
else {
if (get<3>(check[i2]) == 0 || get<3>(check[i2]) == 2) for (int j = get<1>(check[i2]);j;j -= j & -j) {
clnumber1[get<2>(check[i2])] += BIT1[j];
clnumber2[get<2>(check[i2])] += BIT2[j];
}
else if (get<3>(check[i2]) == 1 || get<3>(check[i2]) == 3) for (int j = get<1>(check[i2]);j;j -= j & -j) {
clnumber1[get<2>(check[i2])] -= BIT1[j];
clnumber2[get<2>(check[i2])] -= BIT2[j];
}
else if (get<3>(check[i2]) == 4 || get<3>(check[i2]) == 6) for (int j = get<1>(check[i2]);j;j -= j & -j) {
opnumber1[get<2>(check[i2])] += BIT1[j];
opnumber2[get<2>(check[i2])] += BIT2[j];
}
else for (int j = get<1>(check[i2]);j;j -= j & -j) {
opnumber1[get<2>(check[i2])] -= BIT1[j];
opnumber2[get<2>(check[i2])] -= BIT2[j];
}
i2++;
}
}
for (;i2 < 8 * q;i2++) {
if (get<3>(check[i2]) == 0 || get<3>(check[i2]) == 2) for (int j = get<1>(check[i2]);j;j -= j & -j) {
clnumber1[get<2>(check[i2])] += BIT1[j];
clnumber2[get<2>(check[i2])] += BIT2[j];
}
else if (get<3>(check[i2]) == 1 || get<3>(check[i2]) == 3) for (int j = get<1>(check[i2]);j;j -= j & -j) {
clnumber1[get<2>(check[i2])] -= BIT1[j];
clnumber2[get<2>(check[i2])] -= BIT2[j];
}
else if (get<3>(check[i2]) == 4 || get<3>(check[i2]) == 6) for (int j = get<1>(check[i2]);j;j -= j & -j) {
opnumber1[get<2>(check[i2])] += BIT1[j];
opnumber2[get<2>(check[i2])] += BIT2[j];
}
else for (int j = get<1>(check[i2]);j;j -= j & -j) {
opnumber1[get<2>(check[i2])] -= BIT1[j];
opnumber2[get<2>(check[i2])] -= BIT2[j];
}
}
for (int i = 0;i < q;i++) {
if (clnumber1[i] == opnumber1[i] && clnumber2[i] == opnumber2[i]) printf("%d ", clnumber1[i]);
else printf("-1 ");
}
putchar('\n');
}
}