Codefest 2019 Tournament Summary

A XORinacci

\(a,b,a\oplus b,a,b,a\oplus b,\ldots\)

B Uniqueless

Using two-pointer, after the prefix, and the optimization judgment \ (O (n-) \) , the time complexity \ (O (n ^ 2) \)

D Restore Permutation

Determining from the forward, current demand \ (P_i \) , known \ (\ {p_1, p_2, \ ldots, p_i \} \) and \ (S_I \) , a line segment can be obtained by binary tree \ (P_i \ ) , after the \ (p_i \) be deleted from the segment tree. Time complexity \ (O (n-\ log n-) \) .

E Let them Slide

For a number of columns \ (A [. 1, L] \) , wherein the maximum value is set \ (A [P] \) , then \ ([p, p + wl ] \) contribution to this interval \ ( a [P] \) , in \ ([1, p-1 ] \) this interval \ (I \) contribute to the \ (\ max \ limits_ {j \ in [\ max (1, i-w L +), I]} a_j \) , \ ([P-L + W +. 1, W] \) this interval \ (I \) contribution \ (\ max \ limits_ {j \ in [i , \ min (W, WL + I)]} a_j \) , in particular, to consider the possibility of a point without \ (I \) , as well as \ (a [p] <0 \) case need to consider the special intermediate this \ ([the p-, the p-+ WL] \) (other contributions to 0). This takes \ (\ max \) operation can be calculated using the monotonous queue.

Since \ ([p, p + wl ] \) of this section is very large, so you can make a global tag, the number indicates how many all together.

Then add a bunch of judgmentAnd pay attention to the signIt can be passed.

#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 1000003;
int n, w, l, a[N], p, q[N], front, rear;
LL all, ans[N]; 
int main(){
    scanf("%d%d", &n, &w);
    for(Rint i = 1;i <= n;i ++){
        scanf("%d", &l); p = 1;
        for(Rint j = 1;j <= l;j ++){
            scanf("%d", a + j);
            if(a[j] > a[p]) p = j;
        }
        if(a[p] < 0){
            if(w >= 2 * l) continue;
            int tmp = w - l; front = rear = 0;
            for(Rint i = 1;i <= tmp;i ++){
                while(front < rear && a[q[rear - 1]] <= a[i]) -- rear;
                q[rear ++] = i;
            }
            for(Rint i = tmp + 1;i <= l;i ++){
                while(front < rear && q[front] < i - tmp) ++ front;
                while(front < rear && a[q[rear - 1]] <= a[i]) -- rear;
                q[rear ++] = i;
                ans[i] -= a[q[front]];
            }
            continue;
        }
        all += a[p];
        int tmp = w - l; front = rear = 0;
        for(Rint i = 1;i <= p - 1;i ++){
            while(front < rear && q[front] < i - tmp) ++ front;
            while(front < rear && a[q[rear - 1]] <= a[i]) -- rear;
            q[rear ++] = i;
            if(i <= tmp) ans[i] += min(a[p], a[p] - a[q[front]]);
            else ans[i] += a[p] - a[q[front]];
        }
        front = rear = 0;
        for(Rint i = w;i > p + tmp;i --){
            while(front < rear && q[front] > i) ++ front;
            while(front < rear && a[q[rear - 1]] <= a[i - tmp]) -- rear;
            q[rear ++] = i - tmp;
            if(i > l) ans[i] += min(a[p], a[p] - a[q[front]]);
            else ans[i] += a[p] - a[q[front]];
        }
    }
    for(Rint i = 1;i <= w;i ++)
        printf("%I64d ", all - ans[i]);
}

C Magic Grid

All in accordance with the number \ (x >> 4 \) classification, filled into \ (\ frac {n} { 4} \ times \ frac {n} {4} \) of the matrix, a class \ (16 \) fill into a number of squares, each square is the matrix of the sample 1. So that \ (8 | n \) when every row and column is 0, otherwise every row as 13.

F Bits And Pieces

First of all fixed \ (a_i \) , and then from high to low test answers, this one can fill 1 if and only if \ (a_i \) This bit is 1 or current answer \ (x \) is a superset of the \ (a_i \) on the right there are at least two numbers.

Consider the pretreatment \ (X \) rightmost superset two subscripts. This can be done by FMT, it is specific for each ([0,2 ^ {21}) \) \ in a number of maintenance pair, maintaining the value \ (X \) is the rightmost two subscripts. Then combined into a pair FMT addition operation (a pair of two numbers add another pair) on it. After the above conditions can be easily judged.

Time complexity \ (O ((n + m ) \ log m) \)

G Polygons

First, we know, it will certainly be a fixed point, all of the regular polygon should use this point.

Second, if filled out a positive \ (x \) gon, then \ (x \) of all divisors of a regular polygon must be filled in. With respect to (X \) \ all divisors (excluding \ (X, 1,2 \) ) is a regular polygon, n \ (X \) polygons to multi \ (\ varphi (x) \ ) th point. Therefore, considered in the \ ([1, n] \ ) for all \ (\ varphi \) values are sorted, and then taking the smallest \ (K \) th, and we know that \ (d | x \) then \ (\ varphi ( D) \ Le \ varphi (X) \) , this condition is satisfied.

Note that a positive determination out regular polygon and the polygon 2. Time complexity \ (O (n-\ log n-) \) .

H Red Blue Tree

This question is too difficult ♂, only 2min film countdown cut off tourist this problem.

Guess you like

Origin www.cnblogs.com/AThousandMoons/p/11412734.html