CF1028F. Make Symmetrical

CF1028F. Make Symmetrical

题目描述

Solution

结论1:两个点 ( x 1 , y 1 ) , ( x 2 , y 2 ) (x_1,y_1),(x_2,y_2) (x1,y1),(x2,y2)关于 ( 0 , 0 ) , ( x 3 , y 3 ) (0,0),(x_3,y_3) (0,0),(x3,y3)对称的必要条件为 ( x 1 , y 1 ) (x_1,y_1) (x1,y1) ( x 2 , y 2 ) (x_2,y_2) (x2,y2)在同一个以 ( 0 , 0 ) (0,0) (0,0)为圆心的圆上,即 x 1 2 + y 1 2 = x 2 2 + y 2 2 x_1^2+y_1^2=x_2^2+y_2^2 x12+y12=x22+y22

结论2: x 2 + y 2 = N        ( n ≤ 2 ∗ 11290 4 2 ) x^2+y^2=N\;\;\;(n\leq2*112904^2) x2+y2=N(n21129042)的解数 M M M小于等于 144 144 144

因此我们每次添加或删除点时,只会影响到在同一个圆上的点,而圆上最多有 144 144 144个整点,暴力枚举这些圆上的点分别更新对称轴的值即可。

时间复杂度 O ( M q ) O(Mq) O(Mq)

Code

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int num=0,cnt=0;
map<ll,int> Map;
map<PR,int> Ans;
set<PR> Set[MAXN];
int gcd(int x,int y) { return y==0?x:gcd(y,x%y); }
void add(int x,int y,int c)
{
	int g=gcd(x,y);
	x/=g,y/=g;
	Ans[MP(x,y)]+=c;
}
int query(int x,int y)
{
	int g=gcd(x,y);
	x/=g,y/=g;
	return Ans[MP(x,y)];
}
int main()
{
	int Case=read();
	while (Case--)
	{
		ll opt=read(),x=read(),y=read();
		if (opt==1)
		{
			ll z=x*x+y*y;
			if (!Map.count(z)) Map[z]=++cnt;
			z=Map[z];	
			for (auto V:Set[z]) add(V.fi+x,V.se+y,2);
			Set[z].insert(MP(x,y)),add(x,y,1),num++;
		}
		else if (opt==2)
		{
			ll z=x*x+y*y;
			if (!Map.count(z)) Map[z]=++cnt;
			z=Map[z];
			Set[z].erase(Set[z].find(MP(x,y))),add(x,y,-1),num--;
			for (auto V:Set[z]) add(V.fi+x,V.se+y,-2);
		}
		else printf("%d\n",num-query(x,y));
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值