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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

51nod 1682

發(fā)布時(shí)間:2023/12/20 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 51nod 1682 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

原題鏈接

顯然由題意描述可知(所有數(shù)皆是獨(dú)一無二的),所有符合條件的區(qū)間皆為奇數(shù)長度的區(qū)間。

對于一個(gè)區(qū)間(l,r),定義up為區(qū)間內(nèi)大于x的數(shù)的個(gè)數(shù),down為小于x的數(shù)的個(gè)數(shù),若x為中位數(shù)則有up(x)=down(x),cnt[x]表示up-down=x的區(qū)間有多少個(gè)。

假設(shè)x在區(qū)間(l,r)中的位置為pos,x為中位數(shù)則要滿足在(l,pos-1)中up-down=在(pos+1,r)中down-up。

每次枚舉一個(gè)數(shù)a[i],統(tǒng)計(jì)在區(qū)間(l,i)內(nèi)up和down的值并更新cnt[up-down]的值,并不斷向左擴(kuò)展l,右區(qū)間也同樣操作。

#include<map> #include<set> #include<list> #include<cmath> #include<ctime> #include<queue> #include<stack> #include<cstdio> #include<string> #include<bitset> #include<vector> #include<utility> #include<numeric> #include<cstring> #include<iterator> #include<iostream> #include<algorithm> #include<functional> using namespace std; #define fi first #define se second #define MP make_pair #define ll long long #define PR pair<ll,ll> #define LS (root<<1) #define RS ((root<<1)|1) #define LSON LS,l,mid #define RSON RS,(mid+1),r #define MID mid=((l+r)/2) #define mm(a,b) memset(a,b,sizeof(a)) #define rep(a,b,c) for(int a=b;a<c;a++) #define INF 0x3f3f3f3f3f3f3f3f #define eps 1e-9 #define Pi acos(-1.0) #define MAXN 8005 #define MAXE 3000050 #define Inf 9999999 #define debug puts("**************"); template<class T> T f_max(T a, T b){ return a > b ? a : b; } template<class T> T f_min(T a, T b){ return a < b ? a : b; } template<class T> T f_abs(T a){ return a > 0 ? a : -a; } template<class T> T gcd(T a, T b){ return b ? gcd(b, a%b) : a; } template<class T> T lcm(T a, T b){ return a / gcd(a, b)*b; } const int mod=1000007; int n; int a[MAXN]; int cnt[2*MAXN]; int main(){int T, cas=1;int ans=0;while(~scanf("%d",&n)){for(int i=1;i<=n;i++){scanf("%d",&a[i]); // b[i]=a[i];}for(int i=1;i<=n;i++){ans=0; mm(cnt,0);int up, down;up=down=0;cnt[8000]++;for(int j=i-1;j>=1;j--){ //向左擴(kuò)展if(a[j]>a[i]) up++;if(a[j]<a[i]) down++;cnt[down-up+8000]++;}up=down=0;for(int j=i;j<=n;j++){ //向右擴(kuò)展if(a[j]>a[i]) up++;if(a[j]<a[i]) down++;ans+=cnt[up-down+8000];}printf("%d%c",ans,i==n?'\n':' ');}}return 0; }


總結(jié)

以上是生活随笔為你收集整理的51nod 1682的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。