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是 ...
随机推荐
- 小学生都看得懂的C语言入门(4): 数组与函数
// 之前判断素数, 只需要到sqrt(x)即可,//更加简单的, 判断能够比已知的小于x的素数整除, 运行更快 #include <stdio.h> // 之前判断素数, 只需要到sqr ...
- Fiddler导出Jmeter脚本
版本:V4.4 用途:将fiddler抓取的请求,导出为jmx格式,方便jmeter直接调用 新增功能: 1.在测试计划下,新增[HTTP请求默认值],内容为空,后续需将站点的IP和端口填下在这个下面 ...
- docker 给none镜像打镜像
1.遇到none的镜像打tag方式: docker tag + docker ID + 命名:版本名 案例:docker tag 41b7307026c0 gitlab:test 这就 ...
- Python内置模块之time模块
1:概述 时间表示的分类 时间戳 格式化的时间字符串 结构化时间 时间戳:时间戳表示的是从1970年1月1日整0点到目前秒的偏移量,数据类型是浮点型,主要用来让计算机看的 格式化的时间字符串:如 20 ...
- Scrapy 框架 安装
Scrapy 框架 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架,用途非常广泛. 框架的力量,用户只需要定制开发几个模块就可以轻松的实现一个爬虫,用来抓取网页 ...
- 解开一个疑惑,为什么LVS开放的端口,使用netstat或ss命令,不能查找到其监听的端口呢?
RT, 这个疑问,本周一直在心里,今天找到一个说法. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 另外LVS规则算是内核方法,用netstat -ntulp也显 ...
- 使用 cacti 监控 windows 服务器硬盘的 I/O 状况
https://blog.csdn.net/m0_37814112/article/details/80742433
- [转] AES,SHA1,DES,RSA,MD5区别
AES:更快,兼容设备,安全级别高: SHA1:公钥后处理回传 DES:本地数据,安全级别低 RSA:非对称加密,有公钥和私钥 MD5:防篡改 相关: 公开密钥加密(英语:public-key cry ...
- 【AtCoder】Tenka1 Programmer Contest 2019
Tenka1 Programmer Contest 2019 C - Stones 题面大意:有一个01序列,改变一个位置上的值花费1,问变成没有0在1右边的序列花费最少多少 直接枚举前i个都变成0即 ...
- go-无法下载websocket的问题
由于限制问题,国内使用 go get 安装 golang 官方包可能会失败,如我自己在安装 collidermain 时,出现了以下报错: $ go get collidermain package ...