2019.9.26 csp-s simulation test 52 to reflect summary

Just write a blog hour gone, the browser automatically refreshed.

One! A! small! Time!

Computer mouse and keyboard which can not fall, mad at me.

 

Players did not refuse the idea T1T2, T3'd like to come out early, propped by T3 scores.

Data structure to learn silly players, true garbage.

 

T1 average:

If all of a sequence number minus x, then the average will be minus x. This x can be bipartite, the statistical average is less than the sequence number in the sequence of 0, meaning the average number less than the sequence number of the original sequence x. The last statistic is less than k and k closest to the x is the desired answer.

Mean sequence is less than 0, then the sequence and certainly less than 0. Prefix and the performance is the sum of a range R & lt <sum L-. 1 , for the sake converted prefix and the number of the reverse sequence.

And when the merge sort array subscript prefixes from zero, because there may be the case on a sequence beginning less than zero, and to SUM 0 comparison.

#include<iostream>
#include<cstdio>
using namespace std;
int n,k;
double ans;
int num;
double b[100010],c[100010],s[100010],a[100010],maxx;
void work(int l,int r){
    if(l==r){
        b[l]=s[l];
        return;
    }
    int mid=(l+r)/2;
    work(l,mid);
    work(mid+1,r);
    int ll=l,rr=mid+1,p=l;
    while(ll<=mid&&rr<=r){
        if(b[ll]<=b[rr]){
            c[p++]=b[ll++];
        }
        else{
            num+=mid-ll+1;
            c[p++]=b[rr++];
        }
    }
    while(ll<=mid){
//        num+=r-mid;
        c[p++]=b[ll++];
    }
    while(rr<=r){
        c[p++]=b[rr++];
    }
    for(int i=l;i<=r;i++){
        b[i]=c[i];
    }
}
int check(double x){
    num=0;
    for(int i=1;i<=n;i++){
        s[i]=s[i-1]+a[i]-x;
    }
    work(0,n);
    return num;
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%lf",&a[i]);
        maxx=max(maxx,a[i]);
    }
    double l=0,r=1e9;
    while(l+1e-5<r){
        double mid=(l+r)*0.5;
        if(check(mid)<k){
            l=mid;
        }
        else r=mid;
    }
    printf("%.4lf",l);
    return 0;
} 
View Code

 

 

T2 coloring game:

Examination when the first thought of fast power matrix, then do not push DP expression ......

Since adjacent two coating colors and q are independent of what particular color, converted to the question column DP.

Coating the first embodiment to find the number of colors i a. J painted colors disposed F [i] [j] is an i-th row in the program number, f [i] [j] = f [i-1] [j-1] * (p- (j- 1)) + f [i-1] [j] * j, meaning from the remaining p- (j-1) select a new color coat color, or a color selected from duplicate existing species j. Provided g [i] = f [n] [i], g [i] that is the number of colors painted i one embodiment.

Transferred from a consideration of the j k colors to the colors of the column. For each j determined by the colors of the coloring program, to enumerate and sets j and k x. So in this case k can be divided into two parts, with the intersection portion j has C (j, j + kx) choices, k remaining color C (pj, xj) choices. Is then determined for each option k colors, there g [k] / C (p, k) species coloring scheme.

J is then determined for each transferred to the program number k is then multiplied by a dp [i-1] [j ], i.e., a total number of the program j colors.

Initialization dp [1] [i] = g [i].

Found that for j different columns to transfer the k, multiplied by the parameter is the same, so you can quickly optimize power matrix.

The answer is initialized matrix dp [1] [i], the transition matrix A [i] [j] shall be transferred to the parameter i j, followed by rapid power matrix m-1 times (starting from the second row).

#include<iostream>
#include<cstdio>
using namespace std;
const int mod=998244353;
int n,m,p,q;
long long f[110][110],c[110][110],dp[1010][110],ans;
struct node{
    long long g[110][110];
}a,b,d;
long long ks(long long x,long long k){
    long long num=1;
    while(k){
        if(k&1)num=num*x%mod;
        x=x*x%mod;
        k>>=1;
    }
    return num;
}
long long cal(int j,int k){
    long long num=0;
    for(int x=max(q,max(j,k));x<=min(p,j+k);x++){
        num=(num+(c[j][j+k-x]*c[p-j][x-j]%mod)%mod)%mod;
    }
    return num;
}
node cheng(node x,node y){
    node e;
    for(int i=1;i<=p;i++){
        for(int j=1;j<=p;j++){
            e.g[i][j]=0;
        }
    }
    for(int k=1;k<=p;k++){
        for(int i=1;i<=p;i++){
            for(int j=1;j<=p;j++){
                e.g[i][j]=(e.g[i][j]+x.g[i][k]*y.g[k][j]%mod)%mod;
            }
        }
    }
    return e;
}
void ksm(int k,node x){
    while(k){
        if(k&1)b=cheng(b,x);
        x=cheng(x,x);
        k>>=1;
    }
}
int main()
{
    scanf("%d%d%d%d",&n,&m,&p,&q);
    c[0][0]=1;
    for(int i=1;i<=100;i++){
        c[i][0]=1;
        for(int j=1;j<=i;j++){
            c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
        }
    }
    f[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=p;j++){
            f[i][j]=(f[i-1][j]*j%mod+f[i-1][j-1]*(p-(j-1))%mod)%mod;
        }
    }
    for(int i=1;i<=p;i++){
        for(int j=max(q-i,1);j<=min(n,p);j++){
            a.g[i][j]=(a.g[i][j]+f[n][j]*ks(c[p][j],mod-2)%mod*cal(i,j)%mod)%mod;
        }
    }
    for(int i=1;i<=p;i++){
        b.g[1][i]=f[n][i];
    }
    m--;
    ksm(m,a);
    for(int i=1;i<=p;i++){
        ans=(ans+b.g[1][i])%mod; 
    }
    printf("%lld",ans);
    return 0;
}
View Code

 

 

T3 sequence:

While writing explanations while reviewing these questions only engage in more than one hour, the second time to write it very fast. Then T3 may write today will be the least time consuming solution to a problem question ......?

Seen by force, the first reaction is to answer questions and answers on a transfer from.

Complexity n and q are 1e5 level, which is certainly to be optimized to a log. Because the answer is likely to be a change coming from, each modification is a single point of asking specific content and the same, all the information asked to consider how to save enough and quickly find out what each change affects the inquiry.

Inquiry is to ask the interval form, which asks able to save x consider what coverage range, and quickly learned what each change of location x will be affected. It found that for each modification, cover modifications location x, x affected within a certain range, i.e., modify the original number with the current position of the intermediate range. Because each time only modify a position, asking for an impact if there is an answer can only be +1 or -1, so if you can quickly find out how many x in the affected range can know how many answers change. Then the open end around the inquiry, as the same difference, l recorded at + 1, r + x, -1. 1 recording of x. Followed by a subscript x is Chairman tree value, which cover the position of each stored sequence subjected to x.

For each modification, modify the position as long as find out how many x has a value in the intermediate value and the original value modification affected, answers to addition and subtraction accordingly.

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,q,cnt1,pre=1;
int a[100010],tree[100010];
long long ans;
struct node{
    int pos,x,val;
}b[200010];
struct node1{
    int l,r,x;
}c[200010];
bool cmp(node x,node y){
    if(x.pos<y.pos)return true;
    else return false;
}
int T[300010*18],L[300010*18],R[300010*18],tot,cnt[300010*18];
void build(int &p,int l,int r){
    p=++tot;
    if(l==r)return;
    int mid=(l+r)/2;
    build(L[p],l,mid);
    build(R[p],mid+1,r);
}
void update(int &p,int pre,int l,int r,int x,int val){
    p=++tot;
    L[p]=L[pre],R[p]=R[pre],cnt[p]=cnt[pre]+val;
    if(l==r)return;
    int mid=(l+r)/2;
    if(x<=mid)update(L[p],L[pre],l,mid,x,val);
    else update(R[p],R[pre],mid+1,r,x,val);
}
void add(int x){
    for(;x<=n;x+=(x&-x))tree[x]++;
}
int ask(int x){
    if(!x)return 0;
    int val=0;
    for(;x;x-=(x&-x))val+=tree[x];
    return val;
}
int query(int p,int l1,int r1,int l,int r){
    if(l1<=l&&r<=r1)return cnt[p];
    int mid=(l+r)/2;
    if(r1<=mid)return query(L[p],l1,r1,l,mid);
    if(l1>mid)return query(R[p],l1,r1,mid+1,r);
    return query(L[p],l1,mid,l,mid)+query(R[p],mid+1,r1,mid+1,r);
} 
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=1,x,y,z;i<=m;i++){
        scanf("%d%d%d",&x,&y,&z);
        b[++cnt1].pos=x,b[cnt1].x=z,b[cnt1].val=1;
        b[++cnt1].pos=y+1,b[cnt1].x=z,b[cnt1].val=-1;
        c[i].l=x,c[i].r=y,c[i].x=z;
    }
    sort(b+1,b+2*m+1,cmp);
    cnt1=1;
    build(T[0],1,n);
    for(int i=1;i<=n+1;i++){
        if(b[cnt1].pos==i){
            while(b[cnt1].pos==i){
                update(T[i],pre,1,n,b[cnt1].x,b[cnt1].val);
                pre=T[i];
                if(b[cnt1].val==-1){//r 
                    ans+=ask(n)-ask(b[cnt1].x-1);
                }
                else{//l
                    ans-=ask(n)-ask(b[cnt1].x-1);
                }
                cnt1++;
            }
        }
        else if(i<=n){
            T[i]=pre;
        }
        if(i<=n)add(a[i]);
    }
    printf("%lld\n",ans);
    for(int i=1,p,v;i<=q;i++){
        scanf("%d%d",&p,&v);
        long long pos=p^ans;
        long long x=v^ans;
        if(x>a[pos]){
            int num=query(T[pos],a[pos]+1,x,1,n);
            ans+=num;
            a[pos]=x;
        }
        else if(x<a[pos]){
            int num=query(T[pos],x+1,a[pos],1,n);
            ans-=num;
            a[pos]=x;
        }
        printf("%lld\n",ans);
    }
    return 0;
 } 
View Code

 

 

No more garbage browser written explanations of orzzzzzzzz mad at me

A night to write this one, although the joint review a long time, get to know these questions again and try to sum up routine ...

Goo out problem solutions as well as n chapter, I so hard -

Guess you like

Origin www.cnblogs.com/chloris/p/11614198.html