2019 cattle off the country more than a school

 

Part of the solution to a problem is more behind the line

 

A Equivalent Prefixes

Solution: Monotone stack maintains range can cover each point sequence, and then to compare the two arrays are the same.

Reference Code:

#include<bits/stdc++.h>
#define maxl 100010
using namespace std;
 
int n,ans,top;
int a[maxl],b[maxl];
int la[maxl],ra[maxl],lb[maxl],rb[maxl];
int s[maxl];
 
inline bool jug(int mid)
{
    top=0;
    for(int i=1;i<=mid;i++)
    {
        while(top>0 && a[i]<a[s[top]])
            ra[s[top]]=i-1,top--;
        s[++top]=i;
        la[i]=s[top-1]+1;
    }
    while(top>0) ra[s[top]]=mid,top--;
    top=0;
    for(int i=1;i<=mid;i++)
    {
        while(top>0 && b[i]<b[s[top]])
            rb[s[top]]=i-1,top--;
        s[++top]=i;
        lb[i]=s[top-1]+1;
    }
    while(top>0) rb[s[top]]=mid,top--;
    for(int i=1;i<=mid;i++)
    if(la[i]!=lb[i] || ra[i]!=rb[i]) return false;
    return true;
}
 
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        for(int i=1;i<=n;i++) scanf("%d",&b[i]);
        int l=1,r=n,mid;
        while(l+1<r)
        {
            mid=(l+r)>>1;
            if(jug(mid)) l=mid;
            else r=mid; 
        }
        if(jug(r)) ans=r;
        else ans=l;
        printf("%d\n",ans);
    }
    return 0;
}
View Code

Integration

Reference Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod =1e9+7;
const int size=1e3+5;
int quick_pow(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1) ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;
        b>>=1;
    }
    return ans%mod;
}
int a[size];
int k[size];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {  
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        for(int i=1;i<=n;i++)
        {
            k[i]=1;
            for(int j=1;j<=n;j++)
            {
                if(j==i) continue;
                k[i]=1LL*k[i]*((1LL*a[j]*a[j]%mod-1LL*a[i]*a[i]%mod+mod)%mod)%mod;
            }
            k[i]=quick_pow(k[i],mod-2);
        }
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            ans=(ans+1LL*k[i]*500000004%mod*quick_pow(a[i],mod-2)%mod)%mod;
        }
        printf("% d \ n " , year); 
    } 
}
View Code

 And ABBA

Reference Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod=1e9+7;
const int size=4e3+5;
int fac[size],invfac[size];
int quick_pow(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1) ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;
        b>>=1;
    }
    return ans%mod;
}  
void init()
{
    fac[0]=1;
    for(int i=1;i<size;i++) fac[i]=1LL*fac[i-1]*i%mod;
    invfac[size-1]=quick_pow(fac[size-1],mod-2);
    for(int i=size-2;i>=0;i--) invfac[i]=1LL*invfac[i+1]*(i+1)%mod;
}
int combi(int a,int b)
{
    if(a<0) return 0;
    if(a==0) return 1;
    return 1LL*fac[b]*invfac[a]%mod*invfac[b-a]%mod;
}
int main()
{
    int n,m;
    init();
    while(~scanf("%d%d",&n,&m))
    {
        printf("%d\n",(1LL*fac[2*(n+m)]*invfac[n+m]%mod*invfac[n+m]%mod-combi(n-1,2*(n+m))+mod-combi(m-1,2*(n+m))+mod)%mod);
    }
}
View Code

 F Random  Point in Triangle 

Reference Code:

#include<bits/stdc++.h>
#define maxl 10010
 
using namespace std;
 
int main()
{
    int x1,y1,x2,y2,x3,y3;
    while(~scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3))
    {
        long long tmp=1ll*(x2-x1)*(y3-y1)-1ll*(x3-x1)*(y2-y1);
        if(tmp<0)
            tmp=-tmp;
        printf("%lld\n",tmp*11);
    }
    return 0;
}
View Code

J Freaction Comparision

Reference Code:

#include<bits/stdc++.h>
 
using namespace std;
 
long long x,y,a,b;
 
int main()
{
    __int128 sum1,sum2;
    while(~scanf("%lld%lld%lld%lld",&x,&y,&a,&b))
    {
        sum1=x;sum1*=b;
        sum2=y;sum2*=a;
        if(sum1<sum2)
            puts("<");
        else if(sum1>sum2)
            puts(">");
        else
            puts("=");
    }
    return 0;
}
View Code

 

 

Update slowly behind other topics -

 

Guess you like

Origin www.cnblogs.com/songorz/p/11210776.html