[2019.8.25]codeforces1208 Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)

Overview

Ranking: 304/6994

Over the number of questions: 5

Rating:\(\color{green}{+44}\)(\(\color{orange}{2147}\))

topic

A. XORinacci

AC Time: 5min, 490 points

answer:

First by considering bits.

For each one, if \ (F (0), F (1) \) is 0, then this one must be 0;

The remaining three are four-cycle. Direct judgment can be.

code:

#include<bits/stdc++.h>
using namespace std;
int T,a,b,n,ans;
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d",&a,&b,&n),ans=0;
        for(int i=1;i<=a||i<=b;i<<=1){
            if((a&i)&&(b&i))ans|=i*(n%3!=2);
            else if(a&i)ans|=i*(n%3!=1);
            else if(b&i)ans|=i*(n%3!=0);
        }
        printf("%d\n",ans);
    }
    return 0;
}

B.Uniqueness

AC Time: 14min, 944 min

answer:

Discrete, then the starting point enumeration, enumeration end. For the same start and end points can be directly transferred.

code:


#include<bits/stdc++.h>
using namespace std;
struct ST{
    int v,id;
}s[2010];
int n,a[2010],tmp,num[2010],t[2010],ans=1e9,tg=1,tt,mn;
bool cmp(ST x,ST y){
    return x.v<y.v;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",&s[i].v),s[i].id=i;
    sort(s+1,s+n+1,cmp);
    for(int i=1;i<=n;++i)tmp+=s[i].v!=s[i-1].v,a[s[i].id]=tmp,++num[tmp],tg&=(num[tmp]==1);
    if(tg)return puts("0"),0;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=tmp;++j)t[j]=num[j],tt+=t[j]>1;
        for(mn=i;mn<=n&&tt;++mn)--t[a[mn]],tt-=t[a[mn]]==1;
        if(!tt)ans=min(ans,mn-i);
    }
    printf("%d",ans);
    return 0;
}

C.Magic Grid

AC Time: 52min, 1188 points

(Pit death of me)

answer:

Two important properties:

For any non-negative integer \ (K \) , there are \ ((4k) xor (4k + 1) xor (4k + 2) xor (4k + 3) = 0 \)

Further, the non-negative integer \ (K \) and \ (0 \ Le P <. 4 \) , there are \ ((16k + p) xor (16k + 4 + p) xor (16k + 8 + p) xor (16k + 12p) = 0 \)

Noting \ (0 \ XOR \. 1 \ XOR \ 2 \ XOR \ = 0. 3 \) , above two points are easy to demonstrate.

Thus, for any \ (K \) , any of the ranks of the matrix below the exclusive OR and to 0:
\ [\ the begin {Equation} \ the begin {Array} {CCCC} 16K & 16K +. 1 & 16K + 2 & 16K +. 3 \\ 16K +. 4 & 16K + 5 & 16k + 6 & 16k
+ 7 \\ 16k + 8 & 16k + 9 & 16k + 10 & 16k + 11 \\ 16k + 12 & 16k + 13 & 16k + 14 & 16k + 15 \ end {array} \ end {equation} \] Since \ (n-\) is a multiple of 4, direct such construction can be.

code:


#include<bits/stdc++.h>
using namespace std;
int n,mp[1010][1010],tt;
void Work(int x,int y){
    for(int i=0;i<4;++i)for(int j=0;j<4;++j)mp[x+i][y+j]=tt++;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i+=4)for(int j=1;j<=n;j+=4)Work(i,j);
    for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)printf("%d%c",mp[i][j]," \n"[j==n]);
    return 0;
}

D.Restore Permutation

AC Time: 1h8min, 1456 points

(Yes I used the D 16min, C took 38min)

answer:

After considering the forward calculation.

After completion of a period recorded in the computer suffix, if the next position \ (X \) , then all satisfy the conditions and the number of \ (sum_x \) .

A start, \ (sum_x = \ {X FRAC (. 1-X)} {2} \)

Current position \ (I \) , we can obtain two points satisfies \ (sum_x = s_i \) a \ (X \) .

Then we want to update \ (SUM \) . All equivalent to \ (K> X \) , so \ (sum_k = sum_k-X \) .

Segment tree maintenance can be.

Another problem is that some have let go of a few, but we dichotomy when it will still be assigned to two, that meet \ (sum_x = s_i \) may be a while \ (x \) , rather than a \ (x \) .

In fact, we're looking for \ (x \) should be all satisfied \ (sum_x = s_i \) is \ (x \) the largest.

code:

#include<bits/stdc++.h>
#define ci const int&
#define Upd(x) (t[x].sum=t[x<<1].sum+t[x<<1|1].sum)
#define Sum(x) (1ll*(x+1)*(x)/2ll)
using namespace std;
struct node{
    int l,r;
    long long sum;
}t[800010];
int n,prt[200010];
long long s[200010];
void Build(ci x,ci l,ci r){
    t[x].l=l,t[x].r=r;
    if(l==r)return;
    int mid=l+r>>1;
    Build(x<<1,l,mid),Build(x<<1|1,mid+1,r);
}
void Change(ci x,ci id){
    if(t[x].l==t[x].r)return(void)(t[x].sum=id);
    int mid=t[x].l+t[x].r>>1;
    id<=mid?Change(x<<1,id):Change(x<<1|1,id),Upd(x);
}
long long Query(ci x,ci l,ci r){
    if(l>r)return 0;
    if(t[x].l==l&&t[x].r==r)return t[x].sum;
    int mid=t[x].l+t[x].r>>1;
    return r<=mid?Query(x<<1,l,r):(l>mid?Query(x<<1|1,l,r):(Query(x<<1,l,mid)+Query(x<<1|1,mid+1,r)));
}
int l,r,mid;
int main(){
    scanf("%d",&n),Build(1,1,n);
    for(int i=1;i<=n;++i)scanf("%I64d",&s[i]);
    for(int i=n;i>=1;--i){
        l=1,r=n;
        while(l<r)mid=l+r+1>>1,Sum(mid-1)-Query(1,1,mid-1)<=s[i]?l=mid:r=mid-1;
        prt[i]=l,Change(1,l);
    }
    for(int i=1;i<=n;++i)printf("%d ",prt[i]);
    return 0;
}

E.Let Them Slide

AC Time: 2h4min, 1084 points (-1)

answer:

For each of length \ (L \) under \ (A \) , which can correspond to the position \ (K \) number actually \ (A \) period of the interval \ ([max (1, k- ( WL)), min (L, K)] \) .

Since some positions may not correspond to any number, so we \ (A_ = a_0 +. 1 {L} = 0 \) , the upper section to \ ([max (0, k- (wl)), min (l + 1 , k)] \) .

Then ascending enumeration position \ (I \) , each up to a position to increase or decrease a position, maintenance can be monotonous queue.

But so \ (T \) a.

The above algorithm is due to the fact \ (O (nw) \) may order \ (^ n-10. 6 = W = \) , each of a length of the bar.

Consider for a short article \ (A \) , there are a number of intermediate positions may correspond to (A \) \ all the numbers.

So long as we can calculate the number of all the corresponding section, the number of interval plus the maximum number of directly winding section by the differential approach.

For the remaining part, the number is \ (O (l) \) a.

Thus the time complexity becomes \ (O (\ SUM L) \) .

code:

Speak up is simple, in fact, there are a lot of details.

(This is what you write code for a reason nearly 1h of?)

#include<bits/stdc++.h>
#define ci const int&
using namespace std;
int n,w,len,t,mx,dq[1000010],id[1000010],hd,tl;
long long d[1000010];
vector<int>a[1000010];
void Add(ci x,ci ind){
    if(ind>=a[x].size())return;
    while(hd>=tl&&dq[hd]<=a[x][ind])--hd;
    dq[++hd]=a[x][ind],id[hd]=ind;
}
void Del(ci x,ci ind){
    if(id[tl]==ind)++tl;
}
int main(){
    scanf("%d%d",&n,&w);
    for(int i=1;i<=n;++i){
        scanf("%d",&len),hd=0,tl=1,a[i].push_back(0),mx=0;
        for(int j=1;j<=len;++j)scanf("%d",&t),a[i].push_back(t),mx=max(mx,t);
        a[i].push_back(0),Add(i,0),Add(i,1);
        if(w-len==0)Del(i,0);
        for(int j=1;j<=len+1;Del(i,j-(w-len)),++j,Add(i,j))d[j]+=dq[tl],d[j+1]-=dq[tl];
        if(len+1<w-len)d[len+2]+=mx,d[w-len+1]-=mx,Del(i,0);
        for(int j=max(w-len+1,len+2);j<=w;++j)d[j]+=dq[tl],d[j+1]-=dq[tl],Del(i,j-(w-len));
    }
    for(int i=1;i<=w;++i)d[i]+=d[i-1],printf("%I64d ",d[i]);
    return 0;
}

to sum up

The last game of the 14s AC E title

Fortunately delayed 5min ... or else orange estimated name is gone

The problem is really autistic C, D and E to see the problem surface within 2min to come up with positive solutions ... QWQ

Guess you like

Origin www.cnblogs.com/xryjr233/p/CF1208.html