题目链接


\(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. loadrunner出现报错operands of = have illegal types `pointer to char' and `int'

    原始代码: void split(char * p,char * str){ /* 传入一个数组进行p和一个以什么进行分割的str,返回切片后的值 */ int i = 0, j = 0; char ...

  2. python基础面试题(一)

    1.   简述Python代码的运行机制 1.把原始代码编译成字节码         编译后的字节码是特定于Python的一种表现形式,它不是二进制的机器码,需要进一步编译才能被机器执行. 2.把编译 ...

  3. Tensorflow生成唐诗和歌词(上)

    整个工程使用的是Windows版pyCharm和tensorflow. 源码地址:https://github.com/Irvinglove/tensorflow_poems/tree/master ...

  4. 007-Python函数-装饰器

    函数回顾 1.函数可以当做一个参数赋值给另一个函数: def func(): print("in the func") def foo(x): x() foo(func) 输出: ...

  5. python---实现多个有序列表的合并

    我觉得不用抄书上的代码. 遇到实现问题,应该结合python本身的功能去解决. 比如,当合并有序列表时,为什么一定要一项一项比较,而不是使用list的sort函数呢? # coding = utf-8 ...

  6. Go语言之匿名函数

    匿名函数和字面量函数一样, 凡是可以使用字面量函数的地方,都可以用匿名函数代替. 这个和js中的匿名函数差不多吧. package main import "fmt" var su ...

  7. [转] HTML5+规范:device(管理设备信息)

    http://blog.csdn.net/qq_27626333/article/details/51815310 Device模块管理设备信息,用于获取手机设备的相关信息,如IMEI.IMSI.型号 ...

  8. cuda by example【读书笔记1】

    cuda 1. 以前用OpenGL和DirectX API简介操作GPU,必须了解图形学的知识,直接操作GPU要考虑并发,原子操作等等,cuda架构为此专门设计.满足浮点运算,用裁剪后的指令集执行通用 ...

  9. angular 4 开发环境下打包文件过大

    angular 4本地开发环境下,ng server -- port 8080 -o 之后在在浏览器中查看数据请求,其中vendor.bundle.js有8.3mb,而整个传输数据大小为16.3mb ...

  10. 背包的一些idea

    题解: 给出n个物品,每次能使用l-r之间的物品,问能不能表示出k,m次询问 k<=100,m,n=1e5 想了线段树分治 发现是k^2(n+m)logn claris告诉我可以直接分治 我们对 ...