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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

HDOJ 5147 Sequence II 树阵

發布時間:2025/3/21 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDOJ 5147 Sequence II 树阵 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


樹陣:

每個號碼的前面維修比其數數少,和大量的這后一種數比他的數字

再枚舉每一個位置組合一下?

Sequence II

Time Limit: 5000/2500 MS (Java/Others)????Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 121????Accepted Submission(s): 58


Problem Description Long long ago, there is a sequence A with length n. All numbers in this sequence is no smaller than 1 and no bigger than n, and all numbers are different in this sequence.
Please calculate how many quad (a,b,c,d) satisfy:
1.?1a<b<c<dn
2.?Aa<Ab
3.?Ac<Ad
Input The first line contains a single integer T, indicating the number of test cases.
Each test case begins with a line contains an integer n.
The next line follows n integers?A1,A2,,An.

[Technical Specification]
1 <= T <= 100
1 <= n <= 50000
1 <=?Ai?<= n
Output For each case output one line contains a integer,the number of quad.
Sample Input 1 5 1 3 2 4 5
Sample Output 4
Source BestCoder Round #23


/* *********************************************** Author :CKboss Created Time :2014年12月20日 星期六 21時38分00秒 File Name :HDOJ5147.cpp ************************************************ */#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map>using namespace std;typedef long long int LL;const int maxn=55000;int a[maxn]; int n;LL sum1[maxn],sum2[maxn]; int t1[maxn],t2[maxn];int lowbit(int x) { return x&(-x); }/// 1 找比當前數小的 2 找比當前數大的void init() {memset(sum1,0,sizeof(sum1));memset(sum2,0,sizeof(sum2));memset(t1,0,sizeof(t1));memset(t2,0,sizeof(t2)); }void add(int kind,int p) {if(kind==1) for(int i=p;i<maxn;i+=lowbit(i)) t1[i]+=1;else if(kind==2) for(int i=p;i;i-=lowbit(i)) t2[i]+=1; }int sum(int kind,int p) {int ret=0;if(kind==1) for(int i=p;i;i-=lowbit(i)) ret+=t1[i];else if(kind==2) for(int i=p;i<maxn;i+=lowbit(i)) ret+=t2[i];return ret; }int main() {//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int T_T;scanf("%d",&T_T);while(T_T--){scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",a+i);init();/// from left to rightfor(int i=1;i<=n;i++){int ss=sum(1,a[i]);sum1[i]=ss;add(1,a[i]);}/// from right to leftfor(int i=n;i>=1;i--){int ss=sum(2,a[i]);sum2[i]=sum2[i+1]+ss;add(2,a[i]);}LL ans=0;for(int i=2;i<=n-1;i++){/// X...i i+1...Xans+=sum1[i]*sum2[i+1];}cout<<ans<<endl;}return 0; }


版權聲明:本文博客原創文章,博客,未經同意,不得轉載。

總結

以上是生活随笔為你收集整理的HDOJ 5147 Sequence II 树阵的全部內容,希望文章能夠幫你解決所遇到的問題。

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