HDU 6406 Taotao Picks Apples (2018 multi-university Training Contest 8 1010) (binary, prefix and)

Source: Internet
Author: User

Links: http://acm.hdu.edu.cn/showproblem.php?pid=6406

Ideas:

Violence, preprocessing three prefixes and: "1,n" peach will be removed, 1 to the current point maximum, 1 to the current point of the number of peaches removed, and then we enumerate to modify the P point caused by all the effects:

1, if the new input point is larger than the original point value, then we have modified p this point and "1,p-1" the maximum value of the relationship analysis, that is, the impact of the first half of the analysis: (1) If P-point is greater than the maximum value of 1-p-1, we directly use the prefix and O (1) to get "1,p-1" How many peaches have been removed and then added to the current one. (2) If the P-point is less than or equal to the maximum value of "1,p-1", the first half and the second half of the paragraph will not be affected, the direct output preprocessing to the "1,n" value is good; then we analyze the effect of the second half: (1) If the P-point is greater than the maximum value of "1,p-1", Then only the second half of the peach removed will be affected, we directly two points to find the "p+1,n" in the value of the removed Peach is greater than the value of the modified C subscript, minus a bit, the second half of the peach will be taken off a few in the P point is modified still need to take off, It would be nice to add the value of the second half to the value of the first half of the paragraph. (2) If P point is less than or equal to the maximum value of "1,p-1", then the second half is not affected,

2. If the new input point is less than or equal to the original point value, the value of the modified P point and the maximum value of "1,p-1" are analyzed: first, the effect of the first half: (1) If P-point is greater than the maximum value of 1-p-1, we use prefix and O (1) to get "1,p-1" How many peaches are removed , then add the current one. (2) If P-point is less than or equal to the maximum value of "1,p-1", then this point is still not affected by the first half, the value of the first half is equal to the number of peaches removed in "1,p-1",

The next most difficult part of the discussion is:

Before processing here the idea was stuck for a long time: (1) If P-point is greater than the maximum value of 1-p-1

Because the current point becomes smaller, the effect on the back point is to remove some of the peaches that would not have been picked, then how to determine the specific peach is those? In fact, we can launch, these multi-picking peaches are only less than p in the 1 to the current coordinates, because these numbers are when p becomes smaller and more, then they must be at 1 to the current point is only less than P point, then we add it to the previous dimension of P Vecvector array, as to how to find these values, We just need to maintain a second-largest value, and these second-largest values are peaches that are likely to pick more. When P-point is a peach that was originally picked, we found the value in the presence of v[p] to find the value that is larger than the P-value modification, which is the new value of the second half, plus the original value to be picked.

(2) If less than equals, it still does not affect, go directly to the prefix and just fine

3, assuming that the input point is the same as the original point value, the direct prefix and

This is a total of five main cases: two with a binary O (Logn), the other three direct prefixes and O (1), a little calculation will not time out. Finally ran 405ms, the topic gave 2000mS, run quickly, is to achieve a bit complex, there should be a better solution, but the game did not think so much, direct violence rash passed, or better than the code to be changed to vomit. Qaq

Implementation code:

#include <bits/stdc++.h>using namespacestd;Const intM = 1e5+Ten;structnode{intId,val;}; Vector<int>V[m];intA[m],ans[m],maxx[m],b[m],arr[m];intMain () {intT,n,q,p,c; scanf ("%d",&t);  while(t--) {scanf ("%d%d",&n,&q);  for(inti =1; I <= N;i + +) {scanf ("%d",&A[i]);        } node Mx,mx1; Mx.val=0; Mx1.val =0, mx.id =0, mx1.id =0; intCNT =0, num =0; maxx[0] =0;  for(inti =1; I <= N;i + +){            if(Mx.val <A[i]) {Mx1.val= Mx.val; Mx1.id =mx.id; Mx.val= A[i]; Mx.id = i; b[cnt++] =A[i]; Num++; }            Else if(Mx1.val <A[i]) {Mx1.val= A[i]; Mx1.id =i;            V[mx.id].push_back (A[i]); } Maxx[i]= Mx.val; Ans[i] =num; }         while(q--) {scanf ("%d%d",&p,&c); intsum =0; if(C >A[p]) {                if(C > maxx[p-1]) {sum++; Sum + = ans[p-1]; intKK = Upper_bound (b,b+cnt,c)-b; if(KK! = cnt) sum + = cnt-KK; }                Elsesum=Ans[n]; }            Else if(c = = A[p]) sum =Ans[n]; Else{                if(C > maxx[p-1]) Sum++,sum + = ans[p-1]; ElseSum + = ans[p-1]; if(A[p] = =Maxx[p]) {                     intKK = Upper_bound (V[p].begin (), V[p].end (), c)-V[p].begin (); Sum+ = V[p].size ()-KK; intKK1 = Upper_bound (B,b+cnt,a[p])-b; if(KK1! = cnt) sum + = cnt-Kk1; }                Elsesum=Ans[n]; } printf ("%d\n", sum); }         for(inti =0; I <= N;i + +) {Maxx[i]=0; Ans[i] =0; V[i].clear (); }         for(inti =0; I <= cnt;i + +) B[i] =0; }    return 0;}

HDU 6406 Taotao Picks Apples (2018 multi-university Training Contest 8 1010) (binary, prefix and)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.