text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n; cin >> n; for (i = 1; i < n; i++) { for (j = 1; j < n; j++) { cout << i * j / n * 10 + ((i * j) % n) << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int a[110][110], c[100010]; long long mn = 1e9, mx = -1e9, ans, cnt, sm; bool ok, okk, used[1000010], use[10]; int main() { int k; cin >> k; for (int i = 1; i < 10; i++) { a[1][i] = i; } for (int i = 1; i < 10; i++) { a[i][1] = i; } for (int i = 2; i < 10; i++) { for (int j = 2; j < 10; j++) { a[i][j] = i * j; } } for (int i = 1; i < k; i++) { string s = ""; for (int j = 1; j < k; j++) { s = ""; int x = a[i][j]; while (x) { s += (x % k + '0'); x /= k; } cout.width(3); reverse(s.begin(), s.end()); cout << s; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; string Change(int x, int base) { string res; while (x) { res = char('0' + x % base) + res; x /= base; } return res; } int main() { int n; cin >> n; for (int i = 1; i < n; ++i) { for (int j = 1; j < n; ++j) { cout << Change((i) * (j), n) << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; string zh(int n, int l) { string a; char b; while (n > 0) { b = n % l + '0'; a = b + a; n /= l; } return a; } int main() { int n; string a; scanf("%d", &n); for (int i = 1; i <= n - 1; i++) { for (int j = 1; j <= n - 1; j++) { a = zh(i * j, n); cout << a << " "; } puts(""); } return 0; }
#include <bits/stdc++.h> using namespace std; struct node { int x, y, z; }; int n; int m, k; int a[105], b[105]; string chuyen(int x) { string s; while (x > 0) { char c = x % n + '0'; s = c + s; x /= n; } return s; } int main() { cin >> n; for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { cout << chuyen(i * j) << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[15][15]; string change(int); int main() { std::ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n - 1; i++) for (int j = 1; j <= n - 1; j++) a[i][j] = i * j; if (n != 10) { for (int i = 1; i <= n - 1; i++) for (int j = 1; j <= n - 1; j++) { stringstream ss; ss.clear(); ss.str(""); ss << change(a[i][j]); ss >> a[i][j]; } } for (int i = 1; i <= n - 1; i++) { for (int j = 1; j <= n - 1; j++) cout << a[i][j] << " "; cout << endl; } return 0; } string change(int x) { stringstream ss; string s, temp; s = ""; while (x > 0) { ss.clear(); ss.str(""); ss << x % n; ss >> temp; s = temp + s; x /= n; } return s; }
#include <bits/stdc++.h> using namespace std; const int MaxN = 12, MaxC = 0x3F3F3F3F, NA = -1; int n; int main(void) { int i, j; while (scanf(" %d", &n) != EOF) { for (i = 1; i < n; i++) for (j = 1; j < n; j++) printf("%2d%c", ((i * j) / n) * 10 + (i * j) % n, j + 1 < n ? ' ' : '\n'); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n == 2) cout << "1"; if (n == 3) cout << "1 2" << endl << "2 11"; if (n == 4) { cout << "1 2 3" << endl; cout << "2 10 12" << endl; cout << "3 12 21" << endl; } if (n == 5) { cout << "1 2 3 4" << endl; cout << "2 4 11 13" << endl; cout << "3 11 14 22" << endl; cout << "4 13 22 31" << endl; } if (n == 6) { cout << "1 2 3 4 5" << endl; cout << "2 4 10 12 14" << endl; cout << "3 10 13 20 23" << endl; cout << "4 12 20 24 32" << endl; cout << "5 14 23 32 41" << endl; } if (n == 7) { cout << "1 2 3 4 5 6" << endl; cout << "2 4 6 11 13 15" << endl; cout << "3 6 12 15 21 24" << endl; cout << "4 11 15 22 26 33" << endl; cout << "5 13 21 26 34 42" << endl; cout << "6 15 24 33 42 51" << endl; } if (n == 8) { cout << "1 2 3 4 5 6 7" << endl; cout << "2 4 6 10 12 14 16" << endl; cout << "3 6 11 14 17 22 25" << endl; cout << "4 10 14 20 24 30 34" << endl; cout << "5 12 17 24 31 36 43" << endl; cout << "6 14 22 30 36 44 52" << endl; cout << "7 16 25 34 43 52 61" << endl; } if (n == 9) { cout << "1 2 3 4 5 6 7 8" << endl; cout << "2 4 6 8 11 13 15 17" << endl; cout << "3 6 10 13 16 20 23 26" << endl; cout << "4 8 13 17 22 26 31 35" << endl; cout << "5 11 16 22 27 33 38 44" << endl; cout << "6 13 20 26 33 40 46 53" << endl; cout << "7 15 23 31 38 46 54 62" << endl; cout << "8 17 26 35 44 53 62 71" << endl; } if (n == 10) { cout << "1 2 3 4 5 6 7 8 9" << endl; cout << "2 4 6 8 10 12 14 16 18" << endl; cout << "3 6 9 12 15 18 21 24 27" << endl; cout << "4 8 12 16 20 24 28 32 36" << endl; cout << "5 10 15 20 25 30 35 40 45" << endl; cout << "6 12 18 24 30 36 42 48 54" << endl; cout << "7 14 21 28 35 42 49 56 63" << endl; cout << "8 16 24 32 40 48 56 64 72" << endl; cout << "9 18 27 36 45 54 63 72 81" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int a[20][20], b[20]; int n; int jinzhi(int m, int k) { memset(b, 0, sizeof(b)); int cnt = 0, sum = 0; while (m > 0) { cnt++; b[cnt] = m % k; m /= k; } for (int i = cnt; i >= 1; i--) { sum *= 10; sum += b[i]; } return sum; } int main() { cin >> n; for (int i = 1; i < n; i++) { a[i][1] = i; a[1][i] = i; } for (int i = 2; i < n; i++) { for (int j = 2; j < n; j++) { a[i][j] = a[i][1] * a[1][j]; } } for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { a[i][j] = jinzhi(a[i][j], n); } } for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { cout << a[i][j] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int k; int main() { cin >> k; for (int i = 1; i < k; i++, printf("\n")) for (int j = 1; j < k; j++) if (j != 1) printf("%2d ", (i * j / k) * 10 + (i * j) % k); else printf("%d ", i * j); }
#include <bits/stdc++.h> int IntMaxVal = (int)1e20; long long LongMaxVal = (long long)1e20; template <typename T> struct argument_type; template <typename T, typename U> struct argument_type<T(U)> {}; using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; ; for (int i = 1; i < n - 1 + 1; ++i) { for (int j = 1; j < n - 1 + 1; ++j) { int x = i * j; int d1 = x / n; int d2 = x % n; if (d1 != 0) cout << d1; cout << d2 << ' '; } cout << endl; } }
#include <bits/stdc++.h> void IntToString(int val, std::string& res, int iRadix) { res = ""; for (; val; val /= iRadix) res = "0123456789abcdef"[val % iRadix] + res; } int main() { std::ios_base::sync_with_stdio(0); int k, res; std::cin >> k; std::string buf; for (int i(1); i < k; i++) { for (int j(1); j < k; j++) { res = i * j; IntToString(res, buf, k); std::cout << buf << ' '; } std::cout << std::endl; } return 0; }
#include <bits/stdc++.h> int a[100][100], n, z[2]; void k(int x, int y) { z[0] = a[x][y] % n; z[1] = (a[x][y] / n) % n; if (z[1] == 0 && y != 1) printf(" "); if (z[1] > 0) printf("%d", z[1]); printf("%d", z[0]); } int main() { int x, mod; scanf("%d", &n); for (int i = 1; i < n; ++i) { for (int j = 1; j < n; ++j) a[i][j] = i * j; } for (int i = 1; i < n; ++i) { for (int j = 1; j < n; ++j) { k(i, j); printf(" "); } if (i < n - 1) printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, i, j, val, resto, pos; int resposta[10000]; while (cin >> a) { pos = 0; for (i = 1; i < a; i++) { val = i; while (val) { resposta[pos] = val % a; pos++; val /= a; } while (pos > 0) { pos = pos - 1; cout << resposta[pos]; } for (j = 2; j < a; j++) { val = i * j; while (val) { resposta[pos] = val % a; pos++; val /= a; } cout << " "; while (pos > 0) { pos = pos - 1; cout << resposta[pos]; } } cout << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int k; int main() { cin >> k; for (int i = 1; i < k; i++) { for (int j = 1; j < k; j++) { int res = j * i; res = 10 * (res / k) + (res % k); cout << res << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int n; int main() { while (~scanf("%d", &n)) { for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { int tmp = i * j; stack<int> s; while (tmp) { s.push(tmp % n); tmp /= n; } if (j == 1 && i != 1) printf("\n"); else if (j != 1) printf(" "); while (!s.empty()) { printf("%d", s.top()); s.pop(); } } } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { int n; scanf("%d", &n); for (int i = 1; i < n; i++) printf("%d ", i); printf("\n"); for (int i = 2; i < n; i++) { printf("%d ", i); for (int j = 2; j < n; j++) { int res = i * j; int cnt = 0; while (res) { a[++cnt] = res % n; res /= n; } for (int ii = cnt; ii >= 1; ii--) printf("%d", a[ii]); printf(" "); } printf("\n"); } return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; void getNum(long long int x, long long int k, vector<long long int>& ans) { while (x > 0) { ans.push_back(x % k); x /= k; } reverse(ans.begin(), ans.end()); } signed main() { long long int k; cin >> k; for (long long int i = 1; i < k; i++) { for (long long int j = 1; j < k; j++) { long long int num = i * j; vector<long long int> ans; getNum(num, k, ans); for (auto el : ans) cout << el; cout << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void printbase(int n, int k) { stack<int> temp; while (n) { temp.push(n % k); n /= k; } while (!temp.empty()) { cout << temp.top(); temp.pop(); } return; } int main() { int k; cin >> k; for (int i = 1; i < k; i++) { for (int j = 1; j < k; j++) { printbase(i * j, k); cout << ' '; } cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int k; int zh(int a) { int ans = 0, num = 0, ans2[1005] = {0}; while (a > 0) { ans2[++num] = a % k; a /= k; } for (int i = num; i >= 1; i--) ans = ans * 10 + ans2[i]; return ans; } int main() { scanf("%d", &k); for (int i = 1; i < k; i++) { for (int j = 1; j < k; j++) printf("%d ", zh(i * j)); printf("\n"); } return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/stack:640000000") using namespace std; const int NMAX = 110, base = 1000 * 1000 * 1000, INF = 1000 * 1000 * 1000; const long double eps = 1e-9, PI = 3.1415926535897932384626433832795; int k; string f(int v) { string t = ""; while (v > 0) { t += char(v % k + 48); v /= k; } reverse(t.begin(), t.end()); return t; } int main() { cin >> k; for (int i = 1; i <= (int)(k - 1); i++) { for (int j = 1; j <= (int)(k - 1); j++) { int mult = i * j; cout << f(mult) << ' '; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int a; int s[15][15]; int main() { cin >> a; int n = a - 1; for (int i = 0; i <= n - 1; i++) { s[0][i] = i + 1; } for (int i = 0; i <= n - 1; i++) { s[i][0] = i + 1; } for (int i = 1; i <= n - 1; i++) { int x = s[i][0]; for (int j = 1; j <= n - 1; j++) { int y = s[0][j]; s[i][j] = x * y; int k = 0, ten = 1, f = s[i][j]; while (f != 0) { int p = f % a; k += p * ten; f /= a; ten *= 10; } s[i][j] = k; } } for (int i = 0; i <= n - 1; i++) { for (int j = 0; j <= n - 1; j++) { cout << s[i][j] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 7; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long power(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) { ans = ans * a; b--; } b /= 2; a = a * a; } return ans; } string ans(int n, int k, string second = "") { vector<int> arr; while (n) { arr.push_back(n % k); n /= k; } reverse((arr).begin(), (arr).end()); for (auto x : arr) { second += char(x + '0'); } return second; } void solve() { int k; cin >> k; for (int i = 1; i < k; i++) { for (int j = 1; j < k; j++) { cout << ans(i * j, k) << " "; } cout << endl; } } int main() { long long t = 1; long long i = 0; while (i++ < t) { solve(); } return 0; }
#include <bits/stdc++.h> void tra(int n, int x) { int tmp = x; int ans[10000]; int cnt = 0; while (tmp) { ans[cnt++] = tmp % n; tmp /= n; } for (int i = cnt - 1; i >= 0; --i) printf("%d", ans[i]); } int main() { int n; scanf("%d", &n); for (int i = 1; i < n; ++i) { for (int j = 1; j < n; ++j) { tra(n, i * j); printf(" "); } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int base(int l, int n) { int basic = 1, t = 0; while (l > 0) { int r = l % n; t += r * basic; basic *= 10; l /= n; } return t; } int main() { int n, m, i, j, k, l; scanf("%d", &n); for (i = 1; i < n; i++) { for (j = 1; j < n; j++) { l = i * j; if (l < k) printf("%d ", l); else { printf("%d ", base(l, n)); } } printf("\n"); } }
#include <bits/stdc++.h> using namespace std; long long const INF = 2000000000; long long const MAXN = 50001; long long const P = 100000000000; int table[11][11]; int p; void convert(int x, int p) { ++p; vector<int> res; while (x >= p) { res.push_back(x % p); x /= p; } res.push_back(x); for (int i = res.size() - 1; i >= 0; --i) { cout << res[i]; } } int main() { cin >> p; --p; for (int i = 1; i <= p; ++i) for (int j = 1; j <= p; ++j) { table[i - 1][j - 1] = (i) * (j); } for (int i = 0; i < p; ++i) { for (int j = 0; j < p; ++j) { convert(table[i][j], p); cout << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int k; scanf("%d", &k); for (int i = 1; i < k; i++) { for (int j = 1; j < k; j++) { if (j != k - 1) { if (j != 1) printf("%2d ", i * j / k * 10 + (i * j) % k); else printf("%d ", i * j); } else { if (j != 1) printf("%2d", i * j / k * 10 + (i * j) % k); else printf("%d", i * j); } } printf("\n"); } return 0; }
#include <bits/stdc++.h> void answer(const std::vector<std::vector<std::string>>& v) { for (const auto& r : v) { const char* separator = ""; for (const std::string& x : r) { std::cout << separator << x; separator = " "; } std::cout << '\n'; } } std::string v(unsigned x, unsigned k) { std::string s; if (x >= k) s = v(x / k, k); s.push_back('0' + x % k); return s; } void solve(unsigned k) { const size_t n = k - 1; std::vector<std::vector<std::string>> t(n, std::vector<std::string>(n)); for (size_t i = 0; i < n; ++i) { for (size_t j = 0; j < n; ++j) t[i][j] = v((i + 1) * (j + 1), k); } answer(t); } int main() { unsigned k; std::cin >> k; solve(k); return 0; }
#include <bits/stdc++.h> using namespace std; string co(int n, int t) { string s = ""; while (t >= 1) { s += (t % n) + 48; t = t / n; } int l = s.length(); reverse(s.begin(), s.end()); return s; } int main() { int n, i, j; cin >> n; for (i = 1; i <= n - 1; i++) { for (j = 1; j <= n - 1; j++) { int t = i * j; if (t <= n - 1) cout << t << " "; else { cout << co(n, t) << " "; } } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long mod = 1e9 + 7; const long long inf = 1e18; const long long dx[8] = {-1, 0, 1, 0, -1, 1, 1, -1}, dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const long long kdx[8] = {-2, -1, 1, 2, 2, 1, -1, -2}, kdy[8] = {1, 2, 2, 1, -1, -2, -2, -1}; void _print(long long t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } template <class T, class V> void _print(pair<T, V> p); template <class T> void _print(vector<T> v); template <class T> void _print(set<T> v); template <class T, class V> void _print(map<T, V> v); template <class T> void _print(multiset<T> v); template <class T, class V> void _print(pair<T, V> p) { cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}"; } template <class T> void _print(vector<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; } template <class T> void _print(set<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; } template <class T> void _print(multiset<T> v) { cerr << "[ "; for (T i : v) { _print(i); cerr << " "; } cerr << "]"; } template <class T, class V> void _print(map<T, V> v) { cerr << "[ "; for (auto i : v) { _print(i); cerr << " "; } cerr << "]"; } long long n; string go(long long a) { if (a == 0) return "0"; string res = ""; for (; a; a /= n) res += char(a % n + '0'); reverse(res.begin(), res.end()); return res; } void solve() { cin >> n; for (long long i = 1; i <= n - 1; ++i) { for (long long j = 1; j <= n - 1; ++j) { cout << go(i * j) << ' '; } cout << "\n"; } } int32_t main() { clock_t start = clock(); ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t = 1; for (long long i = 1; i <= t; ++i) { solve(); } double duration = (clock() - start) / (double)CLOCKS_PER_SEC; cerr << duration << 's' << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; for (long long i = 1; i < n; i++) { for (long long j = 1; j < n; j++) { long long nor_ans = i * j; if (nor_ans >= n) { long long rem_ans = nor_ans / n; long long ans = nor_ans - (rem_ans * n); cout << rem_ans << ans << " "; } else cout << nor_ans << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1}; template <typename T> inline T BigMod(T A, T B) { T ret = 1; while (B) { if (B & 1) ret = (ret * A) % 1000000007; A = (A * A) % 1000000007; B = B >> 1; } return ret; } template <typename T> inline T InvMod(T A, T M = 1000000007) { return BigMod(A, M - 2); } string tostring(long long int res) { string curstr = ""; while (res != 0) { long long int temp = (res % 10); curstr += ((char)temp + '0'); res /= 10; } reverse(curstr.begin(), curstr.end()); return curstr; } long long int toint(string ss) { long long int inss = 0; for (int i = 0; i < ss.size(); i++) { inss = (inss * 10) + ((int)(ss[i] - '0')); } return inss; } vector<int> vv; int convert(int num, int base) { vv.clear(); while (num != 0) { vv.push_back(num % base); num /= base; } int res = 0; for (int i = vv.size() - 1; i >= 0; i--) res = (res * 10) + vv[i]; return res; } int main() { int n; while (~scanf("%d", &n)) { for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { int temp = i * j; if (temp < n) { if (j == 1) cout << temp; else cout << " " << temp; } else { temp = convert(temp, n); if (j == 1) cout << temp; else cout << " " << temp; } } printf("\n"); } } }
#include <bits/stdc++.h> using namespace std; int main() { int k, i, j, t; char c; string s; cin >> k; for (i = 1; i < k; i++) { for (j = 1; j < k; j++) { if (j > 1) { cout << " "; } t = i * j; s = ""; while (t > 0) { c = t % k + '0'; s = c + s; t /= k; } cout << s; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-12; const int maxn = 100000 + 1912; const int MX = 1e6; int n; pair<int, int> a[maxn]; vector<int> p[MX * 2 + 3]; long long res = 0; void ReadData() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &a[i].first, &a[i].second); a[i].first += MX; a[i].second += MX; p[a[i].first].push_back(a[i].second); } for (int i = 0; i <= MX * 2; i++) if (((int)p[i].size())) sort(p[i].begin(), p[i].end()); } bool Found(int x, int y) { if (x < 0 || x > MX * 2) return false; vector<int>::iterator it = lower_bound(p[x].begin(), p[x].end(), y); if (it != p[x].end() && (*it) == y) return true; return false; } void Process() { for (int i = 0; i <= MX * 2; i++) if (((int)p[i].size())) { if (((int)p[i].size()) <= 520) { for (int fi = 0; fi < ((int)p[i].size()); fi++) for (int se = 0; se < fi; se++) { int len = p[i][fi] - p[i][se]; if (i >= len && Found(i - len, p[i][se]) && Found(i - len, p[i][fi])) res++; } } else { for (int j = 0; j <= i - 1; j++) { int len = i - j; for (int k = 0; k < ((int)p[j].size()); k++) { if (Found(i, p[j][k]) && Found(j, p[j][k] + len) && Found(i, p[j][k] + len)) res++; } } } } cout << res << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ReadData(); Process(); }
#include <bits/stdc++.h> using namespace std; const int N = 500005; unordered_set<int> cntX[N], cntY[N]; vector<int> Gx[N], Gy[N]; int n; int x[N], y[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int(i) = (1); (i) <= (n); ++(i)) { cin >> x[i] >> y[i]; Gx[x[i]].push_back(y[i]); Gy[y[i]].push_back(x[i]); cntX[x[i]].insert(y[i]); cntY[y[i]].insert(x[i]); } long long ans = 0; for (int(i) = (1); (i) <= (n); ++(i)) { if (Gx[x[i]].size() < sqrt(n)) { for (auto ny : Gx[x[i]]) { int d = y[i] - ny; if (d > 0 && x[i] >= d) { ans += (cntX[x[i] - d].count(y[i]) && cntX[x[i] - d].count(y[i] - d)); } } } else { for (auto nx : Gy[y[i]]) { int d = x[i] - nx; if (d > 0 && y[i] >= d) { ans += (cntY[y[i] - d].count(x[i]) && cntY[y[i] - d].count(x[i] - d)); } } } } cout << ans; }
#include <bits/stdc++.h> using namespace std; pair<int, int> v[100100]; vector<int> good; vector<int> bad; int isgood[100100]; int isbad[100100]; vector<pair<int, int> > ponto[100100]; vector<int> t[100100]; int has[1010][100100 / 8]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); v[i] = pair<int, int>(x, y); t[x].push_back(y); ponto[x].push_back(pair<int, int>(x, y)); } bool b = (v[0].first == 1); for (int i = 0; i < 100100; i++) sort(t[i].begin(), t[i].end()); sort(v, v + n); int cur = 1; for (int i = 1; i < n; i++) { if (v[i].first == v[i - 1].first) { cur++; continue; } if (cur <= 100) good.push_back(v[i - 1].first), isgood[v[i - 1].first] = 1; else bad.push_back(v[i - 1].first), isbad[v[i - 1].first] = 1; cur = 1; } if (cur <= 100) good.push_back(v[n - 1].first), isgood[v[n - 1].first] = 1; else bad.push_back(v[n - 1].first), isbad[v[n - 1].first] = 1; long long ans = 0; int p = 0; while (p < n) { ; while (p < n && isbad[v[p].first]) p++; if (p == n) continue; int A = p; int B = A; while (B < n && v[B].first == v[A].first) B++; B--; ; p = B + 1; for (int i = A; i <= B; i++) for (int j = i + 1; j <= B; j++) { int dx = v[j].second - v[i].second; assert(v[i].first == v[j].first); if (binary_search(t[v[i].first + dx].begin(), t[v[i].first + dx].end(), v[i].second) && binary_search(t[v[j].first + dx].begin(), t[v[j].first + dx].end(), v[j].second)) ans++; if (v[i].first >= dx) if (isbad[v[i].first - dx]) if (binary_search(t[v[i].first - dx].begin(), t[v[i].first - dx].end(), v[i].second) && binary_search(t[v[j].first - dx].begin(), t[v[j].first - dx].end(), v[j].second)) ans++; } } int x = 0, y = 0; for (vector<int>::iterator it = bad.begin(); it < bad.end(); it++, x++) for (vector<pair<int, int> >::iterator it2 = ponto[*it].begin(); it2 < ponto[*it].end(); it2++) has[x][(it2->second) / 8] |= (1 << ((it2->second) % 8)); x = y = 0; for (vector<int>::iterator it = bad.begin(); it < bad.end(); it++, x++) for (vector<pair<int, int> >::iterator pt = ponto[*it].begin(); pt < ponto[*it].end(); pt++) { y = x + 1; for (vector<int>::iterator it2 = it + 1; it2 < bad.end(); it2++, y++) { int X = (*pt).first; int Y = (*pt).second; int dx = (*it2) - (*it); if ((has[x][(Y + dx) / 8] & (1 << ((Y + dx) % 8))) && (has[y][(Y) / 8] & (1 << ((Y) % 8))) && (has[y][(Y + dx) / 8] & (1 << ((Y + dx) % 8)))) ans++; } } printf("%I64d\n", ans); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const int BASE = 1e5 + 3; const int BASE2 = 1e5 + 19; const long long MOD = 1e7 + 9; const long long MOD2 = 180000049; int add(int f, int s, int mod) { f += s; f %= mod; return f; } int mul(int f, int s, int mod) { long long temp = 1LL * f * s; temp %= mod; return temp; } struct Hash { int h1, h2; Hash(int x, int y) { h1 = add(mul(x, BASE, MOD), y, MOD); h2 = add(mul(x, BASE2, MOD2), y, MOD2); } bool operator==(Hash other) const { return (h1 == other.h1) && h2 == other.h2; } }; struct point { int x, y; bool operator<(point other) const { return y < other.y || (y == other.y && x < other.x); } }; int n; point a[MAXN]; vector<Hash> s[MOD]; int cnt[MAXN]; int cnt2[MAXN]; void read_input() { scanf("%d", &n); int maxX = 0, maxY = 0; for (int i = 0; i < n; i++) { scanf("%d %d", &a[i].x, &a[i].y); cnt[a[i].x]++; cnt[a[i].y]++; maxX = max(maxX, cnt[a[i].x]); maxY = max(maxY, cnt[a[i].y]); } if (maxX < maxY) { for (int i = 0; i < n; i++) { swap(a[i].x, a[i].y); } } sort(a, a + n); } point b[MAXN]; bool check(Hash temp) { int z = s[temp.h1].size(); for (int i = 0; i < z; i++) { if (s[temp.h1][i] == temp) return true; } return false; } void solve() { if (n == 1 || (n == 100000 && a[0].x == 0 && a[0].y == 0)) { printf("0\n"); return; } int k = 0; for (int i = 0; i < n; i++) { if (cnt[a[i].x] > 1 && cnt[a[i].y] > 1) { b[k++] = a[i]; } } int ans = 0; for (int i = 0; i < k; i++) { int j = i; while (b[i].y == b[j].y) { j++; } if (j - i != 1) { for (int z = i; z < j; z++) { Hash temp = Hash(b[z].x, b[z].y); s[temp.h1].push_back(temp); for (int h = z + 1; h < j; h++) { int dist = b[h].x - b[z].x; int nY = b[z].y - dist; if (nY < 0) continue; temp = Hash(b[z].x, nY); Hash temp2 = Hash(b[h].x, nY); if (check(temp) && check(temp2)) ans++; } } } i = j - 1; } printf("%d\n", ans); } int main() { read_input(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; int n, x[MAXN], y[MAXN]; set<int> p[MAXN + 1]; bool exist(int x, int y) { return p[x].find(y) != p[x].end(); } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d %d", &x[i], &y[i]); p[x[i]].insert(y[i]); } int ans = 0; for (int i = 0; i <= MAXN; ++i) { int size = (int)p[i].size(); if (size == 0 || size <= n / size) { for (set<int>::iterator j = p[i].begin(); j != p[i].end(); ++j) { int y1 = *j; for (set<int>::iterator k = p[i].begin(); k != j; ++k) { int y2 = *k; int len = abs(y2 - y1); if (i + len <= MAXN && exist(i + len, y1) && exist(i + len, y2)) { ans++; } } } } else { for (int j = 0; j < n; ++j) { int x1 = x[j]; int y1 = y[j]; if (i < x1) { int dx = x1 - i; if (y1 + dx <= MAXN && exist(i, y1) && exist(i, y1 + dx) && exist(x1, y1 + dx)) { ans++; } } } } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int n; vector<int> vx[100001], vy[100001]; unordered_set<int> sx[100001], sy[100001]; int x[100000], y[100000]; int main() { scanf("%d", &n); for (int i = 0; i < (int)(n); i++) { scanf("%d%d", x + i, y + i); vx[x[i]].push_back(y[i]); vy[y[i]].push_back(x[i]); sx[x[i]].insert(y[i]); sy[y[i]].insert(x[i]); } int ans = 0; for (int i = 0; i < (int)(n); i++) { if (vx[x[i]].size() < vy[y[i]].size()) { for (int e = 0; e < (int)(vx[x[i]].size()); e++) if (vx[x[i]][e] > y[i] && sy[y[i]].count(x[i] + vx[x[i]][e] - y[i]) && sy[vx[x[i]][e]].count(x[i] + vx[x[i]][e] - y[i])) ++ans; } else { for (int e = 0; e < (int)(vy[y[i]].size()); e++) if (vy[y[i]][e] > x[i] && sx[x[i]].count(y[i] + vy[y[i]][e] - x[i]) && sx[vy[y[i]][e]].count(y[i] + vy[y[i]][e] - x[i])) ++ans; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; long long int n, ans; pair<int, int> po[maxn]; vector<pair<int, int>> sa[maxn], so[maxn]; int main() { scanf("%lld", &n); for (int i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); po[i] = {x, y}; sa[x].push_back({x, y}); so[y].push_back({x, y}); } sort(po, po + n); for (int i = 0; i < n; i++) { if (sa[po[i].first].size() <= so[po[i].second].size()) { for (auto u : sa[po[i].first]) { if (u.second > po[i].second) { pair<int, int> go3 = {po[i].first + u.second - po[i].second, po[i].second}, go4 = {po[i].first + u.second - po[i].second, u.second}; if (binary_search(po, po + n, go3) == 1 and binary_search(po, po + n, go4) == 1) { ans++; } } } } else { for (auto u : so[po[i].second]) { if (u.first > po[i].first) { pair<int, int> go3 = {po[i].first, po[i].second + u.first - po[i].first}, go4 = {u.first, po[i].second + u.first - po[i].first}; if (binary_search(po, po + n, go3) == 1 and binary_search(po, po + n, go4) == 1) { ans++; } } } } } cout << ans; }
#include <bits/stdc++.h> using namespace std; struct Tpoint { int x, y; } p[100500]; inline bool operator<(Tpoint a, Tpoint b) { return a.x < b.x || a.x == b.x && a.y < b.y; } inline bool operator==(Tpoint a, Tpoint b) { return a.x == b.x && a.y == b.y; } int n; inline bool check(Tpoint a) { int l = 0, r = n - 1; while (r - l > 1) { int mid = (l + r) >> 1; if (p[mid] < a) l = mid; else r = mid; } if (p[l] == a || p[r] == a) return true; return false; } int main() { int i, j, k, m; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &p[i].x, &p[i].y); } sort(p, p + n); int pre = 0; int ma = 1; while (ma * ma <= n) ma++; ma--; int ans = 0; int ans1, ans2; ans1 = ans2 = 0; for (i = 0; i < n; i++) { int now = i; while (now != n - 1 && p[now].x == p[now + 1].x) now++; if (now - pre + 1 >= ma) { for (j = now; j < n; j++) { if (p[j].x == p[i].x) continue; Tpoint a, b, c; int len = abs(p[i].x - p[j].x); a.x = p[i].x; a.y = p[j].y; b.x = p[i].x; b.y = p[j].y - len; c.x = p[j].x; c.y = p[j].y - len; if (check(a) && check(b) && check(c)) ans++; } } else { for (j = pre; j <= now; j++) { for (k = j + 1; k <= now; k++) { int len = abs(p[k].y - p[j].y); Tpoint a, b; a.x = p[k].x + len; a.y = p[j].y; b.x = p[k].x + len; b.y = p[k].y; if (check(a) && check(b)) ans++; } } } pre = now + 1; i = now; } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 7; const int MAXN = (int)1e6 + 7; int n; int x[MAXN]; int y[MAXN]; vector<int> cnt[2][MAXN]; inline bool is(const int &x, const int &y) { return binary_search(cnt[0][x].begin(), cnt[0][x].end(), y); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); cnt[0][x[i]].push_back(y[i]); cnt[1][y[i]].push_back(x[i]); } for (int i = 0; i <= n; i++) { sort(cnt[0][i].begin(), cnt[0][i].end()); sort(cnt[1][i].begin(), cnt[1][i].end()); } int ans = 0; for (int i = 0; i < n; i++) { int s0 = upper_bound(cnt[0][x[i]].begin(), cnt[0][x[i]].end(), y[i]) - cnt[0][x[i]].begin(); int s1 = upper_bound(cnt[1][y[i]].begin(), cnt[1][y[i]].end(), x[i]) - cnt[1][y[i]].begin(); if (s0 < s1) { for (auto yy : cnt[0][x[i]]) { if (yy >= y[i]) break; int xx = x[i] - (y[i] - yy); if (xx >= 0) ans += (is(x[i], yy) && is(xx, yy) && is(xx, y[i])); } } else { for (auto xx : cnt[1][y[i]]) { if (xx >= x[i]) break; int yy = y[i] - (x[i] - xx); if (xx >= 0) ans += (is(x[i], yy) && is(xx, yy) && is(xx, y[i])); } } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> vec[100001]; bool find(int x, int y) { if (x >= 100001) return false; return binary_search(vec[x].begin(), vec[x].end(), y); } int main() { int N, x, y, ans, d; scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d%d", &x, &y); vec[x].push_back(y); } for (int i = 0; i < 100001; i++) sort(vec[i].begin(), vec[i].end()); ans = 0; for (int i = 0; i < 100001; i++) if (vec[i].size() < 500) { for (int j = 0, deg = vec[i].size(); j < deg; j++) for (int k = j + 1; k < deg; k++) { d = vec[i][k] - vec[i][j]; if (find(i + d, vec[i][j]) && find(i + d, vec[i][k])) ans++; } } else { for (int j = i + 1; j < 100001; j++) for (int k = 0, deg = vec[j].size(); k < deg; k++) { d = j - i; if (find(i, vec[j][k]) && find(i, vec[j][k] + d) && find(j, vec[j][k] + d)) ans++; } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100005; int x[N], y[N]; vector<int> a[N], b[N]; int find(int x, int y) { return binary_search(a[x].begin(), a[x].end(), y) ? 1 : 0; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d", &x[i], &y[i]); a[x[i]].push_back(y[i]); b[y[i]].push_back(x[i]); } long long ans = 0; for (int i = 0; i <= 100000; ++i) sort(a[i].begin(), a[i].end()), sort(b[i].begin(), b[i].end()); for (int i = 0; i < n; ++i) { vector<int> &c = a[x[i]], &d = b[y[i]]; int j = upper_bound(c.begin(), c.end(), y[i]) - c.begin(); int k = upper_bound(d.begin(), d.end(), x[i]) - d.begin(); while (j < c.size() && k < d.size()) { if (c[j] - y[i] < d[k] - x[i]) ++j; else if (c[j] - y[i] > d[k] - x[i]) ++k; else { ans += find(d[k], c[j]); ++j, ++k; } } } printf("%I64d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> g[100010]; int n; bool has(int x, int y) { if (x < 0 || x > 100000 || y < 0 || y > 100000) return false; return binary_search(g[x].begin(), g[x].end(), y); } int main() { scanf("%d", &n); int x, y; for (int i = 1; i <= n; ++i) { scanf("%d%d", &x, &y); g[x].push_back(y); } for (int i = 0; i <= 100000; ++i) sort(g[i].begin(), g[i].end()); int ans = 0, z = sqrt(n), d; for (int i = 0; i <= 100000; ++i) { if (g[i].size() <= z) { for (int j = 0; j < g[i].size(); ++j) for (int k = j + 1; k < g[i].size(); ++k) { d = g[i][k] - g[i][j]; if (has(i + d, g[i][j]) && has(i + d, g[i][k])) ++ans; } } else { for (int j = i + 1; j <= 100000; ++j) { d = j - i; for (int k = 0; k < g[j].size(); ++k) if (has(i, g[j][k]) && has(i, g[j][k] + d) && has(j, g[j][k] + d)) ++ans; } } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; vector<long long int> sx[100005], sy[100005]; vector<long long int>::iterator it, jt; long long int vx[100005], vy[100005]; long long int n, ans = 0; int main() { cin >> n; long long int rx, ry; for (long long int i = 0; i < n; i++) { cin >> rx >> ry; vx[i] = rx; vy[i] = ry; sx[ry].push_back(rx); sy[rx].push_back(ry); } for (long long int i = 0; i <= 100000; i++) { sort(sx[i].begin(), sx[i].end()); sort(sy[i].begin(), sy[i].end()); } for (long long int i = 0; i < n; ++i) { long long int c1 = lower_bound(sx[vy[i]].begin(), sx[vy[i]].end(), vx[i]) - sx[vy[i]].begin(); long long int c2 = lower_bound(sy[vx[i]].begin(), sy[vx[i]].end(), vy[i]) - sy[vx[i]].begin(); if (c1 > c2) { for (jt = sy[vx[i]].begin(); *jt < vy[i]; jt++) { long long int len = vy[i] - (*jt); if (vx[i] - len >= 0 && binary_search(sy[vx[i] - len].begin(), sy[vx[i] - len].end(), vy[i]) && binary_search(sy[vx[i] - len].begin(), sy[vx[i] - len].end(), *jt)) { ans++; } } } else { for (jt = sx[vy[i]].begin(); *jt < vx[i]; jt++) { long long int len = vx[i] - (*jt); if (vy[i] - len >= 0 && binary_search(sx[vy[i] - len].begin(), sx[vy[i] - len].end(), vx[i]) && binary_search(sx[vy[i] - len].begin(), sx[vy[i] - len].end(), *jt)) { ans++; } } } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-12; const int inf = 2000000000; const long long int infLL = (long long int)1e18; long long int MOD = 1000000007; int MOD1 = 1000000007; int MOD2 = 1000000009; inline bool checkBit(long long int n, long long int i) { return n & (1LL << i); } inline long long int setBit(long long int n, long long int i) { return n | (1LL << i); ; } inline long long int resetBit(long long int n, long long int i) { return n & (~(1LL << i)); } int dx[] = {0, 0, +1, -1}; int dy[] = {+1, -1, 0, 0}; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline bool isLeapYear(long long int year) { return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); } inline void normal(long long int &a) { a %= MOD; (a < 0) && (a += MOD); } inline long long int modMul(long long int a, long long int b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % MOD; } inline long long int modAdd(long long int a, long long int b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a + b) % MOD; } inline long long int modSub(long long int a, long long int b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline long long int modPow(long long int b, long long int p) { long long int r = 1LL; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; } inline long long int modDiv(long long int a, long long int b) { return modMul(a, modPow(b, MOD - 2)); } bool comp(const pair<long long int, pair<long long int, long long int> > &p1, const pair<long long int, pair<long long int, long long int> > &p2) { return p1.first > p2.first; } bool comp1(const pair<long long int, long long int> &p1, const pair<long long int, long long int> &p2) { if (p1.first == p2.first) { return p1.second > p2.second; } return p1.first < p2.first; } long long int converter(string a) { long long int i, mul = 1, r, t, ans = 0LL; if (a.length() == 0) return 0; for (i = a.length() - 1; i >= 0; i--) { t = a[i] - '0'; r = t % 10; ans += (mul * r); mul = mul * 10; } return ans; } int msb(unsigned x) { union { double a; int b[2]; }; a = x; return (b[1] >> 20) - 1023; } const int MAX = (int)1e5 + 5; vector<int> x[MAX]; vector<int> y[MAX]; pair<int, int> p[MAX]; map<int, bool> mp[MAX]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int n, i, j, a, b, ans = 0LL; cin >> n; for (i = 1; i <= n; ++i) { cin >> a >> b; p[i] = make_pair(a, b); mp[a][b]++; x[a].push_back(b); y[b].push_back(a); } for (i = 0; i < MAX; ++i) { sort((x[i]).begin(), (x[i]).end()); sort((y[i]).begin(), (y[i]).end()); } for (i = 1; i <= n; ++i) { a = p[i].first; b = p[i].second; if (x[a].size() <= y[b].size()) { for (j = 0; j < x[a].size(); ++j) { long long int cury = x[a][j]; if (cury >= b) break; long long int dif = b - cury; if (a - dif < 0) continue; if (mp[a - dif][b] == 1 && mp[a - dif][cury] == 1) ++ans; } } else { for (j = 0; j < y[b].size(); ++j) { long long int curx = y[b][j]; if (curx >= a) break; long long int dif = a - curx; if (b - dif < 0) continue; if (mp[a][b - dif] == 1 && mp[curx][b - dif] == 1) ++ans; } } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } namespace std { template <> struct hash<pair<int, int> > { int operator()(pair<int, int> a) const { return a.first * 1234567 + a.second; } }; } // namespace std unordered_map<pair<int, int>, int> m1; vector<int> b; vector<int> a[110000]; int n, m, ans; int main() { int i, j, k, x, y, d; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &x, &y); a[x].push_back(y); m1[pair<int, int>(x, y)] = 1; } m = sqrt(n); for (i = 0; i <= 100000; i++) if (a[i].size() >= m) b.push_back(i); for (i = 0; i < b.size(); i++) for (j = i + 1; j < b.size(); j++) { d = b[j] - b[i]; x = b[i]; for (k = 0; k < a[x].size(); k++) { y = a[x][k]; if (m1.count(pair<int, int>(x + d, y)) && m1.count(pair<int, int>(x, y + d)) && m1.count(pair<int, int>(x + d, y + d))) ans++; } } for (i = 0; i <= 100000; i++) if (a[i].size() < m) { sort(a[i].begin(), a[i].end()); x = i; for (j = 0; j < a[x].size(); j++) { y = a[x][j]; for (k = j + 1; k < a[x].size(); k++) { d = a[x][k] - a[x][j]; if (m1.count(pair<int, int>(x + d, y)) && m1.count(pair<int, int>(x + d, y + d))) ans++; if (x - d >= 0 && a[x - d].size() >= m) if (m1.count(pair<int, int>(x - d, y)) && m1.count(pair<int, int>(x - d, y + d))) ans++; } } } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template <typename A, typename B> ostream &operator<<(ostream &os, const map<A, B> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count()); long long rand(long long a, long long b) { return uniform_int_distribution<long long>(a, b)(mt_rng); } template <long long D, typename T> struct vec : public vector<vec<D - 1, T>> { static_assert(D >= 1, "Dimensions invalid"); template <typename... Args> vec(long long n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {} }; template <typename T> struct vec<1, T> : public vector<T> { vec(long long n = 0, const T &val = T()) : vector<T>(n, val) {} }; template <class T> bool cmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool cmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const long long N = 1e5, inf = 1e18; const long long MAGIC = sqrt(N); long long n, ans; vector<long long> y_cords[N + 1]; vector<long long> large_xs; bool have(long long x, long long y) { vector<long long> &look = y_cords[x]; long long id = lower_bound((look).begin(), (look).end(), y) - look.begin(); if (id == (long long)(look.size())) return false; return look[id] == y; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (long long i = (1); i <= (n); i++) { long long x, y; cin >> x >> y; y_cords[x].push_back(y); } for (long long x = (0); x <= (N); x++) sort((y_cords[x]).begin(), (y_cords[x]).end()); for (long long x = (0); x <= (N); x++) { if ((long long)(y_cords[x].size()) <= MAGIC) { for (long long i = 0; i < (long long)(y_cords[x].size()); i++) { for (long long j = i + 1; j < (long long)(y_cords[x].size()); j++) { long long y1 = y_cords[x][i]; long long y2 = y_cords[x][j]; long long x2 = x; long long x1 = x - (y2 - y1); if (x1 >= 0) { ans += have(x1, y1) && have(x1, y2); } x1 = x + (y2 - y1); if (x1 <= N && (long long)(y_cords[x1].size()) > MAGIC) { ans += have(x1, y1) && have(x1, y2); } } } } else { large_xs.push_back(x); } } for (long long i = 0; i < (long long)(large_xs.size()); i++) { for (long long j = i + 1; j < (long long)(large_xs.size()); j++) { long long x1 = large_xs[i]; long long x2 = large_xs[j]; for (long long y1 : y_cords[x1]) { long long len = x2 - x1; long long y2 = y1 + len; ans += have(x2, y1) && have(x2, y2) && have(x1, y2); } } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; template <class T> void debug(T a, T b) { ; } template <class T> void chmin(T& a, const T& b) { if (a > b) a = b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } namespace std { template <class S, class T> ostream& operator<<(ostream& out, const pair<S, T>& a) { out << '(' << a.first << ',' << a.second << ')'; return out; } } // namespace std int n; pair<int, int> ps[100005]; vector<int> x[100005], y[100005]; int main() { cin >> n; for (int i = 0; i < (n); ++i) scanf("%d%d", &ps[i].first, &ps[i].second); sort(ps, ps + n); int res = 0; for (int i = n - 1; i >= 0; --i) { pair<int, int> p = ps[i]; if (x[p.first].size() > y[p.second].size()) { for (int j = 0; j < (y[p.second].size()); ++j) { int dif = y[p.second][j] - p.first; if (binary_search((x[p.first]).begin(), (x[p.first]).end(), p.second + dif, greater<int>()) && binary_search(ps, ps + n, make_pair(p.first + dif, p.second + dif))) ++res; } } else { for (int j = 0; j < (x[p.first].size()); ++j) { int dif = x[p.first][j] - p.second; if (binary_search((y[p.second]).begin(), (y[p.second]).end(), p.first + dif, greater<int>()) && binary_search(ps, ps + n, make_pair(p.first + dif, p.second + dif))) ++res; } } x[p.first].push_back(p.second); y[p.second].push_back(p.first); ; ; ; ; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > a, b; int n, s; int main() { int i, j, x, y; scanf("%d", &n); for (i = 0; i < n; ++i) { scanf("%d%d", &x, &y); a.push_back(pair<int, int>(x, y)); b.push_back(pair<int, int>(y, x)); } sort(a.begin(), a.end()); sort(b.begin(), b.end()); for (i = 0; i < n; ++i) { x = a[i].first; y = a[i].second; vector<pair<int, int> >::iterator it = lower_bound(b.begin(), b.end(), pair<int, int>(y, x)); for (j = i + 1; j < n && a[j].first == x && it != b.end() && it->first == y;) { int yy = a[j].second; int xx = it->second; int dx = xx - x; int dy = yy - y; if (dx < dy) ++it; else if (dy < dx) ++j; else { ++it; ++j; if (binary_search(a.begin(), a.end(), pair<int, int>(xx, yy))) ++s; } } } printf("%d\n", s); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize "O3" using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int N = 1e5 + 5; int n, a, b, ans; vector<int> xy[N], yx[N]; vector<pair<int, int> > pnt; bool jest(pair<int, int> pkt) { return pnt[lower_bound(pnt.begin(), pnt.end(), pkt) - pnt.begin()] == pkt; } bool checkx(pair<int, int> pkt1, pair<int, int> pkt2) { int bok = pkt2.second - pkt1.second; return jest({pkt1.first + bok, pkt1.second}) && jest({pkt2.first + bok, pkt2.second}); } bool checky(pair<int, int> pkt1, pair<int, int> pkt2) { int bok = pkt2.first - pkt1.first; return jest({pkt1.first, pkt1.second + bok}) && jest({pkt2.first, pkt2.second + bok}); } void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a >> b; xy[a].push_back(b); yx[b].push_back(a); pnt.push_back({a, b}); } pnt.push_back({inf, inf}); sort(pnt.begin(), pnt.end()); for (int i = 0; i <= N - 1; i++) { sort(xy[i].begin(), xy[i].end()); sort(yx[i].begin(), yx[i].end()); } for (auto &cor : pnt) { if (cor == make_pair(inf, inf)) continue; if (((int)xy[cor.first].size()) < ((int)yx[cor.second].size())) { for (int y = lower_bound(xy[cor.first].begin(), xy[cor.first].end(), cor.second) - xy[cor.first].begin() + 1; y < ((int)xy[cor.first].size()); y++) { ans += checkx(cor, {cor.first, xy[cor.first][y]}); } } else { for (int y = lower_bound(yx[cor.second].begin(), yx[cor.second].end(), cor.first) - yx[cor.second].begin() + 1; y < ((int)yx[cor.second].size()); y++) { ans += checky(cor, {yx[cor.second][y], cor.second}); } } } cout << ans << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int MX = 100010; set<pair<int, int> > s; set<int> x[MX], y[MX]; int xc[MX] = {}, yc[MX] = {}; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int xx, yy; scanf("%d %d", &xx, &yy); s.insert(pair<int, int>(xx, yy)); } long long r = 0; for (pair<int, int> p : s) { if (xc[p.first] < yc[p.second]) { int u = min(p.second, MX + p.second - p.first); for (int d : x[p.first]) { if (d >= u) break; if (d < p.second - p.first) continue; if (x[p.first + d - p.second].count(d) && x[p.first + d - p.second].count(p.second)) { r++; } } } else { int u = min(p.first, MX + p.first - p.second); for (int d : y[p.second]) { if (d >= u) break; if (d < p.first - p.second) continue; if (y[p.second + d - p.first].count(d) && y[p.second + d - p.first].count(p.first)) { r++; } } } x[p.first].insert(p.second); xc[p.first]++; y[p.second].insert(p.first); yc[p.second]++; } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int max_N = 100000 + 10; const int N = 100000; const int sq = 320; vector<int> h[max_N], v[max_N]; unordered_map<int, bool> mark[max_N]; int main() { int n, x, y; long long ans(0); scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d", &x, &y); h[y].push_back(x); mark[x][y] = true; } for (int i = 0; i <= N; i++) { int sz = (int)h[i].size(); if (sz > sq) { for (int x : h[i]) v[x].push_back(i); continue; } for (int j = 0; j < sz; j++) { int a = h[i][j]; for (int k = j + 1; k < sz; k++) { int b = h[i][k]; int t = abs(a - b); if (i + t <= N && mark[a][i + t] && mark[b][i + t]) ans++; if (i - t >= 0 && mark[a][i - t] && mark[b][i - t]) ans++; } mark[a][i] = false; } } for (int i = 0; i <= N; i++) { int sz = (int)v[i].size(); for (int j = 0; j < sz; j++) { for (int k = j + 1; k < sz; k++) { int a = v[i][j], b = v[i][k]; int t = abs(a - b); if (mark[i + t][a] && mark[i + t][b]) ans++; } } } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxq = 100001; const int bord = 500; vector<int> xs[maxq]; bool exists(int x, int y) { if (x >= maxq) return false; return binary_search((xs[x]).begin(), (xs[x]).end(), y); } int main() { int N; scanf("%d", &N); for (int i = 0; i < (int)(N); ++i) { int x, y; scanf("%d%d", &x, &y); xs[x].push_back(y); } for (int i = 0; i < (int)(maxq); ++i) { sort((xs[i]).begin(), (xs[i]).end()); } long long ans = 0; for (int x = 0; x < (int)(maxq); ++x) { if (xs[x].size() < bord) { for (int i = 0; i < (int)(xs[x].size()); ++i) { for (int j = i + 1; j < xs[x].size(); ++j) { int d = xs[x][j] - xs[x][i]; if (exists(x + d, xs[x][i]) && exists(x + d, xs[x][j])) { ++ans; } } } } else { for (int xx = x + 1; xx < maxq; ++xx) { for (int i = 0; i < (int)(xs[xx].size()); ++i) { int yy = xs[xx][i]; int d = xx - x; if (exists(x, yy) && exists(x, yy + d) && exists(xx, yy + d)) { ++ans; } } } } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int n, tot = 0; map<int, int> x[200000], y[200000]; bool exists(int xx, int yy) { return x[xx].find(yy) != x[xx].end(); } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { int a, b; scanf("%d %d", &a, &b); x[a][b] = 1; y[b][a] = 1; } for (int i = 0; i < 200000; i++) { map<int, int>::iterator it; int moo = 1; for (it = x[i].begin(); it != x[i].end(); it++) { it->second = moo++; } moo = 1; for (it = y[i].begin(); it != y[i].end(); it++) { it->second = moo++; } } for (int i = 0; i < 200000; i++) { if (x[i].empty()) continue; int xx = i; map<int, int>::iterator it, it2; for (it = x[i].begin(); it != x[i].end(); it++) { int yy = it->first; int cx = (int)x[xx].size() - it->second; int cy = (int)y[yy].size() - y[yy][xx]; if (cx < cy) { for (it2 = x[xx].upper_bound(yy); it2 != x[xx].end(); it2++) { int yy2 = it2->first; if (exists(xx + yy2 - yy, yy) && exists(xx + yy2 - yy, yy2)) { tot++; } } } else { for (it2 = y[yy].upper_bound(xx); it2 != y[yy].end(); it2++) { int xx2 = it2->first; if (exists(xx, yy + xx2 - xx) && exists(xx2, yy + xx2 - xx)) { tot++; } } } } } printf("%d\n", tot); }
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; vector<int> xs[maxn], ys[maxn]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); xs[y].push_back(x); } for (int i = 0; i < maxn; i++) { sort(xs[i].begin(), xs[i].end()); } int SQRT = (int)sqrt(n) + 1; long long int ans = 0; for (int i = 0; i < maxn; i++) { if (xs[i].size() <= SQRT) { for (int j = 0; j < xs[i].size(); j++) { int x1 = xs[i][j]; for (int k = j + 1; k < xs[i].size(); k++) { int x2 = xs[i][k]; int dist = x2 - x1; int y2 = i + dist; if (y2 < maxn) { if (binary_search(xs[y2].begin(), xs[y2].end(), x1) && binary_search(xs[y2].begin(), xs[y2].end(), x2)) { ans++; } } y2 = i - dist; if (y2 >= 0) { if (binary_search(xs[y2].begin(), xs[y2].end(), x1) && binary_search(xs[y2].begin(), xs[y2].end(), x2)) { ans++; } } } } xs[i].clear(); } else { for (int j = 0; j < xs[i].size(); j++) { ys[xs[i][j]].push_back(i); } } } for (int x = 0; x < maxn; x++) { assert(ys[x].size() <= SQRT); for (int i = 0; i < ys[x].size(); i++) { int y1 = ys[x][i]; for (int j = i + 1; j < ys[x].size(); j++) { int y2 = ys[x][j]; int x2 = x + (y2 - y1); if (x2 < maxn) { if (binary_search(ys[x2].begin(), ys[x2].end(), y1) && binary_search(ys[x2].begin(), ys[x2].end(), y2)) { ans++; } } } } } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int x[110000]; int y[110000]; vector<vector<int> > vx(110000), vy(110000), xy(210000), yx(210000); vector<set<int> > sx(110000), sy(110000); int main(int argc, char** argv) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); } for (int i = 0; i < n; i++) { vx[x[i]].push_back(i); vy[y[i]].push_back(i); yx[y[i] - x[i] + 100000].push_back(i); xy[x[i] - y[i] + 100000].push_back(i); sx[x[i]].insert(y[i]); sy[y[i]].insert(x[i]); } long long s1 = 0, s2 = 0, s3 = 0, s4 = 0; for (int i = 0; i < vx.size(); i++) s1 += vx[i].size() * vx[i].size(); for (int i = 0; i < vy.size(); i++) s2 += vy[i].size() * vy[i].size(); for (int i = 0; i < xy.size(); i++) s3 += xy[i].size() * xy[i].size(); for (int i = 0; i < yx.size(); i++) s4 += yx[i].size() * yx[i].size(); long long result = 0; if (s1 <= s2 && s1 <= s3 && s1 <= s4) { for (int i = 0; i < vx.size(); i++) { for (int j = 0; j < vx[i].size(); j++) for (int k = j + 1; k < vx[i].size(); k++) { int p1 = vx[i][j], p2 = vx[i][k]; int len = fabs(y[p1] - y[p2]); if (sx[x[p1] + len].count(y[p1]) > 0 && sx[x[p1] + len].count(y[p2]) > 0) result++; } } } else if (s2 <= s1 && s2 <= s3 && s2 <= s4) { for (int i = 0; i < vy.size(); i++) { for (int j = 0; j < vy[i].size(); j++) for (int k = j + 1; k < vy[i].size(); k++) { int p1 = vy[i][j], p2 = vy[i][k]; int len = fabs(x[p1] - x[p2]); if (sy[y[p1] + len].count(x[p1]) > 0 && sy[y[p1] + len].count(x[p2]) > 0) result++; } } } else if (s3 <= s2 && s3 <= s1 && s3 <= s4) { for (int i = 0; i < xy.size(); i++) { for (int j = 0; j < xy[i].size(); j++) for (int k = j + 1; k < xy[i].size(); k++) { int p1 = xy[i][j], p2 = xy[i][k]; if (s1 <= s2 && sx[x[p1]].count(y[p2]) > 0 && sx[x[p2]].count(y[p1]) > 0) result++; if (s2 < s1 && sy[y[p1]].count(x[p2]) > 0 && sy[y[p2]].count(x[p1]) > 0) result++; } } } else { for (int i = 0; i < yx.size(); i++) { for (int j = 0; j < yx[i].size(); j++) for (int k = j + 1; k < yx[i].size(); k++) { int p1 = yx[i][j], p2 = yx[i][k]; if (s1 <= s2 && sx[x[p1]].count(y[p2]) > 0 && sx[x[p2]].count(y[p1]) > 0) result++; if (s2 < s1 && sy[y[p1]].count(x[p2]) > 0 && sy[y[p2]].count(x[p1]) > 0) result++; } } } cout << result; return 0; }
#include <bits/stdc++.h> using namespace std; struct pair_hash { template <class T1, class T2> std::size_t operator()(const std::pair<T1, T2> &pair) const { return (int)((int)(pair.first * 2654435761ll) ^ (int)(pair.second * 2654435761ll) * 2654435761ll); } }; unordered_set<pair<int, int>, pair_hash> BS; vector<vector<pair<int, int>>> stupci(100001); vector<vector<pair<int, int>>> retci(100001); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int LIM = 300; vector<pair<int, int>> svi; int n; cin >> n; for (int i = 0; i < (n); i++) { int x, y; cin >> x >> y; BS.insert({x, y}); stupci[x].push_back({x, y}); retci[y].push_back({x, y}); svi.push_back({x, y}); } for (int i = 0; i < (100001); i++) sort(stupci[i].begin(), stupci[i].end()); for (int i = 0; i < (100001); i++) sort(retci[i].begin(), retci[i].end()); long long cnt = 0; for (pair<int, int> curr : svi) { if (retci[curr.second].size() <= LIM) { for (pair<int, int> myPair : retci[curr.second]) { if (myPair.first > curr.first) { int dist = myPair.first - curr.first; if (BS.count({curr.first, curr.second + dist}) && BS.count({myPair.first, curr.second + dist})) cnt++; } } } else { for (pair<int, int> myPair : stupci[curr.first]) { if (myPair.second > curr.second) { int dist = myPair.second - curr.second; if (BS.count({curr.first + dist, curr.second}) && BS.count({myPair.first + dist, myPair.second})) cnt++; } } } } cout << cnt; }
#include <bits/stdc++.h> using namespace std; int n, i, j, AN, A, B, o, SZ; struct P { int x, y; } p[111111]; bool mp[77777777], pm[77777777]; bool cmp(P a, P b) { return a.x + a.y < b.x + b.y; } int Hash(int x, int y) { int w = (1ll * x * 100007 + 100000 - y) % 77777777; return w; } int Hash2(int x, int y) { int w = (1ll * x * 1000007 + y) % 77777777; return w; } int main() { scanf("%d", &n); SZ = 300; for (i = 1; i <= n; i++) scanf("%d%d", &p[i].x, &p[i].y), mp[Hash(p[i].x, p[i].y)] = 1, pm[Hash2(p[i].x, p[i].y)] = 1; sort(p + 1, p + n + 1, cmp); for (i = 1; i <= n; i = j) { for (j = i; p[j].x + p[j].y == p[i].x + p[i].y && j <= n; j++) ; if (j - i > SZ) { for (A = 1; A < i; A++) { o = p[i].x + p[i].y - p[A].x - p[A].y; if (mp[Hash(p[A].x + o, p[A].y + o)]) if (mp[Hash(p[A].x + o, p[A].y)]) if (mp[Hash(p[A].x, p[A].y + o)]) if (pm[Hash2(p[A].x + o, p[A].y + o)]) if (pm[Hash2(p[A].x + o, p[A].y)]) if (pm[Hash2(p[A].x + o, p[A].y)]) AN++; } } else { for (A = i; A < j; A++) for (B = A + 1; B < j; B++) { if (mp[Hash(p[A].x, p[B].y)]) if (mp[Hash(p[B].x, p[A].y)]) if (pm[Hash2(p[A].x, p[B].y)]) if (pm[Hash2(p[B].x, p[A].y)]) AN++; } } } printf("%d", AN); }
#include <bits/stdc++.h> using namespace std; const int maxq = 100001; const int bord = 316; vector<int> xs[maxq]; bool exists(int x, int y) { if (x >= maxq) return false; return binary_search((xs[x]).begin(), (xs[x]).end(), y); } int main() { int N; scanf("%d", &N); for (int i = 0; i < (int)(N); ++i) { int x, y; scanf("%d%d", &x, &y); xs[x].push_back(y); } for (int i = 0; i < (int)(maxq); ++i) { sort((xs[i]).begin(), (xs[i]).end()); } long long ans = 0; for (int x = 0; x < (int)(maxq); ++x) { if (xs[x].size() < bord) { for (int i = 0; i < (int)(xs[x].size()); ++i) { for (int j = i + 1; j < xs[x].size(); ++j) { int d = xs[x][j] - xs[x][i]; if (exists(x + d, xs[x][i]) && exists(x + d, xs[x][j])) { ++ans; } } } } else { for (int xx = x + 1; xx < maxq; ++xx) { for (int i = 0; i < (int)(xs[xx].size()); ++i) { int yy = xs[xx][i]; int d = xx - x; if (exists(x, yy) && exists(x, yy + d) && exists(xx, yy + d)) { ++ans; } } } } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100005; int x[N], y[N]; vector<int> a[N], b[N]; int find(int x, int y) { return binary_search(a[x].begin(), a[x].end(), y); } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d", &x[i], &y[i]); a[x[i]].push_back(y[i]); b[y[i]].push_back(x[i]); } long long ans = 0; for (int i = 0; i <= 100000; ++i) sort(a[i].begin(), a[i].end()), sort(b[i].begin(), b[i].end()); for (int i = 0; i < n; ++i) { vector<int> &c = a[x[i]], &d = b[y[i]]; int j = upper_bound(c.begin(), c.end(), y[i]) - c.begin(); int k = upper_bound(d.begin(), d.end(), x[i]) - d.begin(); while (j < c.size() && k < d.size()) { if (c[j] - y[i] < d[k] - x[i]) ++j; else if (c[j] - y[i] > d[k] - x[i]) ++k; else { ans += find(d[k], c[j]); ++j, ++k; } } } printf("%I64d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> T sqr(T x) { return x * x; } namespace std { template <> struct hash<pair<int, int> > { int operator()(pair<int, int> a) const { return a.first * 100000000 + a.second; } }; } // namespace std unordered_map<pair<int, int>, int> m1; vector<int> b; vector<int> a[110000]; int n, m, ans; int main() { int i, j, k, x, y, d; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d%d", &x, &y); a[x].push_back(y); m1[pair<int, int>(x, y)] = 1; } m = sqrt(n); for (i = 0; i <= 100000; i++) if (a[i].size() >= m) b.push_back(i); for (i = 0; i < b.size(); i++) for (j = i + 1; j < b.size(); j++) { d = b[j] - b[i]; x = b[i]; for (k = 0; k < a[x].size(); k++) { y = a[x][k]; if (m1.count(pair<int, int>(x + d, y)) && m1.count(pair<int, int>(x, y + d)) && m1.count(pair<int, int>(x + d, y + d))) ans++; } } for (i = 0; i <= 100000; i++) if (a[i].size() < m) { sort(a[i].begin(), a[i].end()); x = i; for (j = 0; j < a[x].size(); j++) { y = a[x][j]; for (k = j + 1; k < a[x].size(); k++) { d = a[x][k] - a[x][j]; if (m1.count(pair<int, int>(x + d, y)) && m1.count(pair<int, int>(x + d, y + d))) ans++; if (x - d >= 0 && a[x - d].size() >= m) if (m1.count(pair<int, int>(x - d, y)) && m1.count(pair<int, int>(x - d, y + d))) ans++; } } } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; struct data { int x, y; } a[110001], b[110001]; int ans, i, j, k, n, m, px[110001], py[110001], t; bool cmp1(data a, data b) { return a.x < b.x || a.x == b.x && a.y < b.y; } bool cmp2(data a, data b) { return a.y < b.y || a.y == b.y && a.x < b.x; } int bs(int x, int y) { int l, r, m; for (l = 1, r = n; l < r - 1;) { m = (l + r) >> 1; if (x == b[m].x && y == b[m].y) return m; if (y < b[m].y || y == b[m].y && x < b[m].x) r = m - 1; else l = m + 1; } if (x == b[l].x && y == b[l].y) return l; if (x == b[r].x && y == b[r].y) return r; return -1; } int main() { scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y), b[i] = a[i]; sort(a + 1, a + 1 + n, cmp1); sort(b + 1, b + 1 + n, cmp2); for (i = n; i; i--) { if (i == n || a[i + 1].x != a[i].x) px[i] = i; else px[i] = px[i + 1]; if (i == n || b[i + 1].y != b[i].y) py[i] = i; else py[i] = py[i + 1]; } for (i = 1, ans = 0; i <= n; i++) { k = bs(a[i].x, a[i].y); if (px[i] - i < py[k] - k) { for (j = i + 1; j <= px[i]; j++) { t = a[j].y - a[i].y; if (bs(a[i].x + t, a[i].y) != -1 && bs(a[i].x + t, a[i].y + t) != -1) ans++; } } else { for (j = k + 1; j <= py[k]; j++) { t = b[j].x - b[k].x; if (bs(b[k].x, b[k].y + t) != -1 && bs(b[k].x + t, b[k].y + t) != -1) ans++; } } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int SZ = 111111; vector<int> xln[SZ], yln[SZ]; vector<pair<int, int> > wait[SZ]; int n, brd; void rebuild() { for (int xv = 0; xv < SZ; ++xv) if (xln[xv].size() >= brd) for (auto yv : xln[xv]) yln[yv].push_back(xv); } int process(vector<int>* hgts) { for (int i = 0; i < SZ; ++i) wait[i].clear(); for (int xv = 0; xv < SZ; ++xv) { if (hgts[xv].size() < brd) for (int fpn = 0; fpn < hgts[xv].size(); ++fpn) for (int spn = fpn + 1; spn < hgts[xv].size(); ++spn) { int fyv = hgts[xv][fpn]; int syv = hgts[xv][spn]; if (fyv > syv) swap(fyv, syv); int dlt = syv - fyv; if (xv + dlt < SZ) { wait[xv + dlt].push_back(make_pair(fyv, syv)); } if (xv - dlt >= 0 && hgts[xv - dlt].size() >= brd) { wait[xv - dlt].push_back(make_pair(fyv, syv)); } } } int retval = 0; vector<int> pts(SZ, -1); for (int xv = 0; xv < SZ; ++xv) { for (auto yv : hgts[xv]) pts[yv] = xv; for (auto& qp : wait[xv]) if (pts[qp.first] == xv && pts[qp.second] == xv) { ++retval; } } return retval; } int main() { scanf("%d", &n); brd = sqrt(n) + 1; ; for (int i = 0; i < n; ++i) { int x, y; scanf("%d%d", &x, &y); xln[x].push_back(y); } int ans = process(xln); rebuild(); ans += process(yln); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long powm(long long a, long long b, long long m); const long long N = 1e5 + 1; unordered_set<long long> xx[100001]; vector<long long> x[100001], y[100001]; vector<pair<long long, long long> > points; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n; cin >> n; long long tex, tey; for (long long i = 0; i < n; i++) { cin >> tex >> tey; points.push_back({tex, tey}); xx[tex].insert(tey); x[tex].push_back(tey); y[tey].push_back(tex); } long long ans = 0; for (pair<long long, long long> te : points) if (y[te.second].size() > x[te.first].size()) { for (long long j : x[te.first]) if (te.first + j - te.second >= 0 && te.first + j - te.second <= 100000) if (xx[te.first + j - te.second].count(te.second) && xx[te.first + j - te.second].count(j)) ans++; } else for (long long j : y[te.second]) if (xx[te.first].count(te.second - te.first + j) && xx[j].count(te.second + j - te.first)) ans++; ans -= n; ans /= 2; cout << ans << '\n'; } long long powm(long long a, long long b, long long m) { long long te = 1; while (b) { if (b & 1) te = (te * a) % m; a = (a * a) % m; b >>= 1; } return te; }
#include <bits/stdc++.h> using namespace std; const int max_n = 100011, inf = 1111111111; int n, x[max_n], y[max_n], cntx[max_n], cnty[max_n]; vector<int> vx[max_n], vy[max_n]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d", &x[i], &y[i]); ++cntx[x[i]]; ++cnty[y[i]]; } for (int i = 0; i < n; ++i) { if (cntx[x[i]] > 1) { vx[x[i]].push_back(y[i]); } if (cnty[y[i]] > 1) { vy[y[i]].push_back(x[i]); } } int maxx = -1, maxy = -1, pozx, pozy; for (int i = 0; i <= 100000; ++i) { if (maxx < (int)vx[i].size()) { maxx = (int)vx[i].size(); pozx = i; } if (maxy < (int)vy[i].size()) { maxy = (int)vy[i].size(); pozy = i; } } if (n == 97330) { } if (maxx < maxy) { for (int i = 0; i <= 100000; ++i) { sort(vx[i].begin(), vx[i].end()); } int ans = 0; for (int i = 0; i <= 100000; ++i) { if (i != pozx) { for (int j = 0; j < vx[i].size(); ++j) { for (int k = j + 1; k < vx[i].size(); ++k) { int x1 = vx[i][j], x2 = vx[i][k]; int r = x2 - x1; if (i + r <= 100000) { vector<int>::iterator it1 = find(vx[i + r].begin(), vx[i + r].end(), x1); vector<int>::iterator it2 = find(vx[i + r].begin(), vx[i + r].end(), x2); if (it1 != vx[i + r].end() && it2 != vx[i + r].end()) { ++ans; } } if (i - r == pozx) { vector<int>::iterator it1 = find(vx[i - r].begin(), vx[i - r].end(), x1); vector<int>::iterator it2 = find(vx[i - r].begin(), vx[i - r].end(), x2); if (it1 != vx[i - r].end() && it2 != vx[i - r].end()) { ++ans; } } } } } } cout << ans << endl; } else { for (int i = 0; i <= 100000; ++i) { sort(vy[i].begin(), vy[i].end()); } int ans = 0; for (int i = 0; i <= 100000; ++i) { if (i != pozy) { for (int j = 0; j < vy[i].size(); ++j) { for (int k = j + 1; k < vy[i].size(); ++k) { int y1 = vy[i][j], y2 = vy[i][k]; int r = y2 - y1; if (i + r <= 100000) { vector<int>::iterator it1 = find(vy[i + r].begin(), vy[i + r].end(), y1); vector<int>::iterator it2 = find(vy[i + r].begin(), vy[i + r].end(), y2); if (it1 != vy[i + r].end() && it2 != vy[i + r].end()) { ++ans; } } if (i - r == pozy) { vector<int>::iterator it1 = find(vy[i - r].begin(), vy[i - r].end(), y1); vector<int>::iterator it2 = find(vy[i - r].begin(), vy[i - r].end(), y2); if (it1 != vy[i - r].end() && it2 != vy[i - r].end()) { ++ans; } } } } } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 1, sqr = 600; int n, ans = 0; unordered_set<int> cl[MAXN], rw[MAXN]; priority_queue<pair<int, pair<int, int>>> sz; inline void calc_rw(int i) { for (int j : rw[i]) for (int k : rw[i]) { if (k <= j) continue; int x1 = i, y1 = j, y2 = k, df = y2 - y1; if (x1 + df < MAXN && cl[y1].count(x1 + df) && cl[y2].count(x1 + df)) ans++; if (x1 - df >= 0 && cl[y1].count(x1 - df) && cl[y2].count(x1 - df)) ans++; } for (int j : rw[i]) { cl[j].erase(i); if ((int)cl[j].size()) sz.push({-(int)cl[j].size(), {j, 1}}); } rw[i].clear(); return; } inline void calc_cl(int i) { for (int j : cl[i]) for (int k : cl[i]) { if (k <= j) continue; int x1 = i, y1 = j, y2 = k, df = y2 - y1; if (x1 + df < MAXN && rw[y1].count(x1 + df) && rw[y2].count(x1 + df)) ans++; if (x1 - df >= 0 && rw[y1].count(x1 - df) && rw[y2].count(x1 - df)) ans++; } for (int j : cl[i]) { rw[j].erase(i); if ((int)rw[j].size()) sz.push({-(int)rw[j].size(), {j, 1}}); } cl[i].clear(); return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; rw[x].insert(y); cl[y].insert(x); } for (int i = 0; i < MAXN; i++) { if ((int)rw[i].size()) sz.push({-(int)rw[i].size(), {i, 0}}); if ((int)cl[i].size()) sz.push({-(int)cl[i].size(), {i, 1}}); } while (!sz.empty()) { int ind = sz.top().second.first, ty = sz.top().second.second, tt = sz.top().first; sz.pop(); if (ty && -tt == (int)cl[ind].size()) calc_cl(ind); else if (-tt == (int)rw[ind].size()) calc_rw(ind); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int sf = 0; struct pr { int x, y; pr(int xe = 0, int ye = 0) { x = xe; y = ye; } bool operator<(const pr& p) const { if (sf == 0) { if (x != p.x) return x < p.x; return y < p.y; } if (sf == 1) { if (y != p.y) return y < p.y; return x < p.x; } if (sf == 2) { if (y - x != p.y - p.x) return y - x < p.y - p.x; return x < p.x; } return 0; } bool eq(const pr& p) { if (sf == 2) return y - x == p.y - p.x; if (sf == 0) return x == p.x; if (sf == 1) return y == p.y; } int dst(int tp, pr& p) { if (tp == 0) return p.y - y; return p.x - x; } }; pr a[3][100005]; int p[3], e[3]; int Check(pr st) { int res = 0; while (p[0] < e[0] && p[1] < e[1] && p[2] < e[2]) { if (st.dst(0, a[0][p[0]]) == st.dst(1, a[1][p[1]]) && st.dst(0, a[0][p[0]]) == st.dst(2, a[2][p[2]])) { p[0]++; p[1]++; p[2]++; res++; continue; } if (st.dst(0, a[0][p[0]]) < st.dst(1, a[1][p[1]]) && st.dst(0, a[0][p[0]]) < st.dst(2, a[2][p[2]])) { p[0]++; continue; } if (st.dst(0, a[0][p[0]]) > st.dst(1, a[1][p[1]]) && st.dst(1, a[1][p[1]]) < st.dst(2, a[2][p[2]])) { p[1]++; continue; } if (st.dst(2, a[2][p[2]]) < st.dst(1, a[1][p[1]]) && st.dst(1, a[1][p[1]]) > st.dst(2, a[2][p[2]])) { p[2]++; continue; } if (st.dst(0, a[0][p[0]]) == st.dst(1, a[1][p[1]])) { p[0]++; p[1]++; continue; } if (st.dst(2, a[2][p[2]]) == st.dst(1, a[1][p[1]])) { p[2]++; p[1]++; continue; } if (st.dst(2, a[2][p[2]]) == st.dst(0, a[0][p[0]])) { p[2]++; p[0]++; continue; } } return res; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &a[0][i].x, &a[0][i].y); a[1][i] = a[2][i] = a[0][i]; } long long res = 0; for (int i = 0; i < 3; i++) { sf = i; sort(a[i], a[i] + n); } for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { sf = j; p[j] = lower_bound(a[j], a[j] + n, a[0][i]) - a[j] + 1; if (j == 0) e[j] = lower_bound(a[j], a[j] + n, pr(a[0][i].x + 1, -1000000)) - a[j]; if (j == 1) e[j] = lower_bound(a[j], a[j] + n, pr(-1000000, a[0][i].y + 1)) - a[j]; if (j == 2) e[j] = lower_bound(a[j], a[j] + n, pr(-1000000, -1000000 + (a[0][i].y - a[0][i].x + 1))) - a[j]; } res += Check(a[0][i]); } printf("%I64d\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; set<int> xps[101010]; set<int> yps[101010]; set<pair<int, int> > xs; set<pair<int, int> > ys; void rm(int x, int y) { int exc = xps[x].size(); int eyc = yps[y].size(); xs.erase({exc, x}); ys.erase({eyc, y}); xps[x].erase(y); yps[y].erase(x); if (exc > 1) { xs.insert({exc - 1, x}); } if (eyc > 1) { ys.insert({eyc - 1, y}); } } int is(int x, int y) { return xps[x].count(y) > 0; } int x[101010]; int y[101010]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } for (int i = 0; i < n; i++) { xps[x[i]].insert(y[i]); yps[y[i]].insert(x[i]); } for (int i = 0; i <= n; i++) { if ((int)xps[i].size() > 0) { xs.insert({(int)xps[i].size(), i}); } if ((int)yps[i].size() > 0) { ys.insert({(int)yps[i].size(), i}); } } int v = 0; while ((int)xs.size() > 0 || (int)ys.size() > 0) { if ((int)xs.size() == 0 || (((int)xs.size() > 0 && (int)ys.size() > 0) && (*ys.begin()).first < (*xs.begin()).first)) { vector<int> xx; int ty = (*ys.begin()).second; for (int kx : yps[ty]) { xx.push_back(kx); } for (int i = 0; i < (int)xx.size(); i++) { for (int ii = i + 1; ii < (int)xx.size(); ii++) { int d = abs(xx[ii] - xx[i]); int ny1 = ty + d; int ny2 = ty - d; if (is(xx[i], ny1) && is(xx[ii], ny1)) v++; if (is(xx[i], ny2) && is(xx[ii], ny2)) v++; } } for (int i = 0; i < (int)xx.size(); i++) { rm(xx[i], ty); } } else { vector<int> yy; int tx = (*xs.begin()).second; for (int ky : xps[tx]) { yy.push_back(ky); } for (int i = 0; i < (int)yy.size(); i++) { for (int ii = i + 1; ii < (int)yy.size(); ii++) { int d = abs(yy[ii] - yy[i]); int nx1 = tx + d; int nx2 = tx - d; if (is(nx1, yy[ii]) && is(nx1, yy[i])) v++; if (is(nx2, yy[ii]) && is(nx2, yy[i])) v++; } } for (int i = 0; i < (int)yy.size(); i++) { rm(tx, yy[i]); } } } cout << v << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 100005; const int INF = (1 << 29); const int mod = 1000007; int a, b, c, d, e, f, g, h, i, j, k; pair<int, int> G[N]; vector<long long> hav[2][1000025]; vector<int> GG[N], Big; int tot, type[N]; int max_x = -INF, max_y = -INF, min_x = INF, min_y = INF; int an; inline long long Num(int x, int y) { return 2000000LL * ((long long)x + 2000000 - 1) + ((long long)y + 2000000); } inline bool Hash(vector<long long> uu[], int x, int y) { long long tt = Num(x, y); for (int ii = 0; ii < uu[tt % mod].size(); ii++) if (uu[tt % mod][ii] == tt) return true; return false; } inline void Check1(int x, int y) { int delta = G[y].second - G[x].second; if (G[x].first - delta >= min_x && Hash(hav[0], G[x].first - delta, G[x].second) && Hash(hav[0], G[x].first - delta, G[y].second)) an++; if (G[x].first - delta >= min_x && Hash(hav[1], G[x].first - delta, G[x].second) && Hash(hav[1], G[x].first - delta, G[y].second)) an++; if (G[x].first + delta <= max_x && Hash(hav[1], G[x].first + delta, G[x].second) && Hash(hav[1], G[x].first + delta, G[y].second)) an++; } inline void Check2(int x, int y) { int delta = G[y].first - G[x].first; if (G[x].second - delta >= min_y && Hash(hav[1], G[x].first, G[x].second - delta) && Hash(hav[1], G[y].first, G[y].second - delta)) an++; } int main() { cin >> a; for (i = 1; i <= a; i++) { scanf("%d%d", &G[i].first, &G[i].second); max_x = max(max_x, G[i].first); max_y = max(max_y, G[i].second); min_x = min(min_x, G[i].first); min_y = min(min_y, G[i].second); } sort(G + 1, G + a + 1); for (i = 1; i <= a; i++) { if (i == 1 || G[i].first != G[i - 1].first) tot++; GG[tot].push_back(i); } int siz = (int)sqrt((double)a); for (i = 1; i <= tot; i++) { int vv = 1; if (GG[i].size() <= siz) vv = 0; else Big.push_back(i); for (j = 0; j < GG[i].size(); j++) { long long tt = Num(G[GG[i][j]].first, G[GG[i][j]].second); hav[vv][tt % mod].push_back(tt); } } int Cnt = 0; for (i = 1; i <= tot; i++) if (GG[i].size() <= siz) { Cnt += GG[i].size() * GG[i].size(); for (j = 0; j < GG[i].size(); j++) for (k = j + 1; k < GG[i].size(); k++) Check1(GG[i][j], GG[i][k]); } for (i = 0; i < Big.size(); i++) for (j = i + 1; j < Big.size(); j++) { c = Big[i], d = Big[j]; vector<pair<int, int> > u; for (k = 0; k < GG[d].size(); k++) u.push_back(make_pair(G[GG[d][k]].second, GG[d][k])); int pos = 0; for (k = 0; k < GG[c].size(); k++) { while (pos < u.size() && G[GG[c][k]].second > u[pos].first) pos++; if (pos == u.size()) break; if (G[GG[c][k]].second < u[pos].first) continue; Check2(GG[c][k], u[pos].second); } } cout << an << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100001; vector<int> a[N], b[N]; int ans, x, y, p1, p2, pos[N], n, m, i, j, q, w; map<pair<int, int>, int> have; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> n; for (i = 1; i <= n; i++) { cin >> q >> w; a[q].push_back(w); b[w].push_back(q); have[make_pair(q, w)] = 1; } for (i = 0; i < N; i++) { sort(a[i].begin(), a[i].end()); sort(b[i].begin(), b[i].end()); } for (x = 0; x < N; x++) for (i = 0; i < a[x].size(); i++) { y = a[x][i]; p1 = i + 1; p2 = pos[y] + 1; while (p1 < a[x].size() && p2 < b[y].size()) { if (a[x][p1] - y == b[y][p2] - x && have[make_pair(b[y][p2], a[x][p1])]) ans++; if (a[x][p1] - y < b[y][p2] - x) p1++; else p2++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int MAXK = 2 * 1e5 + 1; vector<vector<int> > g, g1; vector<vector<pair<int, int> > > need; int sqrtn, ans; vector<int> was; void Do(vector<vector<int> > &g) { need.clear(); need.resize(MAXK); for (int i = 0; i < MAXK; i++) { if (g[i].size() <= sqrtn && g[i].size() > 1) { for (int j = 0; j < g[i].size() - 1; j++) for (int k = j + 1; k < g[i].size(); k++) { need[i + abs(g[i][j] - g[i][k])].push_back( make_pair(g[i][j], g[i][k])); if ((i - abs(g[i][j] - g[i][k]) >= 0) && (g[i - abs(g[i][j] - g[i][k])].size() > sqrtn)) need[i - abs(g[i][j] - g[i][k])].push_back( make_pair(g[i][j], g[i][k])); } } } was.assign(MAXK, 0); for (int i = 0; i < MAXK; i++) { for (int j = 0; j < g[i].size(); j++) was[g[i][j]] = i + 1; for (int j = 0; j < need[i].size(); j++) if (was[need[i][j].first] == i + 1 && was[need[i][j].second] == i + 1) ans++; if (g[i].size() <= sqrtn) g[i].clear(); } } int main() { int n; scanf("%i", &n); sqrtn = sqrt(0.0 + n); g.resize(MAXK); for (int i = 0; i < n; i++) { int x, y; scanf("%i%i", &x, &y); g[x].push_back(y); } Do(g); g1.resize(MAXK); for (int i = 0; i < MAXK; i++) for (int j = 0; j < g[i].size(); j++) g1[g[i][j]].push_back(i); Do(g1); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long int N = 1e5 + 1; unordered_set<long long int> sx[N], sy[N]; long long int x[N], y[N]; void solve() { long long int n; cin >> n; for (long long int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; sx[x[i]].insert(y[i]); sy[y[i]].insert(x[i]); } long long int ans = 0; for (long long int i = 1; i <= n; i++) { if (sx[x[i]].size() <= sy[y[i]].size()) { for (long long int yy : sx[x[i]]) { long long int l = yy - y[i]; if (l <= 0) continue; if (sy[yy].count(x[i] + l) && sy[y[i]].count(x[i] + l)) ans++; } } else { for (long long int xx : sy[y[i]]) { long long int l = xx - x[i]; if (l <= 0) continue; if (sx[xx].count(y[i] + l) && sx[x[i]].count(y[i] + l)) ans++; } } } cout << ans; } signed main() { ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0); clock_t clk = clock(); long long int t; t = 1; while (t--) { solve(); } cerr << '\n' << (double)(clock() - clk) / CLOCKS_PER_SEC; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> ys[100003]; vector<int> xs[100003]; int n; unordered_map<long long, bool> exist; pair<int, int> pts[100003]; long long hash_pair(pair<int, int> a) { return (long long)(a.first) * 100003 + a.second; } long long ans; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; for (int i = 1; i <= n; i++) { cin >> pts[i].first >> pts[i].second; exist[hash_pair(pts[i])] = true; ys[pts[i].first].push_back(pts[i].second); xs[pts[i].second].push_back(pts[i].first); } for (int i = 0; i < 100003; i++) { sort(xs[i].begin(), xs[i].end()); sort(ys[i].begin(), ys[i].end()); } for (int i = 1; i <= n; i++) { auto it1 = lower_bound(ys[pts[i].first].begin(), ys[pts[i].first].end(), pts[i].second); auto it2 = lower_bound(xs[pts[i].second].begin(), xs[pts[i].second].end(), pts[i].first); if (it1 - ys[pts[i].first].begin() < it2 - xs[pts[i].second].begin()) for (int j = 0; j < ys[pts[i].first].size() && ys[pts[i].first][j] < pts[i].second; j++) { int side = pts[i].second - ys[pts[i].first][j]; if (exist[hash_pair( make_pair(pts[i].first - side, ys[pts[i].first][j]))] && exist[hash_pair(make_pair(pts[i].first - side, pts[i].second))]) ans++; } else for (int j = 0; j < xs[pts[i].second].size() && xs[pts[i].second][j] < pts[i].first; j++) { int side = pts[i].first - xs[pts[i].second][j]; if (exist[hash_pair(make_pair(pts[i].first, pts[i].second - side))] && exist[hash_pair( make_pair(xs[pts[i].second][j], pts[i].second - side))]) ans++; } } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100001; const int inf = 0x7f7f7f7f; const int mod = (int)(1e9 + 7); const long long INF = 1LL << 50; const double eps = 1e-8; const double pi = acos(-1.0); const int mask = 65535; vector<int> W[maxn]; bool ok(int x, int y) { if (x >= maxn || y >= maxn) return 0; return binary_search(W[x].begin(), W[x].end(), y); } int main() { ios::sync_with_stdio(false); int n, i, j, k, u, x, y; cin >> n; for (i = 0; i < n; ++i) { cin >> x >> y; W[x].push_back(y); } for (i = 0; i < maxn; ++i) { sort(W[i].begin(), W[i].end()); } int block = (int)sqrt(n + 0.0); vector<int>::iterator it, jt; int ans = 0, d; for (i = 0; i < maxn; ++i) { int sz = W[i].size(); if (sz <= block) { for (j = 0; j < sz; ++j) { for (k = j + 1; k < sz; ++k) { d = W[i][k] - W[i][j]; y = W[i][j]; x = i; ans += ok(x + d, y) && ok(x + d, y + d); } } } else { for (j = i + 1; j < maxn; ++j) { int sz = W[j].size(); d = j - i; for (k = 0; k < sz; ++k) { x = j; y = W[j][k]; ans += ok(j, y + d) && ok(i, y) && ok(i, y + d); } } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; bool exist(pair<int, int> p, vector<vector<int> > &H) { if (p.second < 0 || p.second >= H.size()) return 0; return binary_search(H[p.second].begin(), H[p.second].end(), p.first); } int main() { vector<vector<int> > H(100010); vector<vector<int> > V(100010); int N; cin >> N; for (int i = 0; i < N; ++i) { pair<int, int> p; cin >> p.first >> p.second; H[p.second].push_back(p.first); } for (int i = 0; i < H.size(); ++i) sort(H[i].begin(), H[i].end()); int THRESHOLD = sqrt(N) + 1; int CNT = 0, oC = 0; for (int i = 0; i < H.size(); ++i) { if (H[i].size() && H[i].size() <= THRESHOLD) { for (int j = 0; j < H[i].size(); ++j) { int x1 = H[i][j]; for (int k = j + 1; k < H[i].size(); ++k) { oC++; int x2 = H[i][k]; int L = x2 - x1; if (i + L < H.size() && H[i + L].size() > THRESHOLD) CNT += exist(pair<int, int>(x1, i + L), H) && exist(pair<int, int>(x2, i + L), H); CNT += exist(pair<int, int>(x1, i - L), H) && exist(pair<int, int>(x2, i - L), H); } } } else if (H[i].size()) { for (int j = 0; j < H[i].size(); ++j) V[H[i][j]].push_back(i); } } for (int i = 0; i < V.size(); ++i) { for (int j = 0; j < V[i].size(); ++j) { int y1 = V[i][j]; for (int k = j + 1; k < V[i].size(); ++k) { int y2 = V[i][k]; int L = y2 - y1; CNT += exist(pair<int, int>(i - L, y1), H) && exist(pair<int, int>(i - L, y2), H); } } } cout << CNT << endl; }
#include <bits/stdc++.h> using namespace std; unordered_set<int> lin[100010]; unordered_set<int> col[100010]; int x[100010], y[100010]; int main() { int n, i, sol = 0, x0, y0; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d%d", &x[i], &y[i]); lin[x[i]].insert(y[i]); col[y[i]].insert(x[i]); } for (i = 1; i <= n; i++) if (lin[x[i]].size() < col[y[i]].size()) { for (auto& y0 : lin[x[i]]) if (y0 > y[i]) if (col[y[i]].count(x[i] + y0 - y[i]) > 0 && col[y0].count(x[i] + y0 - y[i]) > 0) sol++; } else for (auto& x0 : col[y[i]]) if (x0 > x[i]) if (lin[x[i]].count(y[i] + x0 - x[i]) > 0 && lin[x0].count(y[i] + x0 - x[i]) > 0) sol++; printf("%d", sol); return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-12; const int inf = 2000000000; const long long int infLL = (long long int)1e18; long long int MOD = 1000000007; int MOD1 = 1000000007; int MOD2 = 1000000009; inline bool checkBit(long long int n, long long int i) { return n & (1LL << i); } inline long long int setBit(long long int n, long long int i) { return n | (1LL << i); ; } inline long long int resetBit(long long int n, long long int i) { return n & (~(1LL << i)); } int dx[] = {0, 0, +1, -1}; int dy[] = {+1, -1, 0, 0}; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline bool isLeapYear(long long int year) { return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); } inline void normal(long long int &a) { a %= MOD; (a < 0) && (a += MOD); } inline long long int modMul(long long int a, long long int b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % MOD; } inline long long int modAdd(long long int a, long long int b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a + b) % MOD; } inline long long int modSub(long long int a, long long int b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline long long int modPow(long long int b, long long int p) { long long int r = 1LL; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; } inline long long int modDiv(long long int a, long long int b) { return modMul(a, modPow(b, MOD - 2)); } bool comp(const pair<long long int, pair<long long int, long long int> > &p1, const pair<long long int, pair<long long int, long long int> > &p2) { return p1.first > p2.first; } bool comp1(const pair<long long int, long long int> &p1, const pair<long long int, long long int> &p2) { if (p1.first == p2.first) { return p1.second > p2.second; } return p1.first < p2.first; } long long int converter(string a) { long long int i, mul = 1, r, t, ans = 0LL; if (a.length() == 0) return 0; for (i = a.length() - 1; i >= 0; i--) { t = a[i] - '0'; r = t % 10; ans += (mul * r); mul = mul * 10; } return ans; } int msb(unsigned x) { union { double a; int b[2]; }; a = x; return (b[1] >> 20) - 1023; } const int MAX = (int)1e5 + 5; vector<long long int> x[MAX]; vector<long long int> y[MAX]; pair<long long int, long long int> p[MAX]; unordered_map<long long int, int> mp[MAX]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int n, i, j, a, b, ans = 0LL; cin >> n; for (i = 1; i <= n; ++i) { cin >> a >> b; p[i] = make_pair(a, b); mp[a][b]++; x[a].push_back(b); y[b].push_back(a); } for (i = 0; i < MAX; ++i) { sort((x[i]).begin(), (x[i]).end()); sort((y[i]).begin(), (y[i]).end()); } for (i = 1; i <= n; ++i) { a = p[i].first; b = p[i].second; if (x[a].size() <= y[b].size()) { for (j = 0; j < x[a].size(); ++j) { long long int cury = x[a][j]; if (cury >= b) break; long long int dif = b - cury; if (a - dif < 0) continue; if (mp[a - dif][b] == 1 && mp[a - dif][cury] == 1) ++ans; } } else { for (j = 0; j < y[b].size(); ++j) { long long int curx = y[b][j]; if (curx >= a) break; long long int dif = a - curx; if (b - dif < 0) continue; if (mp[a][b - dif] == 1 && mp[curx][b - dif] == 1) ++ans; } } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A> string to_string(A* ptr) { stringstream ss; ss << "0x" << std::setw(16) << std::setfill('0') << std::hex << (uint64_t)(uintptr_t)ptr; return ss.str(); } string to_string(char c) { return ((string) "'" + c) + "'"; } template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto& x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } const int MX = 1e5 + 99; int n; int x[MX], y[MX]; bool have(vector<pair<int, int>>& S, int x, int y) { pair<int, int> xy = {x, y}; return binary_search(S.begin(), S.end(), xy); } int solve() { vector<vector<int>> M_hor(MX), M_ver(MX); vector<pair<int, int>> S; S.reserve(n); for (int i = 0; i < n; i++) { M_hor[y[i]].push_back(x[i]); M_ver[x[i]].push_back(y[i]); S.push_back({x[i], y[i]}); } for (auto& v : M_hor) sort(v.begin(), v.end()); for (auto& v : M_ver) sort(v.begin(), v.end()); sort(S.begin(), S.end()); int result = 0; for (int i = 0; i < n; i++) { int first = x[i], second = y[i]; auto& VHOR = M_hor[second]; auto& VVER = M_ver[first]; auto it_hor = upper_bound(VHOR.begin(), VHOR.end(), first); auto it_ver = upper_bound(VVER.begin(), VVER.end(), second); int cnt_hor = (int)(VHOR.end() - it_hor); int cnt_ver = (int)(VVER.end() - it_ver); if (cnt_hor <= cnt_ver) { for (auto it = it_hor; it != VHOR.end(); it++) { int dx = *it - first; if (have(S, first, second + dx) && have(S, first + dx, second + dx)) result++; } } else { for (auto it = it_ver; it != VVER.end(); it++) { int dy = *it - second; if (have(S, first + dy, second) && have(S, first + dy, second + dy)) result++; } } } return result; } int main() { int TTT = 1; for (int ttt = 0; ttt < TTT; ttt++) { cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; cout << solve() << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const int mo = 1e9 + 7; const int N = 101010; vector<int> sx[N], sy[N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { int x, y; cin >> x >> y; sx[x].push_back(y); sy[y].push_back(x); } for (int i = 0; i <= 100000; i++) { sort(sx[i].begin(), sx[i].end()); sort(sy[i].begin(), sy[i].end()); } int ans = 0; for (int i = 0; i <= 100000; i++) { if (sx[i].size() < 2) continue; for (unsigned int j = 0; j < sx[i].size(); j++) { int x = i, y = sx[i][j]; int px = j + 1, py = lower_bound(sy[y].begin(), sy[y].end(), x) - sy[y].begin(); while (px < (int)sx[i].size() && py < (int)sy[y].size()) { if (sx[i][px] - y > sy[y][py] - x) { py++; continue; } if (sx[i][px] - y < sy[y][py] - x) { px++; continue; } int tx = sx[i][px], ty = sy[y][py]; ans += binary_search(sx[sy[y][py]].begin(), sx[sy[y][py]].end(), sx[x][px]); px++; py++; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> ve[110000]; int n; bool check(int x, int y) { if (x > 100000 || ve[x].size() == 0) return false; return binary_search(ve[x].begin(), ve[x].end(), y); } int main() { int i, x, y, j, g, ans = 0, len, l; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d%d", &x, &y); ve[x].push_back(y); } for (i = 0; i <= 100000; i++) sort(ve[i].begin(), ve[i].end()); for (i = 0; i <= 100000; i++) { l = ve[i].size(); if (l >= 500) { for (j = i + 1; j <= 100000; j++) { for (g = 0; g < ve[j].size(); g++) { if (check(i, ve[j][g]) && check(i, ve[j][g] + j - i) && check(j, ve[j][g] + j - i)) ans++; } } } else { for (j = 0; j < ve[i].size(); j++) { for (g = j + 1; g < ve[i].size(); g++) { len = ve[i][g] - ve[i][j]; if (check(i + len, ve[i][j]) && check(i + len, ve[i][g])) ans++; } } } } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; struct point { int x, y; }; point d[222222], e[222222]; int n, m, ans = 0, sum[222222]; bool cmp(point u, point v) { return (u.x < v.x) || ((u.x == v.x) && (u.y < v.y)); } bool found(point u) { int low = 1, high = n, mid; while (low + 1 < high) { mid = (low + high) / 2; if ((u.x < d[mid].x) || ((u.x == d[mid].x) && (u.y <= d[mid].y))) high = mid; else low = mid; } if ((u.x == d[low].x) && (u.y == d[low].y)) return true; if ((u.x == d[high].x) && (u.y == d[high].y)) return true; return false; } void solve(int tp) { sort(d + 1, d + n + 1, cmp); int p = 1, last, edge; memset(sum, 0, sizeof(sum)); for (int i = 1; i <= n; i++) sum[d[i].x]++; point u; while (p <= n) { for (int i = p; i <= n; i++) if (d[i].x == d[p].x) last = i; else break; if ((tp) || (last - p + 1 <= m)) { for (int i = p; i <= last; i++) for (int j = i + 1; j <= last; j++) { edge = d[j].y - d[i].y; u.x = d[i].x + edge; u.y = d[i].y; if (found(u)) { u.x = d[j].x + edge; u.y = d[j].y; if (found(u)) ans++; } if (!tp) if ((d[i].x - edge >= 0) && (sum[d[i].x - edge] > m)) { u.x = d[i].x - edge; u.y = d[i].y; if (found(u)) { u.x = d[j].x - edge; u.y = d[j].y; if (found(u)) ans++; } } } } p = last + 1; } } void init() { int p = 1, last, ne = 0; while (p <= n) { for (int i = p; i <= n; i++) if (d[i].x == d[p].x) last = i; else break; if (last - p + 1 > m) for (int i = p; i <= last; i++) e[++ne] = d[i]; p = last + 1; } n = ne; for (int i = 1; i <= n; i++) d[i] = e[i]; for (int i = 1; i <= n; i++) swap(d[i].x, d[i].y); } int main() { cin >> n; m = trunc(sqrt((double)n)) + 3; for (int i = 1; i <= n; i++) scanf("%d%d", &d[i].x, &d[i].y); ans = 0; solve(0); init(); solve(1); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A> string to_string(A* ptr) { stringstream ss; ss << "0x" << std::setw(16) << std::setfill('0') << std::hex << (uint64_t)(uintptr_t)ptr; return ss.str(); } string to_string(char c) { return ((string) "'" + c) + "'"; } template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto& x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } long long to_key(long long x, long long y) { return (x << 20) + y; } const int MX = 1e5 + 99; int n; int x[MX], y[MX]; bool have(vector<pair<int, int>>& S, int x, int y) { pair<int, int> xy = {x, y}; return binary_search(S.begin(), S.end(), xy); } int solve() { vector<vector<int>> M_hor(MX), M_ver(MX); unordered_set<long long> S; for (int i = 0; i < n; i++) { M_hor[y[i]].push_back(x[i]); M_ver[x[i]].push_back(y[i]); S.insert(to_key(x[i], y[i])); } for (auto& v : M_hor) sort(v.begin(), v.end()); for (auto& v : M_ver) sort(v.begin(), v.end()); int result = 0; for (int i = 0; i < n; i++) { int first = x[i], second = y[i]; auto& VHOR = M_hor[second]; auto& VVER = M_ver[first]; auto it_hor = upper_bound(VHOR.begin(), VHOR.end(), first); auto it_ver = upper_bound(VVER.begin(), VVER.end(), second); int cnt_hor = (int)(VHOR.end() - it_hor); int cnt_ver = (int)(VVER.end() - it_ver); if (cnt_hor <= cnt_ver) { for (auto it = it_hor; it != VHOR.end(); it++) { int dx = *it - first; if (S.count(to_key(first, second + dx)) && S.count(to_key(first + dx, second + dx))) result++; } } else { for (auto it = it_ver; it != VVER.end(); it++) { int dy = *it - second; if (S.count(to_key(first + dy, second)) && S.count(to_key(first + dy, second + dy))) result++; } } } return result; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int TTT = 1; for (int ttt = 0; ttt < TTT; ttt++) { cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; cout << solve() << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, x[(100005)], y[(100005)]; vector<vector<int> > vert, hori; bool check(int p, int q) { if (p >= (100005) || q >= (100005)) return false; vector<int>::iterator it = (lower_bound(hori[p].begin(), hori[p].end(), q)); return (it != hori[p].end() && (*it) == q); } int main() { while (scanf("%d", &n) != EOF) { vert.clear(); vert.resize((100005)); hori.clear(); hori.resize((100005)); for (int i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); hori[x[i]].push_back(y[i]); vert[y[i]].push_back(x[i]); } for (int i = 0; i < (100005); i++) { sort(vert[i].begin(), vert[i].end()); sort(hori[i].begin(), hori[i].end()); } int ans = 0; for (int i = 0; i < (100005); i++) { int sz = hori[i].size(); for (int j = 0; j < sz; j++) { int p = i; int q = hori[i][j]; int sz2 = vert[q].size(); int ind2 = lower_bound(vert[q].begin(), vert[q].end(), p) - vert[q].begin(); if ((sz2 - ind2) > (sz - j)) { for (int k = j + 1; k < sz; k++) { int dis = hori[i][k] - q; if (check(p + dis, q) && check(p + dis, q + dis)) { ans++; } } } else { for (int k = ind2 + 1; k < sz2; k++) { int dis = vert[q][k] - p; if (check(p, q + dis) && check(p + dis, q + dis)) { ans++; } } } } } printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 5; const long long linf = 1e18 + 5; const int N = 1e5 + 5; int n, x, y, ans; pair<int, int> a[N]; vector<int> vx[N], vy[N]; int main() { ios ::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i].first >> a[i].second; vx[a[i].first].push_back(a[i].second); vy[a[i].second].push_back(a[i].first); } for (int i = 0; i <= 100000; i++) { sort(vx[i].begin(), vx[i].end()); sort(vy[i].begin(), vy[i].end()); } for (int i = 1; i <= n; i++) { x = a[i].first; y = a[i].second; if (vx[x].size() < vy[y].size()) { for (__typeof((vx[x]).begin()) it = (vx[x]).begin(); it != (vx[x]).end(); it++) if (*it > y) if (binary_search(vy[y].begin(), vy[y].end(), x + *it - y)) if (binary_search(vy[*it].begin(), vy[*it].end(), x + *it - y)) ans++; } else { for (__typeof((vy[y]).begin()) it = (vy[y]).begin(); it != (vy[y]).end(); it++) if (*it > x) if (binary_search(vx[x].begin(), vx[x].end(), y + *it - x)) if (binary_search(vx[*it].begin(), vx[*it].end(), y + *it - x)) ans++; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> const int MOD = 1000000007; using namespace std; const int MX = 100010; const int SZ = 350; long long ans; vector<int> pts[MX]; int N; bool is(int x, int y) { if (y < 0 || y >= MX) return false; auto it = lower_bound(pts[y].begin(), pts[y].end(), x); return it != pts[y].end() && *it == x; } int main() { scanf("%d", &(N)); for (int k = (0); k < (N); k++) { int x; scanf("%d", &(x)); ; int y; scanf("%d", &(y)); ; pts[y].push_back(x); } for (int i = (0); i < (MX); i++) sort(pts[i].begin(), pts[i].end()); vector<int> large; for (int ypos = (0); ypos < (MX); ypos++) { if (pts[ypos].size() > SZ) large.push_back(ypos); else { auto& V = pts[ypos]; for (int i = (0); i < (V.size()); i++) for (int j = (i + 1); j < (V.size()); j++) { int d = V[j] - V[i]; if (ypos - d >= 0 && pts[ypos - d].size() > SZ) ans += is(V[i], ypos - d) && is(V[j], ypos - d); ans += is(V[i], ypos + d) && is(V[j], ypos + d); } } } for (int i = (0); i < (large.size()); i++) for (int j = (i + 1); j < (large.size()); j++) { int a = large[i]; int b = large[j]; auto& A = pts[a]; auto& B = pts[b]; int d = b - a; int l1 = 0; int r1 = 0; int r2 = 0; for (int l2 = 0; l2 < A.size(); l2++) { int p = A[l2]; while (p - A[l1] > d) l1++; while (r2 < B.size() && p > B[r2]) r2++; if (r2 == B.size()) break; while (p - B[r1] > d) r1++; ans += A[l2] == B[r2] && B[r1] == p - d && A[l1] == p - d; } } printf("%lld\n", ans); }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target( \ "avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; int MOD = 1e9 + 7; const int N = 120000; const int B = 300; vector<int> xn[N]; bool exists(int x, int y) { if (x >= N) return false; return binary_search(xn[x].begin(), xn[x].end(), y); } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20); int n; cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; xn[x].push_back(y); } int ans = 0; for (int i = 0; i < N; i++) { sort(xn[i].begin(), xn[i].end()); } for (int i = 0; i < N; i++) { if (xn[i].size() < B) { for (auto j : xn[i]) { for (auto j2 : xn[i]) { if (j >= j2) continue; int ds = j2 - j; if (exists(i + ds, j) && exists(i + ds, j2)) { ans++; } } } } else { for (int i2 = i + 1; i2 < N; i2++) { for (auto y : xn[i2]) { if (exists(i, y) && exists(i, y + i2 - i) && exists(i2, y + i2 - i)) { ans++; } } } } } cout << ans; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long powm(long long a, long long b, long long m); unordered_set<long long> xx[100001], yy[100001]; vector<long long> x[100001], y[100001]; vector<pair<long long, long long> > points; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n; cin >> n; long long tex, tey; for (long long i = 0; i < n; i++) { cin >> tex >> tey; points.push_back({tex, tey}); xx[tex].insert(tey); x[tex].push_back(tey); yy[tey].insert(tex); y[tey].push_back(tex); } long long ans = 0; for (pair<long long, long long> te : points) if (y[te.second].size() > x[te.first].size()) for (long long j : x[te.first]) { if (yy[te.second].count(te.first + j - te.second) && yy[j].count(te.first + j - te.second)) ans++; } else for (long long j : y[te.second]) { if (xx[te.first].count(te.second - te.first + j) && xx[j].count(te.second + j - te.first)) ans++; } ans -= n; ans /= 2; cout << ans << '\n'; } long long powm(long long a, long long b, long long m) { long long te = 1; while (b) { if (b & 1) te = (te * a) % m; a = (a * a) % m; b >>= 1; } return te; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, ans; vector<int> xs[N], ys[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; xs[x].push_back(y); ys[y].push_back(x); } for (int i = 0; i < N; ++i) { sort(xs[i].begin(), xs[i].end()); sort(ys[i].begin(), ys[i].end()); } for (int i = 0; i < N; ++i) { int nowX = i; for (int nowY : xs[i]) { int boundY = upper_bound(xs[nowX].begin(), xs[nowX].end(), nowY) - xs[nowX].begin(); int boundX = upper_bound(ys[nowY].begin(), ys[nowY].end(), nowX) - ys[nowY].begin(); while (boundY < (int)xs[nowX].size() and boundX < (int)ys[nowY].size()) { int checkX = ys[nowY][boundX]; int checkY = xs[nowX][boundY]; if (checkX - nowX > checkY - nowY) ++boundY; else if (checkX - nowX < checkY - nowY) ++boundX; else { ans += binary_search(xs[checkX].begin(), xs[checkX].end(), checkY); ++boundX; ++boundY; } } } } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; const int inft = 1000000009; const int MAXN = 1000006; pair<int, int> P[MAXN]; int n; vector<pair<int, int> > X[MAXN], Y[MAXN]; inline bool czy(pair<int, int> a) { if (min(a.first, a.second) < 0 || max(a.first, a.second) >= MAXN) return 0; if (X[a.first].size() < Y[a.second].size()) return binary_search((X[a.first]).begin(), (X[a.first]).end(), a); else return binary_search((Y[a.second]).begin(), (Y[a.second]).end(), a); } inline bool jest(pair<int, int> a, int d) { return czy(pair<int, int>(a.first - d, a.second)) && czy(pair<int, int>(a.first - d, a.second - d)) && czy(pair<int, int>(a.first, a.second - d)); } int main() { scanf("%d", &n); for (int i = 0; i < (n); ++i) scanf("%d%d", &P[i].first, &P[i].second); sort(P, P + n); for (int i = 0; i < (n); ++i) X[P[i].first].push_back(P[i]); for (int i = 0; i < (n); ++i) Y[P[i].second].push_back(P[i]); for (int i = 0; i < (MAXN); ++i) sort((X[i]).begin(), (X[i]).end()); for (int i = 0; i < (MAXN); ++i) sort((Y[i]).begin(), (Y[i]).end()); int ret = 0; for (int i = 0; i < (n); ++i) { int first = P[i].first, second = P[i].second; int x1 = lower_bound((X[first]).begin(), (X[first]).end(), P[i]) - X[first].begin(); int y1 = lower_bound((Y[second]).begin(), (Y[second]).end(), P[i]) - Y[second].begin(); if (x1 <= y1) for (int j = 0; j < (x1); ++j) ret += jest(P[i], P[i].second - X[first][j].second); else for (int j = 0; j < (y1); ++j) ret += jest(P[i], P[i].first - Y[second][j].first); } printf("%d\n", ret); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1e4; struct Point { int x, y; Point() {} Point(int x, int y) : x(x), y(y) {} } point[N]; set<int> ss[N]; vector<Point> pp[N]; vector<Point>::iterator it; int n, num[N], which[10000]; int cmp(const Point &a, const Point &b) { if (a.x != b.x) return a.x < b.x; return a.y < b.y; } bool check(int x, int y, int lower) { if (x < 0 || x > 100000) return 0; if (num[x] <= lower) return 0; if (ss[x].find(y) != ss[x].end()) return 1; else return 0; } int main() { cin >> n; int maxn = sqrt(n); memset(num, 0, sizeof(num)); for (int i = 1; i <= n; i++) { scanf("%d%d", &point[i].x, &point[i].y); ss[point[i].x].insert(point[i].y); num[point[i].x]++; } sort(point + 1, point + n + 1, cmp); point[0].x = -1; point[n + 1].x = 2e5; int l = 1; int ans = 0; for (int i = 1; i <= n + 1; i++) { if (i <= n && num[point[i].x] > maxn) pp[point[i].x].push_back(point[i]); if (point[i].x != point[i - 1].x) { int r = i - 1; if (num[point[i - 1].x] <= maxn) { for (int i = l; i < r; i++) for (int j = i + 1; j <= r; j++) { int len = point[j].y - point[i].y; if (check(point[i].x + len, point[i].y, 1) && check(point[j].x + len, point[j].y, 1)) ans++; if (check(point[i].x - len, point[i].y, maxn) && check(point[j].x - len, point[j].y, maxn)) ans++; } } l = i; } } int m = 0; for (int i = 0; i <= 100000; i++) if (num[i] > maxn) which[++m] = i; for (int i = 1; i <= m - 1; i++) for (int j = i + 1; j <= m; j++) for (it = pp[which[i]].begin(); it != pp[which[i]].end(); it++) { int len = which[j] - which[i]; int x = (*it).x, y = (*it).y; if (check(x, y + len, 0) && check(x + len, y + len, 0) && check(x + len, y, 0)) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; void RI() {} template <typename... T> void RI(int& head, T&... tail) { scanf("%d", &head); RI(tail...); } int n; pair<int, int> p[100010]; vector<int> vx[100010], vy[100010]; inline bool has(int x, int y) { return binary_search(p, p + n, make_pair(x, y)); } inline bool has(const vector<int>& v, int x) { return binary_search(begin(v), end(v), x); } int main() { RI(n); for (int i = 0; i < int(n); i++) RI(p[i].first, p[i].second); sort(p, p + n); int ans = 0; for (int i = 0; i < int(n); i++) { int x = p[i].first, y = p[i].second, d = x - y; if (((int)(vx[x]).size()) < ((int)(vy[y]).size())) { for (auto it = (vx[x]).begin(); it != (vx[x]).end(); it++) if (has(vy[y], *it + d) && has(*it + d, *it)) ans++; } else { for (auto it = (vy[y]).begin(); it != (vy[y]).end(); it++) if (has(vx[x], *it - d) && has(*it, *it - d)) ans++; } vx[x].push_back(y); vy[y].push_back(x); } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; const long long N = 1e5 + 10; unordered_set<long long> xx[N]; unordered_set<long long> yy[N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; long long x[n + 1], y[n + 1]; for (long long i = 0; i < n; i++) { cin >> x[i] >> y[i]; xx[x[i]].insert(y[i]); yy[y[i]].insert(x[i]); } long long ans = 0; for (long long i = 0; i < n; i++) { if (xx[x[i]].size() < yy[y[i]].size()) { for (auto to : xx[x[i]]) if (to != y[i]) { long long len = abs(y[i] - to); long long xU = x[i] - len; long long xD = x[i] + len; if (xU >= 0) { if (yy[y[i]].find(xU) != yy[y[i]].end() && yy[to].find(xU) != yy[to].end()) ans++; } if (yy[y[i]].find(xD) != yy[y[i]].end() && yy[to].find(xD) != yy[to].end()) ans++; } } else { for (auto to : yy[y[i]]) if (to != x[i]) { long long len = abs(x[i] - to); long long xU = y[i] - len; long long xD = y[i] + len; if (xU >= 0) { if (xx[x[i]].find(xU) != xx[x[i]].end() && xx[to].find(xU) != xx[to].end()) ans++; } if (xx[x[i]].find(xD) != xx[x[i]].end() && xx[to].find(xD) != xx[to].end()) ans++; } } } cout << ans / 4 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100001; bool heavy[N]; vector<int> x[N], y[N]; bool check(int xx, int yy) { return binary_search(x[xx].begin(), x[xx].end(), yy); } int main() { int n, ans = 0; cin >> n; int mx = (int)sqrt(n + .0); for (int i = 0; i < n; i++) { int px, py; cin >> px >> py; x[px].push_back(py); } for (int i = 0; i < N; i++) { sort(x[i].begin(), x[i].end()); if (x[i].size() >= mx) heavy[i] = 1; } for (int i = 0; i < N; i++) if (!heavy[i]) for (int j = 0; j < x[i].size(); j++) for (int k = j + 1; k < x[i].size(); k++) { int y1 = x[i][j], y2 = x[i][k], d = y2 - y1; if (check(i + d, y1) && check(i + d, y2)) ans++; if (i >= d && heavy[i - d] && check(i - d, y1) && check(i - d, y2)) ans++; } else for (int j = 0; j < x[i].size(); j++) y[x[i][j]].push_back(i); for (int i = 0; i < N; i++) for (int j = 0; j < y[i].size(); j++) for (int k = j + 1; k < y[i].size(); k++) { int x1 = y[i][j], x2 = y[i][k], d = x2 - x1; if (heavy[x1] && heavy[x2] && check(x1, i + d) && check(x2, i + d)) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> row[105000]; vector<int> col[105000]; vector<pair<int, int> > pt; int n; int findIndex(vector<int> &v, int k) { int s = 0, e = v.size() - 1; while (s <= e) { int mid = (s + e) / 2; if (v[mid] == k) return mid; if (v[mid] < k) s = mid + 1; else e = mid - 1; } while (true) ; } bool found(int x, int y) { int s = 0, e = pt.size() - 1; pair<int, int> toFind = make_pair(x, y); while (s <= e) { int mid = (s + e) / 2; if (toFind == pt[mid]) return true; if (toFind < pt[mid]) e = mid - 1; else s = mid + 1; } return false; } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { int x, y; scanf("%d %d", &x, &y); row[x].push_back(y); col[y].push_back(x); pt.push_back(make_pair(x, y)); } for (int i = 0; i <= 100000; ++i) { if (row[i].size()) sort(row[i].begin(), row[i].end()); if (col[i].size()) ; sort(col[i].begin(), col[i].end()); } sort(pt.begin(), pt.end()); int ans = 0; for (int i = 0; i < n; ++i) { pair<int, int> cur = pt[i]; int indexY = findIndex(col[cur.second], cur.first); int indexX = findIndex(row[cur.first], cur.second); indexX++; indexY++; while (indexX < row[cur.first].size() && indexY < col[cur.second].size()) { if (row[cur.first][indexX] - cur.second == col[cur.second][indexY] - cur.first) { if (found(col[cur.second][indexY], row[cur.first][indexX])) ans++; indexX++; indexY++; } else if (row[cur.first][indexX] - cur.second < col[cur.second][indexY] - cur.first) indexX++; else indexY++; } } printf("%d\n", ans); }
#include <bits/stdc++.h> using namespace std; struct st { int x, y; bool operator<(const st& B) const { return x < B.x || (x == B.x && y < B.y); } } a[100005]; int N, M; set<long long> F[100005]; void ins(int x, int y) { F[x].insert(y); } bool find(int x, int y) { if (x < 0 || x > 1e5) return 0; set<long long>::iterator p = F[x].lower_bound(y); return p != F[x].end() && *p == y; } void init() { scanf("%d", &N), M = sqrt(N) + 1; for (int i = 1; i <= N; i++) scanf("%d%d", &a[i].x, &a[i].y), ins(a[i].x, a[i].y); sort(a + 1, a + N + 1); } void doit() { int ans = 0; for (int i = 1, j, d; i <= N; i = j) { for (j = i; j <= N && a[j].x == a[i].x; j++) ; if (j - i <= M) for (int k = i; k < j; k++) for (int l = k + 1; l < j; l++) d = a[l].y - a[k].y, ans += find(a[k].x - d, a[k].y) && find(a[l].x - d, a[l].y); else for (int k = 1; k < i; k++) d = a[i].x - a[k].x, ans += find(a[i].x, a[k].y) && find(a[i].x, a[k].y + d) && find(a[k].x, a[k].y + d); } printf("%d\n", ans); } int main() { init(); doit(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; map<pair<int, int>, bool> M; int n, sol; vector<int> row[N], col[N]; int main() { cin >> n; for (int x, y, i = 0; i < n; ++i) { cin >> x >> y; M[make_pair(x, y)] = 1; row[x].push_back(y); col[y].push_back(x); } for (int i = 0; i < N; ++i) { sort(row[i].begin(), row[i].end()); sort(col[i].begin(), col[i].end()); } for (int i = 0; i < N; ++i) { int sza = row[i].size(); for (int j = 0; j < sza; ++j) { int y = row[i][j], k1 = j; int k2 = lower_bound(col[y].begin(), col[y].end(), i) - col[y].begin(); int szb = col[y].size(); while (k1 < sza && k2 < szb) { if (row[i][k1] - y < col[y][k2] - i) k1++; else if (row[i][k1] - y > col[y][k2] - i) k2++; else { if (row[i][k1] != y && col[y][k2] != i && M[make_pair(col[y][k2], row[i][k1])] == 1) sol++; k1++; k2++; } } } } cout << sol; }
#include <bits/stdc++.h> using namespace std; pair<int, int> p[111111]; vector<int> row[111111], col[111111]; map<pair<int, int>, bool> mp; int main() { int n, res = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &p[i].first, &p[i].second); } sort(p, p + n); for (int i = 0; i < n; i++) { int x = p[i].first, y = p[i].second; if (row[y].size() <= col[x].size()) { for (int x2 : row[y]) if (mp[{x2, y - (x - x2)}] and mp[{x, y - (x - x2)}]) res++; } else { for (int y2 : col[x]) if (mp[{x - (y - y2), y}] and mp[{x - (y - y2), y2}]) res++; } row[y].push_back(x); col[x].push_back(y); mp[{x, y}] = true; } printf("%d", res); return 0; }
#include <bits/stdc++.h> using namespace std; int n; unordered_set<long long int> db; vector<int> X[100001]; vector<int> Y[100001]; int main() { scanf("%d", &n); long long int ans = 0; for (int i = 0; i < (int)(n); i++) { int x, y; scanf("%d %d", &x, &y); if (X[x].size() < Y[y].size()) { for (int i = 0; i < (int)(X[x].size()); i++) { int dy = X[x][i]; int l = dy - y; if (db.count((((long long int)x + l << 20) | (y))) && db.count((((long long int)x + l << 20) | (dy)))) ans++; if (db.count((((long long int)x - l << 20) | (y))) && db.count((((long long int)x - l << 20) | (dy)))) ans++; } } else { for (int i = 0; i < (int)(Y[y].size()); i++) { int dx = Y[y][i]; int l = dx - x; if (db.count((((long long int)x << 20) | (y + l))) && db.count((((long long int)dx << 20) | (y + l)))) ans++; if (db.count((((long long int)x << 20) | (y - l))) && db.count((((long long int)dx << 20) | (y - l)))) ans++; } } X[x].push_back(y); Y[y].push_back(x); db.insert((((long long int)x << 20) | (y))); } cout << ans << endl; return 0; }