原题链接
- 题意:给出 (n) 个数 (a_1, a_2, a_3···a_n)求问有多少个四元组 ((i,j,k,l)),使得这个四元组满足下列条件:(1 leqslant i < j < k leqslant l)。
- 题解:就是枚举中间的两个 (j,k),真的就是没有想到。
- 代码:
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 3333;
int a[N];
int sum[N][N];
void solve() {
int n;cin >> n;
ll ans = 0;
for (int i = 1; i <= n; i ++)cin >> a[i];
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
sum[i][j] = sum[i-1][j];
if (j == a[i])sum[i][j]++;
}
}
for (int i = 1; i <= n; i ++) {
for (int j = i + 1; j <= n; j ++) {
ans += (sum[i-1][a[j]] *(sum[n][a[i]] - sum[j][a[i]]));
}
}
cout << ans << endl;
}
int main() {
int t;cin >> t;
while (t--) {
solve();
}
}