Codeforces Round #243 (Div. 1)——Sereja and Squares

时间:2014-04-30 22:34:38   收藏:0   阅读:326

题目链接


const int MAXN = 100001;

vector<int> vt[MAXN];
bool match(int ind, int val)
{
	if (ind >= MAXN) return false;
	return binary_search(all(vt[ind]), val);
}

int main()
{
	//    freopen("in.txt", "r", stdin);
	int n, a, b, bound;
	while (~RI(n))
	{
		REP(i, MAXN) vt[i].clear();
		bound = (int)sqrt(n * 1.0);

		REP(i, n)
		{
			RII(a, b);
			vt[a].push_back(b);
		}
		REP(i, MAXN)
		{
			sort(all(vt[i]));
		}
		LL ans = 0;
		REP(i, MAXN)
		{
			if (vt[i].size() > bound)
			{
				FF(j, i + 1, MAXN)
				{
					int dis = j - i;
					REP(k, vt[j].size())
					{
						int val = vt[j][k];
						if (match(j, val + dis) && match(i, val) && match(i, val + dis))
							ans++;
					}
				}
			}
			else
			{
				REP(j, vt[i].size()) FF(k, j + 1, vt[i].size())
				{
					int dis = vt[i][k] - vt[i][j];
					if (match(i + dis, vt[i][k]) && match(i + dis, vt[i][j]))
						ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!