CF1400D Zigzags(刻骨铭心的失误,又一次上分失败)
#include<bits/stdc++.h> using namespace std; const int maxn=3005; typedef long long ll; int t; int a[maxn]; ll c[maxn][maxn]; int n; int main () { int t; scanf("%d",&t); while (t--) { scanf("%d",&n); for (int i=0;i<=n;i++) for (int j=0;j<=n;j++) c[i][j]=0; for (int i=1;i<=n;i++) scanf("%d",a+i); for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) { if (j==a[i]) c[i][j]=c[i-1][j]+1; else c[i][j]=c[i-1][j]; } } ll ans=0; for (int i=1;i<=n;i++) { for (int j=i+1;j<=n;j++) { ans+=(c[i-1][a[j]]-c[0][a[j]])*(c[n][a[i]]-c[j][a[i]]); } } printf("%lld\n",ans); } }