题目链接


\(Description\)

\(q\)次操作,每次给定点的坐标\((x,y)\),表示加入一个点\((x,y)\),或删除一个点\((x,y)\),或询问:至少需要在平面中加入多少个点,才能使得当前所有点关于\((0,0)-(x,y)\)这条直线对称。

\(q\leq2\times10^5,\ 1\leq x,y\leq 112904\)。

\(Solution\)

两个点关于\((0,0)-(x,y)\)对称,则它们到原点的距离是一样的,即位于同一个圆上。

可以猜到的一个结论是,以原点为圆心画圆,交到整点上的点不会很多。即方程\(x^2+y^2=r^2\)的正整数解\((x,y)\)不会很多。

所以每加入一个点\(i\),枚举和它在一个圆上的点\(j\),给\(i,j\)的对称轴的答案\(-2\),\(i\)自己做对称轴的答案\(-1\);删掉一个点\(i\),就给\(i,j\)的对称轴的答案\(+2\),给\(i\)做对称轴的答案\(+1\)。

对于询问直接输出即可。


//1684ms	23800KB(跑的这么慢..就这么慢吧=-=)
#include <map>
#include <set>
#include <cstdio>
#include <cctype>
#include <algorithm>
#define mp std::make_pair
#define pr std::pair<int,int>
#define gc() getchar()
typedef long long LL;
const int N=2e5+5,M=113000; std::set<pr> st[N];
std::map<LL,int> id;
std::map<int,int> Ans[M]; inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-48,c=gc());
return now;
}
inline int Getid(LL d)
{
static int Index=0;
return id.count(d)?id[d]:id[d]=++Index;
}
void Calc(int x,int y,int &xn,int &yn)
{
int g=std::__gcd(x,y);//g!=0
xn=x/g, yn=y/g;
} int main()
{
for(int Q=read(),tot=0; Q--; )
{
int opt=read(),x=read(),y=read(),xn,yn;
if(opt==1)
{
int p=Getid(1ll*x*x+1ll*y*y);
for(std::set<pr>::iterator it=st[p].begin(); it!=st[p].end(); ++it)
Calc((*it).first+x,(*it).second+y,xn,yn), Ans[xn][yn]+=2;
st[p].insert(mp(x,y)), Calc(x,y,xn,yn), ++Ans[xn][yn], ++tot;
}
else if(opt==2)
{
int p=Getid(1ll*x*x+1ll*y*y); st[p].erase(mp(x,y));
for(std::set<pr>::iterator it=st[p].begin(); it!=st[p].end(); ++it)
Calc((*it).first+x,(*it).second+y,xn,yn), Ans[xn][yn]-=2;
Calc(x,y,xn,yn), --Ans[xn][yn], --tot;
}
else Calc(x,y,xn,yn), printf("%d\n",tot-Ans[xn][yn]);
} return 0;
}

Codeforces.1028F.Make Symmetrical(结论 暴力)的更多相关文章

  1. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

  2. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  3. Codeforces Gym 100637G G. #TheDress 暴力

    G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...

  4. [ An Ac a Day ^_^ ] CodeForces 691F Couple Cover 花式暴力

    Couple Cover Time Limit: 3000MS   Memory Limit: 524288KB   64bit IO Format: %I64d & %I64u Descri ...

  5. Codeforces 626D Jerry's Protest(暴力枚举+概率)

    D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  6. codeforces 650D D. Image Preview (暴力+二分+dp)

    题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...

  7. Codeforces Gym 100203G Good elements 暴力乱搞

    原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...

  8. Codeforces 839D Winter is here - 暴力 - 容斥原理

    Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n s ...

  9. Codeforces 850A - Five Dimensional Points(暴力)

    原题链接:http://codeforces.com/problemset/problem/850/A 题意:有n个五维空间内的点,如果其中三个点A,B,C,向量AB,AC的夹角不大于90°,则点A是 ...

随机推荐

  1. Distance

    1191: Distance 时间限制: 1 Sec  内存限制: 32 MB 题目描述 There is a battle field. It is a square with the side l ...

  2. vue 在.vue文件里监听路由

    监听路由  watch   $route vue项目中的App.vue 文件 <template> <div id="app"> <!--includ ...

  3. Python使用正则表达式分割字符串

    re.split(pattern, string, [maxsplit], [flags]) pattern:表示模式字符串,由要匹配的正则表达式转换而来. string:表示要匹配的字符串. max ...

  4. 论文阅读笔记二十六:Fast R-CNN (ICCV2015)

    论文源址:https://arxiv.org/abs/1504.08083 参考博客:https://blog.csdn.net/shenxiaolu1984/article/details/5103 ...

  5. ubuntu安装界面 会出现不完整情况

    解决方法: alt+鼠标左键或者win+鼠标左键拖动

  6. Python练习题

    内置函数 # 5.随意写一个20行以上的文件# 运行程序,先将内容读到内存中,用列表存储.# 接收用户输入页码,每页5条,仅输出当页的内容 def user_check(filename,num=5) ...

  7. ActiveSync之HTTP

    Exchange ActiveSync:HTTP协议让客户端能够同步存储在服务器上的数据. 互联网工程工作小组(IETF)要求所有互联网协议都比支持UTF-8编码.因此,ActiveSync传输所使用 ...

  8. .NET Framework 类库——C#命名空间大全

    引用地址:https://msdn.microsoft.com/zh-cn/library/gg145045.aspx C# using引用时,不知道有哪些命名空间,这下转载收集一篇,方面查找使用. ...

  9. 使用heptiolabs/eventrouter收集K8S的事件

    k8s的heapster项目中止以后, 事件收集的项目,就推荐使用https://github.com/heptiolabs/eventrouter项目了. 部署文档很简单,但有两个问题要解决: 一, ...

  10. 分享几个在线生成网址二维码的API接口

    现在很多大网站都有这样的一个功能,使用手机扫描一下网页上的二维码便可快速在手机上访问网站.想要实现这样的功能其实很简单,下面麦布分享几个在线生成网址二维码的API接口.都是采用http协议接口,无需下 ...