Median count
Time limit:12000/6000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 909 Accepted Submission (s): 346
Problem description The median is defined as all values from small to large sorted back in the middle of the number, if the value has an even number, usually take the middle of the median two of the average number of values.
There are now n number, each number is unique, to find out how many of the intervals that contain it are the median.
Input multiple sets of test data
First Row one numbern(n≤8000)
Second line< Span id= "mathjax-span-13" class= "Mrow" >n number, 0 ≤ each number ≤ 109 ,
OutputThe number of N , in turn, indicates that the number of I is the median in the number of intervals containing it.
Sample Input51 2 3 4 5
Sample OUTPUT1 2 3 2 1
Source2016 "Baidu Star"-The first round (Astar round2b) idea: Enumerate each bit to find the number of median, will be greater than this number is set to 1, otherwise-1; Before and after the traversal to find greater than it or less than, the specific look at the code;
#include <bits/stdc++.h>using namespacestd;#definell __int64#defineMoD 1000000007#defineINF 999999999#definePi 4*atan (1)//#pragma COMMENT (linker, "/stack:102400000,102400000")Const intn=1e5+Ten, m=2*1e5+Ten;intA[n],b[n];ll Ans[n];intL[m];intR[m];intMain () {intx,y,z,i,t; intT; while(~SCANF ("%d",&x) {memset (ans,0,sizeof(ans)); for(i=1; i<=x;i++) scanf ("%d",&A[i]); for(i=1; i<=x;i++) { for(t=1; t<=x;t++) { if(a[t]==A[i]) b[t]=0; ElseB[t]=a[t]>a[i]?1:-1; } intflag=8000; for(t=i;t>0; t--) Flag+=b[t],l[flag]++; Flag=8000; for(t=i;t<=x;t++) Flag-=b[t],r[flag]++; for(t=0; t<=16010; t++) Ans[i]+ = (LL) l[t]*r[t],l[t]=r[t]=0; } for(i=1; i<=x;i++) printf ("%i64d%c", Ans[i], (i==x)?'\ n':' '); } return 0;}
Hdu 5701 Median counting idea problem