2026.8.21 模拟赛13

· · 个人记录

2026.8.21 模拟赛13

一、比赛基本情况

比赛日期:2026.8.21

比赛时长:14:00\ ~ \ 15:1\ ~1h10min

比赛得分:120pts

比赛排名:rk3

二、比赛整体回顾

开题顺序:T1\ ~(约30min\ 100pts) - T4\ ~(约40min\ 20pts)

三、题目复盘

T1: P8802 [蓝桥杯 2022 国 B] 出差石头剪刀布

I AC T1!!!

T2: P1558 色板游戏

本题得分:0pts

初始思路:

一样看出了是线段树,但是没想出来维护种类的方法。

我试了分块,也没想出来维护种类的方法

考场解题过程:

没写

考场代码:

无

赛后题解:

#### 补题代码: ```cpp #include<bits/stdc++.h> #define int long long #define ull unsigned long long #define endl '\n' using namespace std; const int N=1e5+5; int n,T,q; struct node{ int val; int lzy; }t[4*N]; void pushdown(int x,int l,int r){ if(t[x].lzy==0){ return ; } t[2*x].val=t[2*x+1].val=t[x].lzy; t[2*x].lzy=t[2*x+1].lzy=t[x].lzy; t[x].lzy=0; return ; } void pushup(int x,int l,int r){ t[x].val=t[2*x].val|t[2*x+1].val; } void build(int x,int l,int r){ if(l==r){ t[x].val=1; return ; } int mid=(l+r)/2; build(2*x,l,mid); build(2*x+1,mid+1,r); pushup(x,l,r); } void update(int x,int l,int r,int L,int R,int k){ if(L>r||l>R){ return ; } if(L<=l&&r<=R){ t[x].val=(1<<(k-1)); t[x].lzy=(1<<(k-1)); return ; } pushdown(x,l,r); int mid=(l+r)/2; update(2*x,l,mid,L,R,k); update(2*x+1,mid+1,r,L,R,k); pushup(x,l,r); } int query(int x,int l,int r,int L,int R){ if(L>r||l>R){ return 0; } if(L<=l&&r<=R){ return t[x].val; } pushdown(x,l,r); int mid=(l+r)/2; return query(2*x,l,mid,L,R)|query(2*x+1,mid+1,r,L,R); } int lowbit(int x){ return x&(-x); } int get(int x){ int res=0; while(x!=0){ x-=lowbit(x); res++; } return res; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>T>>q; build(1,1,n); while(q--){ char op; int x,y,k; cin>>op>>x>>y; if(x>y){ swap(x,y); } if(op=='C'){ cin>>k; update(1,1,n,x,y,k); }else{ int ans=query(1,1,n,x,y); cout<<get(ans)<<endl; } } return 0; } ``` ### T3: P1351 [NOIP 2014 提高组] 联合权值 #### 本题得分:$0pts

初始思路:

#### 考场解题过程: 按思路,但是忘记取模了。 #### 考场代码: ```cpp #include<bits/stdc++.h> #define int long long #define ull unsigned long long #define endl '\n' using namespace std; const int N=2e5+5,mod=10007; int n; int ans,maxi; int a[N]; int val[N]; vector<int> G[N]; void dfs(int x,int ff,int step,int st){ // cout<<x<<' '<<step<<endl; if(step==2){ val[x]=a[x]*st; // cout<<x<<": "<<val[x]<<' '<<a[x]<<' '<<st<<endl; } for(int i=0;i<G[x].size();i++){ int v=G[x][i]; if(v==ff){ continue; } if(step+1>=3){ continue; } dfs(v,x,step+1,st); } } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; for(int i=1;i<=n-1;i++){ int u,v; cin>>u>>v; G[u].push_back(v); G[v].push_back(u); } for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ memset(val,0,sizeof(val)); dfs(i,i,0,a[i]); for(int j=1;j<=n;j++){ ans+=val[j]; maxi=max(maxi,val[j]); } // cout<<endl; } cout<<maxi<<' '<<ans; return 0; } ``` #### 赛后题解: 维护邻居权值的和还有邻居的最大权值和邻居的次大权值 对于节点 $i$ 的邻居 $v$,$sum[i] - a[v]$ 表示除了 $v$ 之外所有邻居的权值之和 $a[v] * (sum[i] - a[v])$ 计算了所有包含 $v$ 的邻居对的联合权值之和 对 $i$ 的所有邻居都这样做,就计算了所有邻居对的联合权值之和 ∴ 最大的联合权值一定来自最大的两个邻居权值的乘积 #### 补题代码: ```cpp #include<bits/stdc++.h> #define int long long #define ull unsigned long long #define endl '\n' using namespace std; const int N=2e5+5,mod=10007; int n; int ans; int maxi; int maxi1[N],maxi2[N]; int sum[N]; int a[N]; vector<int> G[N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; for(int i=1;i<=n-1;i++){ int u,v; cin>>u>>v; G[u].push_back(v); G[v].push_back(u); } for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=n;i++){ for(int j=0;j<G[i].size();j++){ int v=G[i][j]; sum[i]+=a[v]; if(a[v]>maxi1[i]){ maxi2[i]=maxi1[i]; maxi1[i]=a[v]; }else if(a[v]>maxi2[i]){ maxi2[i]=a[v]; } // sum[i]%=mod; } } for(int i=1;i<=n;i++){ for(int j=0;j<G[i].size();j++){ int v=G[i][j]; ans+=a[v]*(sum[i]-a[v]); ans%=mod; maxi=max(maxi,maxi1[i]*maxi2[i]); } } cout<<maxi<<' '<<ans; return 0; } ``` ### T4: P5007 DDOSvoid 的疑惑 #### 本题得分:$15pts

初始思路:

没写

考场解题过程:

无

考场代码:

无

赛后题解:

定义dp[u]为以u为根的子树的毒瘤集的总和。

状态转移方程 **注意计算顺序** $pd[x]=(pd[x]+pd[v]+dp[x]*pd[v]+dp[v]*pd[x])%mod; dp[x]=(dp[x]+dp[v]+dp[x]*dp[v])%mod;

补题代码:

#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define endl '\n'
using namespace std;
const int N=1e6+5,mod=100000007;
int n,T;
int a[N];
int dp[N];
int pd[N];
vector<int> G[N];
void dfs(int x,int ff){
    for(int i=0;i<G[x].size();i++){
        int v=G[x][i];
        if(v==ff){
            continue;
        }
        dfs(v,x);
        pd[x]=(pd[x]+pd[v]+dp[x]*pd[v]+dp[v]*pd[x])%mod;
        dp[x]=(dp[x]+dp[v]+dp[x]*dp[v])%mod;
    }
    dp[x]++;
    pd[x]+=a[x];
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>T;
    for(int i=1;i<=n;i++){
        if(T==1){
            a[i]=i;
        }else{
            a[i]=1;
        }
    }
    for(int i=1;i<=n-1;i++){
        int u,v;
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1,1);
    cout<<pd[1]%mod;
    return 0;
}

The end!