19.11.4 summary

19.11.4 summary

Gufen: 100 + 70 + 63

Actual: 100 + 63 + 0

T1

The original title.

First obstacle sorting point, to ensure that the latter point can not come to the front of the point.

Set f [i] indicates the start away from home, after a number of other obstacles to reach the scheme point barrier point i.

Request f [i] when subtracting illegal scheme with the full program.

Obviously, a certain kind of illegal schemes and only one "first hurdle after point"

Therefore, O ( \ (m ^ 2 \) ) transferred just fine.

T2

O (nmK) is clearly

Correct

Consider scanning line, one obtains a line f.

When we added a point, it will affect a square area. However, due to the contribution of the same color point it can not be double-counted, so the actual impact it is an interval. As shown below, only the blue part of the answer ++ just fine. Maintain a differential array.

Delete the situation is similar.

Now we need a support insert, delete, search predecessor successor data structures.

To each point to open a bitset.

Code

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;

long long n,m,i,j,k,ans1,ans2,S,bzz;
int sum[3][3005][3005];
int a[3005][3005];
long long delta[3005],f[3005];
bitset<3105> B1[100005],B2[100005];
int g[3005][3005],last[100005];

void does2()
{
    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++)
        {
            sum[1][i][j]=sum[1][i-1][j]+sum[1][i][j-1]-sum[1][i-1][j-1]+(a[i][j]==1);
            sum[2][i][j]=sum[2][i-1][j]+sum[2][i][j-1]-sum[2][i-1][j-1]+(a[i][j]==2);
        }
    for (i=1;i<=n-k+1;i++)
    {
        for (j=1;j<=m-k+1;j++)
        {
            S=0;
            if (sum[1][i+k-1][j+k-1]-sum[1][i-1][j+k-1]-sum[1][i+k-1][j-1]+sum[1][i-1][j-1]>0) S++;
            if (sum[2][i+k-1][j+k-1]-sum[2][i-1][j+k-1]-sum[2][i+k-1][j-1]+sum[2][i-1][j-1]>0) S++;
            ans1=max(ans1,S);
            ans2=ans2+S;
        }
    }
    printf("%lld %lld",ans1,ans2);
}

void getg()
{
    for (i=1;i<=100000;i++) last[i]=n+k+1;
    for (j=1;j<=m;j++)
    {
        for (i=n;i>=1;i--)
            g[i][j]=(last[a[i][j]]-i<k),last[a[i][j]]=i;
        for (i=n;i>=1;i--)
            last[a[i][j]]=n+k+1;
    }
}

void ADD(long long x,long long y)
{
    long long Pre,Nex;
    if (B2[a[x][y]][y]) return;
    Pre=m-B1[a[x][y]]._Find_next(m-y+1)+1;
    Nex=B2[a[x][y]]._Find_next(y);
    Nex=Nex-k+1;
    B1[a[x][y]][m-y+1]=1;
    B2[a[x][y]][y]=1;
    if (Nex<=Pre) return;
    Pre=max(max(Pre+1,1ll),y-k+1);
    Nex=min(min(Nex,m+1),y+1);
    if (Nex<=Pre) return;
    delta[Pre]++;
    delta[Nex]--;
}

void DEL(long long x,long long y)
{
    long long Pre,Nex;
    if (g[x][y]) return;
    Pre=m-B1[a[x][y]]._Find_next(m-y+1)+1;
    Nex=B2[a[x][y]]._Find_next(y);
    Nex=Nex-k+1;
    B1[a[x][y]][m-y+1]=0;
    B2[a[x][y]][y]=0;
    if (Nex<=Pre) return;
    Pre=max(max(Pre+1,1ll),y-k+1);
    Nex=min(min(Nex,m+1),y+1);
    if (Nex<=Pre) return;
    delta[Pre]--;
    delta[Nex]++;
}

int main()
{
    freopen("read.in","r",stdin);
//  freopen("b.out","w",stdout);
    scanf("%lld%lld%lld",&n,&m,&k);
    bzz=1;
    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++)
        {
            scanf("%d",&a[i][j]);
            if (a[i][j]>2) bzz=0;
        }
    if (bzz==1)
    {
        does2();
        return 0;
    }
    getg();
    for (i=1;i<=k-1;i++)
        for (j=1;j<=m;j++)
            ADD(i,j);
    for (i=k;i<=n;i++)
    {
        for (j=1;j<=m;j++)
        ADD(i,j);
        for (j=1;j<=m-k+1;j++)
        f[j]=f[j-1]+delta[j],ans1=max(ans1,f[j]),ans2+=f[j];
        for (j=1;j<=m;j++)
        DEL(i-k+1,j);
    }
    printf("%lld %lld",ans1,ans2);
}

T3

O ( \ (n-^. 3 \) ) A method of inverse matrix: the matrix \ (A \) and matrix \ (the I \) together, the \ (A \) eliminating a unit matrix, will change the I to \ (A ^ {- 1} \)

Correct

Find the law found, the answer equal

The difficulty is now seeking the number of combinations and the square \ (\ Sigma_ {i = 0 } ^ {n} (C ^ {i} _ {n}) ^ 2 \)

It is equal to

Code

#include<cstdio>
#include<cstring>
#include<algorithm>
#define mod 1000000007
using namespace std;

long long n,m,i,j,k,L,pick,ans,T,xs,MI,S;
long long jc[3000005],invjc[3000005];

long long mi(long long x,long long y)
{
    long long s=1;
    while (y>0)
    {
        if (y%2==1) s=s*x%mod;
        x=x*x%mod;
        y/=2;
    }
    return s;
}

long long C(long long a,long long b)
{
    return jc[a]*invjc[b]%mod*invjc[a-b]%mod;
}

int main()
{
    freopen("read.in","r",stdin);
//  freopen("c.out","w",stdout);
    jc[0]=1;
    for (i=1;i<=3000000;i++)
    jc[i]=jc[i-1]*i%mod;
    invjc[3000000]=mi(jc[3000000],mod-2);
    for (i=3000000-1;i>=0;i--)
    {
        invjc[i]=invjc[i+1]*(i+1)%mod;
    }
    
    scanf("%lld%lld",&n,&m);
    for (i=1;i<=n;i++)
    {
        MI=mi(i,m);
        MI=MI*MI%mod;
        S=MI*(C(2*i,i)-1)%mod;
        ans=(ans+S%mod)%mod;
    }
    printf("%lld",ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/leason-lyx/p/11806422.html