日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Educational Codeforces Round 94 (Rated for Div. 2) D(思维)

發布時間:2023/12/3 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Educational Codeforces Round 94 (Rated for Div. 2) D(思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目:
You are given an array a1,a2…an. Calculate the number of tuples (i,j,k,l) such that:

1≤i<j<k<l≤n;
ai=ak and aj=al;
Input
The first line contains a single integer t (1≤t≤100) — the number of test cases.

The first line of each test case contains a single integer n (4≤n≤3000) — the size of the array a.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n) — the array a.

It’s guaranteed that the sum of n in one test doesn’t exceed 3000.

Output
For each test case, print the number of described tuples.

Example
inputCopy
2
5
2 2 2 2 2
6
1 3 3 1 2 3
outputCopy
5
2
Note
In the first test case, for any four indices i<j<k<l are valid, so the answer is the number of tuples.

In the second test case, there are 2 valid tuples:

(1,2,4,6): a1=a4 and a2=a6;
(1,3,4,6): a1=a4 and a3=a6.

題目大意: 找到滿足條件的所有組合
1≤i<j<k<l≤n;
ai=ak and aj=al;

思路 :枚舉j和l,然后用num來統計 j到l 有多少種組合。
cnt數組 記錄好 j下標前面 出現過多少次這個數。
因為數據比較小,直接o(n^2).

#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <iostream> #include <algorithm> #include <queue> #include <cstdlib> #include <stack> #include <vector> #include <set> #include <map> #include <bitset> #define INF 0x3f3f3f3f3f3f3f3f #define inf 0x3f3f3f3f #define FILL(a,b) (memset(a,b,sizeof(a))) #define re register #define lson rt<<1 #define rson rt<<1|1 #define lowbit(a) ((a)&-(a)) #define ios std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0); #define fi first #define rep(i,n) for(int i=0;(i)<(n);i++) #define rep1(i,n) for(int i=1;(i)<=(n);i++) #define se secondusing namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pii; const ll mod=998244353; const ll N =3e6+10; const double eps = 1e-5; const double pi=acos(-1); ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);} int dx[4]= {-1,0,1,0}, dy[4] = {0,1,0,-1}; ll n,cnt[10005],a[10005],res,num;void solve() {cin>>n;res=0;memset(cnt,0,sizeof(cnt));for(int i=1;i<=n;i++){cin>>a[i];}for(int j=1;j<n;j++){num=0;for(int l=j+1;l<=n;l++){if(a[j]==a[l]){res+=num;}num+=cnt[a[l]];}cnt[a[j]]++;}cout<<res<<endl; } int main() {iosint T;cin>>T;//T=1;while(T--){solve();}return 0; } 創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的Educational Codeforces Round 94 (Rated for Div. 2) D(思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。