Codeforces.1028F.Make Symmetrical(结论 暴力)
\(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(结论 暴力)的更多相关文章
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
- [ An Ac a Day ^_^ ] CodeForces 691F Couple Cover 花式暴力
Couple Cover Time Limit: 3000MS Memory Limit: 524288KB 64bit IO Format: %I64d & %I64u Descri ...
- Codeforces 626D Jerry's Protest(暴力枚举+概率)
D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- codeforces 650D D. Image Preview (暴力+二分+dp)
题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...
- Codeforces Gym 100203G Good elements 暴力乱搞
原题链接:http://codeforces.com/gym/100203/attachments/download/1702/statements.pdf 题解 考虑暴力的复杂度是O(n^3),所以 ...
- 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 ...
- Codeforces 850A - Five Dimensional Points(暴力)
原题链接:http://codeforces.com/problemset/problem/850/A 题意:有n个五维空间内的点,如果其中三个点A,B,C,向量AB,AC的夹角不大于90°,则点A是 ...
随机推荐
- Niagara 泵阀
1.泵阀系统 2.Niagara 每次在启动workbench的时候安装一下daemon,后启动platform 启动station的时候,当station的status变成Running之后启动
- vue 中动态绑定class 和 style的方法
先列举一些例子 :class="['content',{'radioModel':checkType}]" :class="['siteAppListDirNode',{ ...
- 论文阅读笔记十三:The One Hundred Layers Tiramisu: Fully Convolutional DenseNets for Semantic Segmentation(FC-DenseNets)(CVPR2016)
论文链接:https://arxiv.org/pdf/1611.09326.pdf tensorflow代码:https://github.com/HasnainRaz/FC-DenseNet-Ten ...
- maven依赖查找方法
http://mvnrepository.com 1. 搜索依赖库 2. 选择合适版本 3. 复制配置 点击合适的版本进入,负责maven配置: <dependency> ...
- Python os.walk() 方法遍历文件目录
概述 os.walk() 方法用于通过在目录树中游走输出在目录中的文件名,向上或者向下. os.walk() 方法是一个简单易用的文件.目录遍历器,可以帮助我们高效的处理文件.目录方面的事情. 在Un ...
- JAVA 代码中使用中文的办法
在编译代码中插入 -encoding UTF-8 示例: javac -encoding UTF-8 *.java
- NodeJs——router报错原因
rout.js var http = require('http'); var url = require('url'); var router = require('./models/router. ...
- WCF 非http寄宿IIS
摘要 从IIS 7 开始, IIS增加了对非HTTP协议的支持. 因此, 自IIS 7之后, 可以将NetTcpBinding等非HTTP协议的Bindings直接寄宿在IIS上面. 本文将介绍如何在 ...
- Centos6安装SaltStack
rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm yum install ...
- UICollectionView的常用方法
class UICollectionView : UIScrollView //初始化,位置,风格 init(frame: CGRect, collectionViewLayout layout: U ...