2019 Summer Hang two day3 test summary

Foreword

Day3 actually took the test three to + discrete segment tree, it is a special data structure? Although I have come up with a positive solution, but still made some mistakes sucker.

T1

Subject to the effect

Given a white straight line, there are \ (n-\) operations, each time the \ (l, r \) which dyed black section, as well as how many answers after dyed black line \ ((0 <= n <10 = ^ * 2. 5, -10. 9 ^ <= L <= R & lt <= 10 ^. 9) \) .

sol

After the interval with a discrete segment tree maintenance, maintenance intervals how many segments each segment, as well as about whether beyond the range, a large number of segments of the first interval equal to the number of segments and around the interval, if the interval left to right and right to left interval We are exceeded, indicating that there is a line connecting the left and right of it, minus a number of segments.

T2

Subject to the effect

In the shaft there is a number (n-\) \ point, the \ (I \) points coordinates \ (XI \) . There \ (m \) operations, each operation is either of the following:

  1. \ (p, y \) represents the initial labeled \ (P \) coordinates of the points to \ (Y \) .
  2. \ (l, r \) represents the calculated \ (\ sum_ {L <= x_i <= x_j <= L} (x_j-x_i) \) .

    sol

    The same answer for maintenance segment tree each segment interval, \ (X \) the sum of the number of points, \ (ans_p ans_ = {P <<. 1} + {P << ans_. 1 |. 1 sum_ {P} + < <. 1 | cnt_. 1} * {P} -sum_ <<. 1. 1} * {P << <<. 1 cnt_ {P |. 1} \) , \ (X \) the number of points and is better and maintenance.
    I made some mistakes in this topic, I wrote a quick read only read positive number, the results did not over-sample, also tune for a long time. Then I was lazy, did not discrete, direct dynamic open point, the array is still open is \ (nlog (the n-) \) , not \ (nlog (w) \) , RE 40 points. Size of the array or to take the count.

    T3

    T3 test team measured the previous original title, was quite simple.

    Subject to the effect

    Direct pasted:
    Elf Bsny community where there are n number of residents, each resident has a certain status and age, ri represents the i personal position, ai represents the i individual's age.
    Recently community to hold events, requiring several people into a team, a team must have a captain, to be the captain of such a condition:
  3. Captain position in the group should be the highest (can be tied for first);
  4. Team captain of the age gap between age and the other members can not exceed K.

Some people want to own close group of people in the same group, while the group of people where the hope of better. For example, x and y want to be in the same group, small group of people and hope they are located, the better, of course, they must choose a captain meet the above requirements, then ask you to include both group x and y,
up how many people group?

sol

First sort position, then aged discrete, you can use Fenwick tree will captain the team when everyone can have up to how many people deal with it.
code:

    sort(c+1,c+1+n);
    sort(p+1,p+1+n,cmp);
    cnt=unique(c+1,c+1+n)-c-1;
    for(int i=1;i<=n;i++)
    {
        if(p[i].r!=p[i-1].r)//a为年龄,r为地位
            for(;s<i;s++)
                f[s]=ask(ub(p[s].a+k)-1)-ask(lb(p[s].a-k)-1);
        add(lb(p[i].a));
//ask和add为树状数组,f为每个人当队长队内最多可以有多少人
    }
    for(;s<=n;s++)
        f[s]=ask(ub(p[s].a+k)-1)-ask(lb(p[s].a-k)-1);

After asking offline, press two status \ (max \) as a keyword in descending order, prior to processing each answer, they will position greater than or equal status \ (max \) people \ (f \) by that person the age of the tree is added to the segment, the segment processing directly answer the query tree to answer legal age range.
code:

    int j=n;
    for(int i=1;i<=Q;i++)
    {
        int x=q[i].r,y=q[i].a;//询问已经排过序
        while(j&&p[j].r>=p[x].r)change(1,1,cnt,lb(p[j].a),f[j]),j--;
        ans[q[i].id]=query(1,1,cnt,lb(max(p[x].a,p[y].a)-k),ub(min(p[x].a,p[y].a)+k)-1);
    }

Guess you like

Origin www.cnblogs.com/hht2005/p/11402663.html