Codeforces696 Round #362 (Div. 1)(vp) A~D题解

很久没有打比赛了,内部模拟赛天天垫底,第一次vp之旅又是和**一样,这样下去GDOI之后直接退役算了

整场都在忘开LL

 

A. Lorenzo Von Matterhorn

这个题一看我就想直接虚树+树剖强行搞,但是这个是A题啊。。。写着中途看榜已经100+的人A了,冷静思考发现可以暴力计算每个修改对询问的印影响,用树上差分搞搞,两个点的LCA可以用位运算求,反正心态崩着乱推乱玩各种出锅浪费了1h最后给混过去了,不过还是一个很不错的题

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int _=1e2;
const int maxn=3e3+_;

struct opera1
{
    int t; LL x,w;
    opera1(){}opera1(int T,LL X,LL W){t=T,x=X,w=W;}
}a[maxn],b[maxn];int alen,blen;LL as[maxn];
int DEP(LL x)
{
    int t=0;
    while(x>0)x/=2,t++;
    return t-1;
}
LL LCA(LL x,LL y)
{
    LL u,v;
    for(u=x;u!=(u&-u);u-=(u&-u));
    for(v=y;v!=(v&-v);v-=(v&-v));
    LL ret=0;
    while(u!=0&&v!=0)
    {
        if(((x&u)==0)^((y&v)==0))break;
        ret=(ret<<1)|((x&u)?1:0);
        u>>=1,v>>=1;
    }
    return ret;
}
int op[maxn];
int main()
{
    int n;LL u,v,w;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&op[i]);
        if(op[i]==1)
        {
            scanf("%lld%lld%lld",&u,&v,&w);
            a[++alen]=opera1(i,u,w);
            a[++alen]=opera1(i,v,w);
            a[++alen]=opera1(i,LCA(u,v),-2*w);
        }
        else
        {
            scanf("%lld%lld",&u,&v);
            b[++blen]=opera1(i,u,1);
            b[++blen]=opera1(i,v,1);
            b[++blen]=opera1(i,LCA(u,v),-2);
        }
    }
    for(int i=1;i<=alen;i++)
        for(int j=1;j<=blen;j++)
            if(a[i].t<b[j].t)
            {
                LL lca=LCA(a[i].x,b[j].x);
                as[b[j].t]+=DEP(lca)*a[i].w*b[j].w;
            }
    for(int i=1;i<=n;i++)
        if(op[i]==2)printf("%lld\n",as[i]);
    
    return 0;
}
A. Lorenzo Von Matterhorn

 

B. Puzzles

这题是个sb题,先把子树tot搞出来,考虑一个兄弟在我前面被遍历的概率是1/2,直接算就可以了,过的很快

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int _=1e2;
const int maxn=1e5+_;

struct node
{
    int x,y,next;
}a[maxn];int len,last[maxn];
void ins(int x,int y)
{
    len++;
    a[len].x=x;a[len].y=y;
    a[len].next=last[x];last[x]=len;
}
int tot[maxn];double f[maxn];
void dfs(int x)
{
    tot[x]=1;
    for(int k=last[x];k;k=a[k].next)
    {
        dfs(a[k].y);
        tot[x]+=tot[a[k].y];
    }
}
void dfs2(int x)
{
    for(int k=last[x];k;k=a[k].next)
    {
        f[a[k].y]=f[x]+1+(double)(tot[x]-1-tot[a[k].y])/2.0;
        dfs2(a[k].y);
    }
}

int main()
{
    int n,F;
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
        scanf("%d",&F),ins(F,i);
    dfs(1);
    f[1]=1;dfs2(1);
    for(int i=1;i<n;i++)printf("%.6lf ",f[i]);
    printf("%.6lf\n",f[n]);
    
    return 0;
}
B Puzzles

 

C.PLEASE

vp的时候看到这个题画了下柿子发现随便转移,分母是2^n,概率矩乘一下很好算,但是分数的形式很乱搞,就先过了,果然是我不会的数论。后来打了一侧和中间的表发现是一个很熟悉的数列x=x+y,y=2*x,对于一侧有fi=fi-1+2*fi-2(见过很多次了,原来这个是Jacobsthal sequence,这个东西一定是个奇数所以就可以分开做了)Jacobsthal sequence的第n项=(2^n-(-1)^n)/3,算出一侧的,推出中间的就好了

注意有个坑,就是数列是乘起来而不是加起来的。。。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
LL quick_pow(LL A,LL p)
{
    LL ret=1;
    while(p!=0)
    {
        if(p%2==1)ret=ret*A%mod;
        A=A*A%mod;p/=2;
    }
    return ret;
}
int main()
{
    int n; LL p,a=2,b=mod-1;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%lld",&p);
        a=quick_pow(a,p)%mod;
        b=quick_pow(b,p)%mod;
    }
    int z=((a-b+mod)%mod)*quick_pow(3,mod-2)%mod;
    a=a*quick_pow(2,mod-2)%mod;
    printf("%lld/%lld\n",(mod+a-z)%mod,a);
    
    return 0;
}
C. PLEASE

 

D. Legen...

这也是一个一眼题,AC机+DP+矩乘优化,但是这个矩乘的运算方式有点诡异(max(cij,aik+bkj))导致在时间内没有调出来,感觉还是惯性思维了,把一个最值题想成计数题

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int maxn=200+10;
const int maxS=200+10;
const int maxc=26+4;
const LL inf=(1LL<<62);
int li;
struct Matrix
{
    LL mp[maxS][maxS];
    void clear(){memset(mp,0,sizeof(mp));}
    void Mmin(){for(int i=0;i<li;i++)for(int j=0;j<li;j++)mp[i][j]=-inf;}
    friend Matrix operator *(Matrix a,Matrix b)
    {
        Matrix c;c.Mmin();
        for(int i=0;i<li;i++)
            for(int j=0;j<li;j++)
                for(int k=0;k<li;k++)
                    if(a.mp[i][k]!=-inf&&b.mp[k][j]!=-inf)
                        c.mp[i][j]=max(c.mp[i][j],a.mp[i][k]+b.mp[k][j]);
        return c;
    }
}ans,A;
Matrix quick_pow(Matrix c,Matrix a,LL p)
{
    while(p!=0)
    {
        if(p%2==1)c=c*a;
        a=a*a;p/=2;
    }
    return c;
}

struct Trie
{
    int w[maxc],fail;
    LL s;
}tr[maxS];int trlen; char ss[maxS];
void insert(int d)
{
    int now=0,len=strlen(ss+1);
    for(int i=1;i<=len;i++)
    {
        int x=ss[i]-'a'+1;
        if(tr[now].w[x]==0)tr[now].w[x]=++trlen;
        now=tr[now].w[x];
    }
    tr[now].s+=d;
}
int head,tail,list[maxS];
void bfs()
{
    head=1,tail=2;list[head]=0;
    while(head!=tail)
    {
        int now=list[head];
        for(int x=1;x<=26;x++)
        {
            int son=tr[now].w[x];
            if(son==0)continue;
            if(now==0)tr[son].fail=0;
            else
            {
                int pre=tr[now].fail;
                while(pre!=0&&tr[pre].w[x]==0)pre=tr[pre].fail;
                tr[son].fail=tr[pre].w[x];
                tr[son].s+=tr[tr[son].fail].s;
            }
            list[tail++]=son;
        }
        head++;
    }
}

int a[maxn];
int main()
{
    int n;LL L;
    scanf("%d%lld",&n,&L);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        scanf("%s",ss+1),insert(a[i]);
    li=trlen+1;
    bfs();
    
    A.Mmin();
    for(int now=0;now<=trlen;now++)
        for(int x=1;x<=26;x++)
        {
            int pre=now;
            while(pre!=0&&tr[pre].w[x]==0)pre=tr[pre].fail;
            int son=tr[pre].w[x];
            if(son!=0)A.mp[now][son]=tr[son].s;
        }
    ans.Mmin();ans.mp[0][0]=0;
    ans=quick_pow(ans,A,L);
    
    LL mmax=0;
    for(int i=0;i<=trlen;i++)mmax=max(mmax,ans.mp[0][i]);
    printf("%lld\n",mmax);
    
    return 0;
}
D. Legen...

 

E、F留坑待填

 

转载于:https://www.cnblogs.com/AKCqhzdy/p/10653874.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值