标签:acm
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; }
Codeforces Round #243 (Div. 1)——Sereja and Squares
标签:acm
原文地址:http://blog.csdn.net/wty__/article/details/24743347