Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <sstream>
- #include <set>
- #include <cmath>
- #include <bitset>
- #include <iomanip>
- #include <queue>
- #include <stack>
- #include <unordered_map>
- #include <map>
- #include <cstdio>
- #define mp make_pair
- #define pb push_back
- #define all(x) x.begin(), x.end()
- typedef long long ll;
- typedef unsigned long long ull;
- using namespace std;
- signed main() {
- int q;
- cin >> q;
- while (q--) {
- int n;
- cin >> n;
- vector<int> v(n);
- for (auto& x : v) {
- cin >> x;
- }
- vector<pair<map<int, int>, map<int, int>>> mass(n);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; j++) {
- if (i == j) continue;
- if(j < i)mass[i].first[v[i] - v[j]]++;
- if(j > i)mass[i].second[v[j] - v[i]]++;
- }
- }
- long long ans = 0;
- for (int i = 0; i < n; ++i) {
- long long cur_ans = 0;
- for (map<int, int>::iterator it = mass[i].first.begin(); it != mass[i].first.end(); ++it) {
- int k = it->first;
- if (mass[i].second.count(k) == 0) continue;
- cur_ans += (it->second * mass[i].second[k]);
- }
- ans += (cur_ans);
- }
- cout << ans << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement