916 & simulation game about half the tree line summary

1 exam time and made a fatal mistake, not to think about the positive solution of T2 but to the simple push of a formula began the long road to find the law, should not do so in order to get the law although violence but still hit I played some unnecessary procedures such as the number of combinations seeking something more waste of time.

After the examination, in my opinion this is a waste of time wasted I actually avoided a full 1h30min not a question of positive solutions go look are done and then come back to re-examine this question.

Positive Solutions of push time 2 T3 is not long but did not think carefully about their approach is excellent although it should be correct, but not enough to make me think the code becomes very tedious.

For example, some sections of the summing operation I can take a direct deal with a good array of prefixes and suffixes and beg but I wrote two tree line function sum. Obviously you can not segment tree O (n) to write code complexity would be very low, but I do not think the full code directly on the tree line ...

Of course, there are advantages of T1 after the start finish straight to take this point very well (it took 20,000 sets of data so I did not check how directly pay.

Then discuss solution to a problem when I hope that this problem is not just thinking of the exam as well as a summary of the tree line, I think I should summarize some of the features of the tree line is how to write up can not always write when they are pushed again .

Binary tree line and is a useful technique because of its use of interval itself is half in the form of trees and built natively supports most features of the query interval value is the result that we are looking for a more convenient value.

Here to give the title sequence for a given background asking who seek x x less than the entire sequence of the first position is?

The violence we can actually sweep but repeatedly asked it? The inquiry is offline descending out, by force it? A more classic approach is ST + binary sequence not seem monotonous, but we half the length of the answer sheet ST to be looking for the most value can be solved.

Take a single-point amend it? ST table but can not be modified, then half of the tree line at this time can easily solve this problem.

We consider first enter the segment tree observe whether the overall greater than x, then it would not then observed the left and then to the left or to the right to engage in recursive.

Lr how to engage in a confined space and thinking this is the code difficult to upgrade fact, we found that this is not a good thing but it is also written on the use of the tree line in spite of very sleepy.

In fact, for this one we can ask is looking for a fixed l rr r belong to. But obviously that is not what defines the r meaning we can find in the left where r and r than it is of no use. Here we can still continue to put the code in section two.

Specifically still found the equivalent of two endpoints or a range and complexity logn;

code:

inline int ask(int p,int l,int r,int L,int x)//求 L R里第一个<=x的数字
{
    if(sum(p)<=x)return r;
    if(l==r)return l-1;
    int mid=(l+r)>>1;
    if(l>=L)
    {
        if(sum(l(p))<=x)return ask(r(p),mid+1,r,L,x);
        return ask(l(p),l,mid,L,x);
    }
    if(L>mid)return ask(r(p),mid+1,r,L,x);
    int w=ask(l(p),l,mid,L,x);
    if(w==mid)
    {
        if(sum(r(p))<=x)return r;
        return ask(r(p),mid+1,r,L,x);
    }
    return w;
}

This is commonly used to write the board to have some understanding of the segment tree complexity logn may find that we actually first found the left point Zaixun find the right point so find the equivalent of a range.
Of course, not very complicated to find global answers all the more easier. It is noteworthy that due to the lookup is <= x So we sum is the maximum interval recording.

Guess you like

Origin www.cnblogs.com/chdy/p/11531364.html