It's another day's blast. 0!!!!!
Originally the first problem is very easy to do to optimize excessive
Lost the answer.
Put on a question first
1693:ksum
-
Time Limit
-
Ms
-
Memory Limit
-
524288 Kbytes
-
Judge
- Standard Judge
-
Solved
-
18
-
Submit
A
SubmitStatusDescription
Peter likes to play with arrays. Noip this day, he got a positive integer array of size n from Jason's hand.
Peter figured out all the sub-segments of the array and sorted the N (n+1)/2 numbers in descending order, and he wanted to know what the first k number was.
Input Format
The input file name is ksum.in.
The first line of the input data contains two integers n and K.
The next line contains n positive integers, which represent the array.
Output Format
The output file name is Ksum.out.
The number of output K, which represents the number of first k after descending, separated by a space.
Sample Input
INPUT13 3 4input23 310 2 7
Sample Output
output18 7 4 4output219 12 10
Hint
Test point number N≤k≤
1 100 5000
2 500 100000
3 1000 80000
4 1000 100000
5 10000 50000
6 20000 80000
7 50000 80000
8 100000 80000
9 100000 100000
10 100000 100000
For all data, meet AI≤10 9 k≤n (n+1)/2,n≤100000,k≤100000
Significant heap maintenance for a sequential sequence it must be a subset of this sequence of sub-values;
The heap top sequence is crammed into the heap by a subsequence of (l+1,r) && (l,r-1), respectively, each time the heap is removed
Heap maintenance can be noted that the process may occur repeated vertices with a hash table maintenance can be;
#include <cstdio>#include<iostream>#include<cstring>#include<cmath>#include<algorithm>#include<map>#include<vector>#defineMAXN 100010using namespacestd;structst{intL,r; Long Longsum;} mu[2*Maxn];typedef pair<int,int>Pa;map<PA,BOOL>Q1;intn,m,k,l,n1,i;intA[MAXN];voidDownintx) { intFa=X,son; while(fa*2<=N1) {Son=fa*2; if(mu[son+1].sum>mu[son].sum&&son+1<=N1) son++; if(mu[fa].sum>mu[son].sum) Break; Swap (Mu[fa],mu[son]); FA=Son; }}voidUpintx) { intfa,son=x; while(son/2) {FA=son/2; if(mu[fa].sum>mu[son].sum) Break; Swap (Mu[fa],mu[son]); Son=FA; }}voidPush (St x) {n1++; Q1[pa (X.L,X.R)]=1; MU[N1]=x; Up (N1);}intMain () {//freopen ("ksum.in", "R", stdin);//freopen ("Ksum.out", "w", stdout);scanf"%d%d",&n,&k); for(i=1; i<=n;++i) {scanf ("%d",&A[i]); mu[1].sum+=A[i]; } N1=1; mu[1].l=1; mu[1].R=N;Q1[PA (mu[1].l,mu[1].R)]=1; for(i=1; i<=k;++i) {printf ("%lld", mu[1].sum); if(mu[1].l<mu[1].R) {St Q; Q=mu[1]; Q.sum-=A[Q.L]; Q.L++; if(!Q1[pa (Q.L,Q.R)]) push (q); Q=mu[1]; Q.sum-=A[Q.R]; Q.R--; if(!Q1[pa (Q.L,Q.R)]) push (q); } mu[1]=mu[n1--]; Down (1); }}
20,151 in Training Day 5