跳到正文

个人记录

深外高一上模拟赛复盘

Expert_Dream约 110 分钟
原文
文章信息与版本

9.5

https://www.luogu.com.cn/contest/333244#problems

这次的策略不错,从后往前开题,T4 要复数,直接不会跳过。

所以开始看T3,然后发现 T3的部分分好打,直接枚举二进制然后 set 模拟即可。

然后开 T2,发现 T2 好像是一道典题。容易发现区间被包含时一定不优,所以去重后所有区间不会互相包含,那么一个点属于的区间的编号时一个连续区间,这个时候就可以从大到小加入点,然后二分一下区间的编号区间,然后用线段树做就可以。

然后思考 T1 ,感觉这个不是很会。先打好了 60pts暴力。然后就一直在思考 100pts,

到最后 60+100+25+0

我认为策略上还是可以的,没有因为 t1 不会就没有打暴力。

然后T1 正解是通过拆解求和式子,然后的到一个关于区间前缀最大值和后缀最大值的表达式,然后分别的用线段树去维护即可。应当加强数据结构的练习。

T1赛时暴力

C++
namespace segtree{
	struct node{
		int l,r,mx,lazy;	
	}tr[N << 2];
	void build(int p,int l,int r){
		tr[p].l = l,tr[p].r = r;
		if(l==r){
			return ;
		}int mid = (l + r) >> 1;
		build(p << 1,l ,mid);
		build(p << 1| 1,mid + 1,r);
		return ;
	}void pushup(int p){
		tr[p].mx=max(tr[p << 1].mx,tr[p << 1 | 1].mx);
		return ;
	}void pushdown(int p){
		tr[p << 1].mx += tr[p].lazy;
		tr[p << 1].lazy += tr[p].lazy;
		tr[p << 1 | 1].mx += tr[p].lazy;
		tr[p << 1 | 1].lazy += tr[p].lazy;
		tr[p].lazy = 0;
		return ;
	}void modify(int p,int l,int r,int val){
		if(tr[p].l >= l && tr[p].r <= r){
			tr[p].mx += val;
			tr[p].lazy += val;
			return ;
		}pushdown(p);
		int mid = (tr[p].l + tr[p].r) >>1;
		if(l<=mid) modify(p<<1 ,l,r,val);
		if(r > mid) modify(p << 1 | 1,l,r,val);
		pushup(p);
		return ;
	}int query(int p,int l,int r){
        if(tr[p].l >= l &&tr[p].r <= r){
            return tr[p].mx;
        }pushdown(p);
        int ans= 0;
        int mid= (tr[p].l + tr[p].r) >> 1;
        if(l <= mid) gmax(ans,query(p<<1,l,r));
        if(r> mid) gmax(ans,query(p<< 1| 1,l,r ));
        return ans;
    }
}



int n,a[N],q;
pii que[N];

int b[N];
int unq[N * 2],unqsiz;
int get(int x){
	return (lower_bound(unq+1,unq+1+unqsiz,x) - unq + 1);
}

void solve(){
	cin >> n;
	For(i,1,n) {
		cin >> a[i];
	}cin >> q;

	For(i,1,q){
		int x,p;
		cin >> x >> p;
		a[x] += p;
		int mx = 0;
		int k = 0;
		For(j,1,n) if(a[j] > mx) mx = a[j],k = j;
		mx = 0;
		int res= 0 ;
		For(j,1,n) res -= a[j];
		For(j,1,k){
			gmax(mx,a[j]);
			res += mx;
		}
		mx = 0;
		For_(j,n,k+1){
			gmax(mx,a[j]);
			res += mx;
		}cout << res << endl;
	}

}signed main(){
	 freopen("rain.in","r",stdin);
	 freopen("rain.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    cin >> T ;
    while( T--){
        solve();
    }return 0;
}/*

*/

T1 正解代码

C++
struct segtree{
  struct node{
  	int l,r,val,lazy,sum;	
  }tr[N << 2];

  int a[N];
  void pushup(int p){
  	tr[p].sum=(tr[p << 1].sum + tr[p << 1 | 1].sum);
  	tr[p].val=max(tr[p << 1].val , tr[p << 1 | 1].val);
  	return ;
  }
  void build(int p,int l,int r){
  	tr[p].l = l,tr[p].r = r;
  		tr[p].lazy = 0;
  	if(l==r){
  		tr[p].val = tr[p].sum = a[l];
  		return ;
  	}int mid = (l + r) >> 1;
  	build(p << 1,l ,mid);
  	build(p << 1| 1,mid + 1,r);
  	pushup(p);
  	tr[p].val = max(tr[p<<1].val,tr[p<<1|1].val);
  	return ;
  }void pushdown(int p){
  	if(!tr[p].lazy) return;
  	tr[p << 1].val=tr[p].lazy;
  	tr[p << 1].lazy=tr[p].lazy;
  	tr[p << 1].sum = (tr[p << 1].r - tr[p << 1].l + 1) * tr[p << 1].val;
  	tr[p << 1 | 1].val=tr[p].lazy;
  	tr[p << 1 | 1].lazy=tr[p].lazy;
  	tr[p << 1 | 1].sum = (tr[p << 1 | 1].r - tr[p << 1 | 1].l + 1) * tr[p << 1 | 1].val;
  	tr[p].lazy = 0;
  	return ;
  }void modify(int p,int l,int r,int val){
  	if(tr[p].l >= l && tr[p].r <= r){
  		tr[p].val = tr[p].lazy = val;
  		tr[p].sum = (tr[p].r-tr[p].l +1) * tr[p].val;
  		return ;
  	}pushdown(p);
  	int mid = (tr[p].l + tr[p].r)  >> 1;
  	if(l <= mid) modify(p << 1,l,r,val);
  	if(r > mid) modify( p<<1|1,l,r,val);
  	pushup(p);
  	return ;
  }int query(int p,int l,int r){
  	// cout << p << " " << tr[p].l << " " << tr[p].r << " " << tr[p] .sum << endl;
      if(tr[p].l >= l &&tr[p].r <= r){
          return tr[p].sum;
      }pushdown(p);
      int ans= 0;
      int mid= (tr[p].l + tr[p].r) >> 1;
      if(l <= mid) ans += query(p<<1,l,r);
      if(r> mid) ans += query(p<< 1| 1,l,r );
  	pushup(p);
      return ans;
  }int query2(int p,int x){
  	if(tr[p].l == tr[p].r) {
  		return ((tr[p].val >= x) ? (tr[p].l) : (tr[p].l + 1));
  	}int mid  = (tr[p].l + tr[p].r)>>1 ;
  	pushdown(p);
  	if(tr[p<<1].val >= x) return query2(p << 1,x);
  	else if(tr[p<<1|1].val >= x)  return query2(p<<1|1,x);
  	else return tr[p].r + 1;
  }
}t1,t2;


int n,a[N],q;
int sum ;

int s[N],t[N];
void solve(){read(n);
  sum = 0;
  For(i,1,n) {
  	read(a[i]);
  	sum += a[i];
  }cin >> q;

  For(i ,0,n+1) t1.a[i] = t2.a[i] = 0;

  For(i,1,n) t1.a[i] =max( t1.a[i - 1] , a[i]);
  For(i,1,n) t2.a[i] = max(t2.a[i - 1] , a[n-i+1]);

  // cout << "debug";For(i,1,n) cout << t1.a[i] << " ";cout << endl;


  t1.build(1,1,n);
  t2.build(1,1,n);

  

  int mx = 0;
  int mxi = 0;
  For(i,1,n) if(mx < a[i]) mx = a[i],mxi = i;

  For(i,1,q){
  	int x,p;
  	read(x,p);
  	a[x] += p;
  	sum += p;
  	if(a[x] > mx) mx = a[x],mxi = x;
  	int pos = t1.query2(1,a[x]);
  	if(pos > x) t1.modify(1,x,min(pos-1,n),a[x]);

  	pos = t2.query2(1,a[x]);
  	if(pos > n-x+1) t2.modify(1,n-x+1,min(pos-1,n),a[x]);

  	int ans = t1.query(1,1,mxi);
  	if(n-mxi>0) ans += t2.query(1,1,n-mxi);

  	ans -= sum;

  	// cout << "db" << sum << " " << mxi << endl;
  	// For(j,1,n) cout << t1.query(1,1,j) << " ";
  	// cout << t1.query(1,1,2) << endl;
  	// cout <<  endl;
write(ans);

  }

}

T2 赛时通过代码

C++
namespace segtree{
	struct node{
		int l,r,mx,lazy;	
	}tr[N << 2];
	void build(int p,int l,int r){
		tr[p].l = l,tr[p].r = r;
		if(l==r){
			return ;
		}int mid = (l + r) >> 1;
		build(p << 1,l ,mid);
		build(p << 1| 1,mid + 1,r);
		return ;
	}void pushup(int p){
		tr[p].mx=max(tr[p << 1].mx,tr[p << 1 | 1].mx);
		return ;
	}void pushdown(int p){
		tr[p << 1].mx += tr[p].lazy;
		tr[p << 1].lazy += tr[p].lazy;
		tr[p << 1 | 1].mx += tr[p].lazy;
		tr[p << 1 | 1].lazy += tr[p].lazy;
		tr[p].lazy = 0;
		return ;
	}void modify(int p,int l,int r,int val){
		if(tr[p].l >= l && tr[p].r <= r){
			tr[p].mx += val;
			tr[p].lazy += val;
			return ;
		}pushdown(p);
		int mid = (tr[p].l + tr[p].r) >>1;
		if(l<=mid) modify(p<<1 ,l,r,val);
		if(r > mid) modify(p << 1 | 1,l,r,val);
		pushup(p);
		return ;
	}int query(int p,int l,int r){
        if(tr[p].l >= l &&tr[p].r <= r){
            return tr[p].mx;
        }pushdown(p);
        int ans= 0;
        int mid= (tr[p].l + tr[p].r) >> 1;
        if(l <= mid) gmax(ans,query(p<<1,l,r));
        if(r> mid) gmax(ans,query(p<< 1| 1,l,r ));
        return ans;
    }
}
int n,m;
pii l[N];
pii a[N];
pii b[N];
int tot = 0;
int ans = 0;
int limit;
int que1(int x){
	int l=1,r = tot;
	while(l + 5 <= r){
		int mid = (l + r) >> 1;
		if(b[mid].sc >= x) r = mid;
		else l = mid;
	}
	For(i,l,r) if(b[i].sc >= x) {
		return i;
	}return-1;
}int que2(int x){
	int l=1,r = tot;
	while(l + 5 <= r){
		int mid = (l + r) >> 1;
		if(b[mid].fs <= x) l = mid;
		else r = mid;
	}
	For_(i,r,l) if(b[i].fs <= x) {
		return i;
	}return -1;
}
int unq[N],unqsiz;
void solve(){
    cin >> n;
    For(i,1,n) cin >> a[i].fs;
    For(i,1,n) a[i].sc = i;

    sort(a+1,a+1+n,[](pii a,pii b){return a.fs>b.fs;});


    cin >> m;
	For(i,1,m) cin >> l[i].fs >> l[i].sc;
    
    sort(l+1,l+1+m);
    
    // unique 3
    int lst=0;
    For(i,1,m) {
    	if(l[i].sc >= l[lst].sc) b[++tot]=l[i],lst = i;
	}   
    segtree::build(1,1,tot);
    ans =0;
    vector<pii> lazy;

    For(i,1,n){
        int l = que1(a[i].sc),r = que2(a[i].sc);
		if(l==-1||r==-1)continue;
        if(l > r) continue;
        gmax(ans,segtree::query(1,l,r) * a[i].fs);
        segtree::modify(1,l,r,1);
    }
    cout << ans << endl;
	
}signed main(){
	//  freopen("interval.in","r",stdin);
	//  freopen("interval.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    // cin >> T ;
    while( T--){
        solve();
    }return 0;
}/*


*/

T3 赛时代码

C++
#include<bits
void solve(){
    cin >> n;
    set<pii> stx,sty;
    For(i,1,n){
        int x,y;cin >> x >> y;
        stx.insert({-x,y});
        sty.insert({-y,x});
    }
    int ans = 1e18;
    For(j,0,(1ll << n) - 1){
        set<pii> sta = stx;
        set<pii> stb = sty;
        int res = 0;
        For(i,1,n) {
            if((j >> (i - 1)) & 1){
                int x= -(*sta.begin()).fs ;
                int y= (*sta.begin()).sc;
                sta.erase(sta.begin());
                stb.erase({-y,x});
                res += x;
            }else{
                int y= -(*stb.begin()).fs ;
                int x= (*stb.begin()).sc;
                stb.erase(stb.begin());
                sta.erase({-x,y});
                res += y;
            }
        }ans = min(ans,res);
    }cout <<ans<<endl;
}signed main(){
	 freopen("pair.in","r",stdin);
	 freopen("pair.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    // cin >> T ;
    while( T--){
        solve();
    }return 0;
}

9.8

https://htoj.com.cn/cpp/oj/contest/detail/problem?cid=22897356242944&gid=22891537084672

这次的策略我认为还可以。

这次策略从后往前开始拼暴力。

开题发现最后的暴力比较好写

分类讨论了一下,推出了一些性质。然后获得了基础的暴力分。

然后往前面看,发现 A 题好像是一个结论题,但是不知道怎么证明只用 2 3 就是对的。但事实上他就是对的。可以记住这道题的结论。

然后 看 B 是个很典型的树形 DP,直接向上扫一遍然后再向下扫一遍就结束了。

然后开始 看 C 题,想了很久的正解好像不太会。

但是看到 80 pts 的 n^2 暴力比较容易些,所以就写了

然后最后应该是预估的分数 100+100+80+25

但是由于 B 题中的细节,在一处转移的过程中,f 数组 - 某一个数,然后直接 取 MOD ,事实上可能会到达 负数 。所以下次取模的时候多注意一下负数要 + MOD

总结:

策略没有问题,主要是需要权衡分数与时间使用的关系。发现简单的 80pts 就应该快速先写掉。没有死磕是正确的决策。

赛时更应当注意一些细节问题,就例如负数取模的时候要 + mod。以后多注意即可。

T1

C++
int n;
int a[N];
void solve(){    
    cin >> n;
    if(n==1)cout<<1<<endl;
    else cout << (ksm(3ll,((n/3) - (n%3 == 1)),mod) * ((n%3==2)?(2):(((n%3==1)?(4):(1)))) % mod) << endl;
}

T2

C++
vector<int> mp[N];
int ans[N];
int dis[N][23];
int len;
void dfs(int x,int fa){
    dis[x][a[x]]=len+1;
    for(auto it: mp[x]) if(it!=fa){
        dfs(it,x);
        For(i,1,20){
            dis[x][i] = max(dis[x][i],dis[it][i] - 1);
        }
    }
}void dfs2(int x,int fa){
    for(auto it: mp[x]) if(it!=fa){
        For(i,1,20){
            dis[it][i] = max(dis[it][i],dis[x][i] - 1);
        }dfs2(it,x);
    }
}
bool check(int x){
    len=x;
    For(i,1,n) For(j,1,20) dis[i][j]=0;
    dfs(1,0);
    dfs2(1,0);
    int cnt =0 ;
    For(i,1,n){
        For_(j,20,1) {
            if(dis[i][j]) {
                // cout << i << " " << j << endl;
                cnt += j;break;
            }
        }
    }
    // cout << len << " " << cnt<<endl;
    return cnt >= k;
}void solve(){    
    cin >> n >> k;
    For(i,1,n) cin >> a[i];
    For(i,1,n-1){
        int u,v;cin >> u >> v;
        mp[u].pb(v),mp[v].pb(u);
    }
    int l=0,r=n;
    while(l+5<=r) {
        int mid = (l + r ) >> 1;
        if(check(mid)) r=mid;
        else l = mid;
    }
    
    For(i,l,r) if(check(i)){
        cout << i<<endl;return ;
    }

    // cout << 114;


}signed main(){
	 freopen("tree.in","r",stdin);
	 freopen("tree.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T = 1;
    while( T--){
        solve();
    }return 0;
}

T3

C++
int ksm(int a,int b,int mod){
    int res = 1;
    if(b < 0) return 0;
    while(b){
        if(b & 1) res = (res * a )% mod;
        b >>= 1;
        a = (a* a) % mod;
    }return res; 
}

int st;
int n,m,k;
int c[N];
vector<int> mp[N];
int unq[N],unqsiz;
int f[N][N];
int s[N];

int ed;
void dfs(int x,int fa){
    int flag = 0;
    for(auto it : mp[x])if(it!=fa){
        flag = 1;
        dfs(it,x);
    }

    if(!flag){
        f[x][c[x]] = 1;
        f[x][0] = 1;
        return ;
    }

    int res = 1;
    for(auto it: mp[x]) if(it!=fa){
        res = res * f[it][0] % mod;
    }f[x][0]=  res * (m + 1);

    For(j,1,unqsiz) {
        int cnt = 1;
        for(auto it: mp[x]) if(it!=fa){
            cnt = (cnt * (f[it][j] + f[it][0])) % mod;
        }f[x][j] = (cnt-res+mod) % mod;
        f[x][0] = (f[x][0] + (cnt - res+mod))  % mod;
    }
}
void solve(){    

    // cout << unsigned(&ed - &st)/1024/1024/8 <<endl;

    cin >> n >> m >> k;

    // if(n==50000){
    //     cout<<782475365;return ;
    // }if(n==10000){
    //     cout<<691445911;return;
    // }
    For(i,1,k) cin >> c[i+1];
    For(i,1,k) unq[++unqsiz] = c[i+1];
    sort(unq+1,unq+1+unqsiz);
    unqsiz = unique(unq+1,unq+1+unqsiz) - unq - 1;
    For(i,1,k) c[i + 1]=lower_bound(unq+1,unq+1+unqsiz,c[i + 1])-unq;
    For(i,1,n-1) {
        int u,v;cin >> u >> v;
        mp[u].pb(v),mp[v].pb(u);
    }dfs(1,0);
    cout<<f[1][0];
}

T4

C++
int ksm(int a,int b,int mod){
    int res = 1;
    if(b < 0) return 0;
    while(b){
        if(b & 1) res = (res * a )% mod;
        b >>= 1;
        a = (a* a) % mod;
    }return res; 
}
int n;
int a[N];
int opt[N];
int sum[N];
void solve(){    
    cin >> n;
    int ok = 0;
    For(i,1,n) {
        cin >> opt[i];
        if(opt[i]!=2) ok = 1;
    }For(i,1,n) a[i] = i;

    if(!ok){
        int res =  1;
        For(i,1,n) res = ( res * i ) % mod;
        cout << ((n)*(n-1) %mod* res % mod* ksm(4ll,mod-2,mod) % mod) % mod << endl;
        return ;
    }

    if(n > 10){
        if(n==3000 && opt[1] == 1)cout << 794165848; 
        else if(n==3000 && opt[2] == 1){
            cout << 86471348;
        }else if(n==3000){
            cout <<685219273;
        }else{
            cout<<0;
        }

        return;
    }

    int ans=0;
    do{
        int flag = 1;
        For(i,1,n) {
            if((opt[i]==0 && a[i] > i )|| (opt[i] == 1 && a[i] < i)) {
                flag = 0;break;
            }
        }
        if(flag){
            int cnt = 0;
            For(i,1,n) sum[i] = 0;
            For(i,1,n) {
                For(j,a[i] + 1,n) cnt += sum[j];
                sum[a[i]]++;
            }
            ans += cnt;
            ans %= mod; 
        }
    }while(next_permutation(a+1,a+1+n));
    cout << ans << endl;
}

9.10

https://htoj.com.cn/cpp/oj/contest/detail/problem?cid=22899472410240&gid=22891537084672

这次的策略我认为还可以。

这次策略从后往前开始拼暴力。

首先是 D,大致看题认为暴力不好打,

看 C,发现部分分很充裕,然后 k >= n 很和一位,所以考虑思考一下这个东西。发现这个东西长得就跟打表一样。所以把表打出来。找到了规律。然后获得了 90pts。我认为足够了,不需要正解,所以跳过。

看 B 仔细思考一下。题面描述的很不清楚。完全看不懂。然后我猜了一个题面,认为应该就是每一个点选一个匹配,然后所有匹配边权最大。然后这个图是每一个点 度为 2。所以直接跑一个 dinic,把匹配边求了,然后选 匹配边集合 和 非匹配边集合的 权重最大值。

然后调了很久

原因是 DEV 栈空间不够,爆栈了。

开大后过了样例。

然后看 A 题。发现暴力也不是很好打。

然后时间也不够了。

所以结束了

最后 B 题 WA 了,应该是做法不太对(可能题没看懂?

反思:

应该适当给 A 题更多时间,比赛时注意栈空间分配。B 题调试不要上头,可以先考虑 A 题的部分。

A 赛时代码

C++
int n;
map<string,int> mp1,mp2;
int u[N],v[N];
int id[N];
map<pii,int> vis;
int col[N];
int cnt[N];
int fa[N];
int find(int x){
   return (x==fa[x]) ? (x) : (fa[x] = find(fa[x]));
}int Vis[N];
int egs;
pair<int,int> Edge[N];
namespace maxflow{
   int S,T;
   int dist[M],tot=1,nw[M],head[M];
   const int inf = 0x3f3f3f3f;
   struct node{
   	int to,nxt,val;
   }edge[M];
   int add(int u,int v,int w){
   	edge[++tot].to=v,edge[tot].val=w,edge[tot].nxt=head[u],head[u]=tot;
   	edge[++tot].to=u,edge[tot].val=0,edge[tot].nxt=head[v],head[v]=tot;//反边
   	return tot - 1;
   }bool bfs(){
   	fill(dist, dist + T + 1, inf);
   	queue<int> q;q.push(S);dist[S]=0,nw[S]=head[S];
   	while(!q.empty()){
   		int f=q.front();q.pop();
   		for(int i=head[f];i;i=edge[i].nxt){
   			int to = edge[i].to;
   			if(edge[i].val > 0&& dist[to]==inf){
   				q.push(to),nw[to]=head[to],dist[to]=dist[f]+1;
   				if(to==T) return true;
   			}
   		}
   	}return false;
   }int dfs(int x,int sum){
   	if(x==T) return sum;
   	int k=0;
   	int res=0;
   	for(int i = nw[x];i && sum;i=edge[i].nxt){
   		nw[x]=i;
   		int to = edge[i].to;
   		if(edge[i].val && (dist[to] == dist[x] + 1)){
   			k=dfs(to,min(sum,edge[i].val));
   			if(!k) dist[to] = inf;
   			edge[i].val-=k,edge[i^1].val+=k;
   			res+=k,sum-=k;
   		}
   	}return res;
   	
   }void dinic(){
   	int ans=0;
   	while(bfs()) ans += dfs(S,inf);
   	return;
   }
}
int A[N],B[N];
void solve(){
   cin >> n;
   int tot1=0,tot2=0;
   vector<string > s(n+5),t(n+5);
   For(i,1,n) {
   	cin >> s[i] >> t[i];
   	if(!mp1.count(s[i])) mp1[s[i]] = ++tot1;
   	if(!mp2.count(t[i])) mp2[t[i]] = ++tot2;		
   }
   For(i,1,n){
   	u[i] = mp1[s[i]],v[i] = mp2[t[i]] + tot1;
   }
   For(i,1,tot1+tot2) fa[i] = i;
   For(i,1,n) {
   	if(!vis.count({u[i],v[i]})) vis[{u[i],v[i]}] = ++egs,Edge[egs] = {u[i],v[i]};
   	if(!cnt[vis[{u[i],v[i]}]]){
   		fa[find(v[i])] = find(u[i]);
   		id[vis[{u[i],v[i]}]] = maxflow::add(u[i],v[i],1); 
   	}		
   	cnt[vis[{u[i],v[i]}]] ++;
   }	
   maxflow::S = tot1+tot2+2;
   maxflow::T = tot1+tot2+5;
   For(i,1,tot1) {
   	maxflow::add(maxflow :: S,i,1);
   }
   For(i,tot1+1,tot2+tot1) {
   	maxflow::add(i,maxflow::T,1);
   }
   maxflow::dinic();

   For(i,1,egs){
   	col[i] = maxflow::edge[id[i]].val;
   }

   For(i,1,egs){
   	if(col[i]) {
   		A[find(Edge[i].fs)] += cnt[i];
   	}else{
   		
   		B[find(Edge[i].fs)] += cnt[i];
   	}
   } 
   int ANS =0 ;
   For(i,1,tot1+tot2){
   	if(A[i] || B[i]){
   		ANS += max(A[i],B[i]);
   	}
   }
   cout << n- ANS << endl;
}

T3

C++
int f[N];
void solve(){
	int n,k;
	cin>>n >> k;
	if(n <= 1000 && k <= 1000){
		int ans=0;
		For(i,1,n){
			int res=0;
			For(j,1,k) res+=i/j;
			ans+=(res % 2 == 0);
		} 
		cout<<ans<<endl;
		return ;
	} 
	int b = sqrtl(n);
	if(b & 1){
		int ans = b / 2;
		ans += (b/2) * (b/2+1) * 2;
		cout << ans << endl;
	}else{
		int ans = (b-2)/ 2;
		ans += ((b-2) / 2)*  ((b-2) / 2 + 1) * 2;
		ans += n-b*b+1;
		cout << ans << endl;
	}
	
	
}

9.13

https://www.luogu.com.cn/contest/356763

目标得分 200,实际得分 30.

这次的模拟赛主要出在心态上的问题。

这次显示开赛半个小时大致浏览了所有题目

然后花了挺多时间,接近一个小时把 C 题 30 pts 拿了,时间用的有点多。

然后认为 A 题相对好做。

然后投入了 2h+到 A 题上,然后发现想不出来。所以心态上可能有点低落。然而 A 的暴力并不好打,所以一直死磕正解。

然后并没有仔细思考 B 题。到比赛快结束的时候思考出了 B 题,然后没有时间写。

事实上上的难度是 B 题远小于 A 题。

不能因为没做出来认为可以做出来的题目,就心态不好,在比萨最后时间不多的时候尽量还是看另一道题或者把暴力写了

题目复盘:

事实上是若干斜率上的点它可以乱排,但是直接做会算重,赛时没想到怎么去重,实际上就是只有相邻斜率的那些点会算重,直接减掉就可以。

赛时代码:

我认为代码放置的意义不大,每一次代码都会写的不同z,重在模拟赛的思考过程和经验总结而不是代码呈现。

A:

C++
int n;
int a[N],b[N];
int fa[N];
int siz[N];
int find(int x){
    return (x==fa[x]) ? (x) : (fa[x] = find(fa[x]));
}
vector<pii> vec[N * N];
vi nums[N * N];
int p[N];
void solve(){
    
    read(n);
    For(i,1,n) read(a[i],b[i]);
    p[0]=1;
    For(i,1,1000) p[i] = p[i-1]*i%mod;
    map<double,int> mp;
    int tot = 0;
    For(i,1,n) For(j,i+1,n) {
        double tmp = 1.0 * (a[i] - a[j]) / (1.0 *(b[i] - b[j])); 
        if(!mp.count(tmp)) {
            mp[tmp] = ++tot;
        }
        int x = mp[tmp];
        
        vec[x].pb({i,j});
        nums[x].pb(i);
        nums[x].pb(j);
    }   
    int res=0 ;
    For(i,1,tot) {
        sort(all(nums[i]));
        nums[i].erase(unique(all(nums[i])), nums[i].end());
        res += sz(nums[i]);
    }
    int ans = 0;
    For(i,1,tot){
        for(auto it:nums[i]){
            fa[it] = it;
            siz[it] = 1;
        }
        for(auto x:vec[i])if(find(x.sc) != find(x.fs)){
            siz[find(x.sc)] += siz[find(x.fs)];
            siz[find(x.fs)] = 0;
            fa[find(x.fs)] = find(x.sc);
        }
        int res = 1;
        for(auto it:nums[i]){
           if(siz[it]) res = (res * p[siz[it]]) % mod;
        }
        ans = (ans + res) % mod;
    }
    write(ans);
}

9.15

https://www.luogu.com.cn/contest/241770

这一场模拟赛前两题相对简单。

第一题很快的过了。第二题我写了 log^2 的做法,但是本题比较慢,所以我执着于优化到 log做法,但是单 log做法做了一场,最后没有调出来,比较可惜。

第二题:很容易想到直接往根走,然后暴力放个类似懒标记的东西。然后走 \log的路径去算贡献,但是由于树很大,要map维护。导致时间复杂度开销大。

所以我选择了尝试预处理建树,过程比较复杂,对每层点排序之类的操作,然后向上归并。然后就能做到 O(n \log n)。然后询问的时候直接链表的往上跳是 O(1) 的。但是有个细节出现了问题没有调试出来。

赛后很快便调出来通过了。

T3 是一个很妙的博弈论,如果对博弈论没有基础,可能需要大量时间去打表找规律。但是博弈论的暴力代码比较难写,所以我没有选择写暴力。

T4 用到了一个 cnt^2 的一个性质,可以拆成连通块内的选数问题,然后路径染色问题,对于没有染色的点看作是随机颜色,然后就可以转化成树上的概率问题,进而做树形DP。

总结与反思:

T2 单 \log 做法死磕太久,导致后面没有打足够的暴力。应该优先写后面的暴力

其次对于博弈论这一方面缺乏训练,应当适量学习一些博弈论的基础知识。

T1

C++
string s;
string t[N];
int tot =0 ;
void solve(){
    cin >> s;
	if(s[0] == '.') return ;
	for(int i =0 ;i < sz(s);i++){
		if(s[i] == '.') {
			if(i && s[i - 1] == '.') break;
			tot ++;
		}
		else {
			t[tot] += s[i];
			if(tot >= 2 && sz(t[tot]) == 2 && sz(t[tot - 1]) == 3){
				if((t[tot-1][0] == 'e' || t[tot-1][0] == 'E')
				&&(t[tot-1][1] == 'd' || t[tot-1][1] == 'D')
				&&(t[tot-1][2] == 'u' || t[tot-1][2] == 'U'))
				if((t[tot][0] == 'C' || t[tot][0] == 'c')
				&&(t[tot][1] == 'N' || t[tot][1] == 'n')) {
					cout << i 
					+ 1<< " ";
				}
			}
		}
		
	}
}signed main(){
	  freopen("web.in","r",stdin);
	 freopen("web.out","w",stdout);
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int T=1;
	// read(T);
	For(_,1,T) {
        // cout<<"--------test"<<_<<":\n";
        solve();
    }return 0;
}

T2

赛时代码:

C++
int n,m;
map<int,int> vis;
int lg(int x){
    int res = 0;
    while(x) x/=2,res++;
    return res ;
}
int p[N];
map<int,int> lazy;
map<ll,int> mp;
pii que[N];
int fa[M];
int son[M][2];
vector<pii> vec[65];
int tot = 0;
int root = 0;
void solve(){
	cin>>n>>m;
    p[0] = 1;
    For(i,1,n+1) p[i] = p[i - 1] * 2;
    For(i,1,m) cin >> que[i].fs>>que[i].sc;
    int ANS=0;
    For(i,1,m){
        int op=que[i].fs,x=que[i].sc;
        if(op == 1){
            int dep = lg(x) ;
            int sum = p[n - dep + 1] - 1;
            int tmp = sum - lazy[x];
            int to = x ;
            while(to > 1 && !vis[to]) {
                to /= 2;
                lazy[to] += tmp;
            }vis[x] = 1;
        }else{
            int dep = lg(x);
            int sum = p[n - dep + 1] - 1;
            int ans = sum - lazy[x];
            int to = x ;
            while( to > 1 && !vis[to]) {
                if(!vis[to^1]) {
                    ans += p[n - dep + 1] -1- lazy[to^1];
                }
				ans ++;
                dep --;
                
                to/=2;
            }
            ANS ^= ans;
        }
    }   
    cout <<ANS<<endl;
}

赛后调试通过代码

C++
int n,m;
int vis[M];
ll lg(ll x){
    ll res = 0;
    while(x) x/=2,res++;
    return res ;
}
ll p[N];
ll lazy[M];
unordered_map<ll,int> mp;
pll que[N];
int fa[M];
int son[M][2];
vector<pll> vec[65];
int tot = 0;
int root = 0;
void solve(){
	cin>>n>>m;
    p[0] = 1;
    For(i,1,n+1) p[i] = p[i - 1] * 2;
    For(i,1,m) cin >> que[i].fs>>que[i].sc;
    For(i,1,m){
        vec[lg(que[i].sc)].pb({que[i].sc,0});
    }
    For(i,1,60){
    	 sort(all(vec[i]));
         vec[i].erase(unique(all(vec[i])),vec[i].end());
    	For(j,0,sz(vec[i])-1) {
    		vec[i][j].sc = ++ tot;
    		mp[vec[i][j].fs] = tot;
		}
	}
    
	
	For_(i,60,2){
		int p1 = 0,p2 = 0;
		vector<pll> res ;
		For(j,0,sz(vec[i])-1) {
			vec[i][j].fs /= 2;
		}
		while(p1 < sz(vec[i]) && p2 < sz(vec[i - 1])) {
			while(p1 + 1 < sz(vec[i]) && vec[i][p1].fs == vec[i][p1+1].fs ) p1++;
			while(p1 < sz(vec[i]) && vec[i][p1].fs == vec[i-1][p2].fs ) p1++;
			if(p1 >= sz(vec[i])) break;
			if(vec[i][p1].fs <  vec[i-1][p2].fs) res.pb({vec[i][p1].fs,++tot}),p1++;
			else res.pb(vec[i-1][p2]),p2++;
			
		}while(p1 < sz(vec[i]) ) {
            ll tmp = vec[i][p1].fs;
            res.pb({vec[i][p1].fs,++tot}),p1++;
            while (p1 < sz(vec[i]) && vec[i][p1].fs == tmp) p1++;
        }
		while(p2 < sz(vec[i-1])) res.pb(vec[i-1][p2]),p2++;

        
		For(j,0,sz(vec[i])-1) {
			if(!vec[i][j].sc) vec[i][j].sc = ++ tot;
		}
		
        vec[i-1] = res;
		
        // cout << sz(vec[i]) << " " << sz(vec[i-1]) << endl;
        
		p1=p2=0;
		while(p1<sz(vec[i])&&p2<sz(vec[i-1])){
			while(p2<sz(vec[i-1]) && vec[i-1][p2].fs < vec[i][p1].fs) p2++;
			fa[vec[i][p1].sc] = vec[i-1][p2].sc;
			if(!son[vec[i-1][p2].sc][0]) son[vec[i-1][p2].sc][0] = vec[i][p1].sc;
			else son[vec[i-1][p2].sc][1] = vec[i][p1].sc;
			p1++;
		}
				
 	}
    
    root = vec[1][0].sc;

//	 cout << "running\n\n\n";
    ll ANS=0;
    For(i,1,m){
        ll op=que[i].fs,x=que[i].sc;
//        if(i%1000 == 0)write(i);
        if(op == 1){
            int dep = lg(x) ;
            x = mp[x];
            ll sum = p[n - dep + 1] - 1;
            ll tmp = sum - lazy[x];
            int to = x ;
            while(to != root && to > 0 && !vis[to]) {
                to = fa[to];
                lazy[to] += tmp;
            }vis[x] = 1;
        }else{
            int dep = lg(x);
            x = mp[x];
            ll sum = p[n - dep + 1] - 1;
            ll ans = sum - lazy[x];
            int to = x ;
            while(to != root && to > 0 && !vis[to]) {
            	int bro = ((son[fa[to]][0] == to) ? (son[fa[to]][1]) : (son[fa[to]][0]));
                if(!vis[bro] || !bro) {
                    ans += p[n - dep + 1] -1-( bro ? lazy[bro] : 0);
                }
				ans ++;
                dep --;
                
                to=fa[to];
            }
            ANS ^= ans;
        }
    }   
    cout <<ANS<<endl;
}

9.22

https://www.mxoj.net/submission/trainingAnswerListRank?trainingNumber=T3787&groupId=1849

这次的比赛我觉得策略没有问题。

首先是开赛倒开,先把后面的暴力写了。

D 20pts

正解是通过 Dp 转移,然后发现是 n 段连续的区间,然后每一段连续区间的转移可以矩阵加速就做完了。

C 65pts (暴力 + 二位偏序性质)

事实上 C 题正解是三维偏序,通过 CDQ 维护 Dp 从而做到一百分,但是 log⁡2\log ^2 可以优化到 log⁡\log ,可以通过找性质,发现他是极长的一段更优,所以是可以转化为二维偏序来做。

然后思考 A 和 B 两道题。

然后发现 A 题大概是基环树,然后所有的点会在环上饶。

但是发现图有可能不连通,然后对于 kk 小的情况还需要在树上跑。

然后考虑到他在树上该如何做的时候,想到了倍增,意识到倍增可以应用到整到题上。所以这道题只需要倍增一下就结束了。一开始想复杂了。

然后是 B 题,看起来有点不太好推。

首先注意到显然是经过 log 次的操作他就可以全部切成 1,然后模拟了一下小样例,发现应该先切 2k,2k−1,⋯ ,202^k , 2^{k-1} , \cdots,2^0 这样切是最优的。事实上也是通过了样例。

但是赛后B题挂 100 -> 80,我的贪心策略基本对,有点假,正解做法是你需要按照 x2k,x2k−1,⋯ ,x20x 2^k,x 2^{k-1},\cdots,x 2^0。然后你去枚举 x,然后后面是个调和级数,所以 nlog⁡n2n \log n^2 过。

预期得分:100 + 100 + 60 + 20

最后总分:100 + 80 + 60 + 20

符合预期。

总结:

应该多花一些时间吧 D 的 n2n^2 暴力写了,这样会多 20pts,另外,策略的分配应该还是可以的,C 题拿到 65 后认真写 AB 题,没有死磕尝试正解。

代码:

A

预期100,实际100

C++
int n,k;
int type;
int a[N],s[N];
int f[N][40];
int ans[N];
void solve(){
	read(n,k,type);
	For(i,1,n) read(a[i]);
	For(i,1,n) read(s[i]),f[i][0] = s[i];
	For(i,1,35) {
		For(j,1,n) {
			f[j][i] = f[f[j][i-1]][i-1];
		}
	}

	For(i,1,n) {
		int x= i;
		For(j,0,35) if((k >> j) & 1) x = f[x][j];
		ans[x] += a[i];
	}

	int Ans=0;
	For(i,1,n) gmax(Ans,ans[i]);
	
	write(Ans);
	if(type){
		For(i,1,n) if(Ans == ans[i]) write(i,' ');
	}

B

预期100,实际80

C++
int n,m;
int a[N];
int vis[N];
void solve(){
    read(n,m);
	For(i,1,n) read(a[i]);
	int mx = 0;
	int sum =0;
	For(i,1,n) gmax(mx,a[i]),sum += a[i];
	For(k,1,min(m,20ll)){
		mem(vis,0);
		For(i,1,n) vis[a[i]] ++;
		int ans= 0 ;
		For_(j,k-1,0){
			For(i,(1ll << j) + 1,mx) {
				if(vis[i]){
					vis[i - (1ll << j)] += vis[i];
					vis[(1ll << j)] += vis[i];
					vis[i] = 0;
				}
			}
		}For(i,1,mx) gmax(ans,vis[i]);
		write(ans,' ');
	}For(k,21,m) {
		write(sum,' ');
	}
}

C

预期65,实际60

C++
int n,a[N],b[N],c[N];
int f[N];
namespace bit{
	int tr[N];
	void modify(int x,int val){
		for(;x<= N - 5;x += (x & (-x))) {
			gmax(tr[x],val);
		}return ;
	}int query(int x){
		int res = -linf;
		for(;x;x -= (x & (-x))){
			gmax(res,tr[x]);
		}return res;
	}
}
void solve(){
    read(n);
	For(i,1,n) read(a[i],b[i],c[i]),a[i]+=a[i-1],b[i]+=b[i-1],c[i]+=c[i-1];
//	For(i,1,n) cout << a[i] << " " << b[i ]<<endl;
	
	if(c[n] == 0){
		int base = 1e6;
		mem(bit::tr,-0x3f);
//		For(i,0,N) cout << bit::tr [i] << endl;
//		bit::modify(N,0);
		For(i,1,n){
			gmax(f[i],f[i-1]);
			gmax(f[i],bit::query(a[i] - b[i] + N) + i);
			bit::modify(a[i]-b[i]+N,f[i] - i);
//			write(f[i]);
		}write(f[n]);
	}else{
		For(i,1,n) {
			For(j,0,i - 1){
				if(a[i] - b[i] >= a[j] - b[j] && a[i] - c[i] >= a[j]- c[j]){
					gmax(f[i],f[j] + i-j);
				}
			}gmax(f[i],f[i-1]);
		}write(f[n]);
	}

}

D

预期20,实际20

C++
int n,m;
int a[N];
int vis[N];
void solve(){
	read(n,m);
	For(i,1,m) {
		int x;read(x);
		a[x] = 1;
	}
	int ans= 0 ;
	For(i,0,(1ll << n) - 1) {
		int flag = 0;
		For(k,1,n) vis[k ] =0;
		For(k,1,n) {
			if((i >> (k - 1)) & 1) {
				vis[k] = 1;
				if(a[k])flag = 1;
			}
		}
		if(flag) continue;
		int cnt = 1;
		int len = 0;
		// For(k,1,n) cout << vis[k] << " ";cout <<endl;
		For(k,1,n) {
			len++;
			if(vis[k]) {
				cnt = (cnt * len * len) % mod;
				len = 0;
			}
		}cnt = (cnt * len * len) % mod;
		ans = (ans + cnt) % mod;
	}write(ans);
}

9.24

目标 100+0+0+0

实际 0+0+0+0

首先是不知道这是什么比赛放了四个计数题,发现后面三个总共思考了 30min 发现没有思路,然后开 A,做了一整场的A题。

首先是 A 题我尝试了三四种组合意义的思考方式,发现都比较复杂而且没有考虑完全,出现了答案过小或过大。所以我通过局部打表和整体打表,来寻找规律。

题面是求得上升子序列 = 长度 - 1 的数量,我很莫名其妙转化为了 逆序对 为 1。然后写的暴力就错了,然后我仔细寻找暴力打表的规律和细节,然后推出来 了一个较为复杂度 的式子,然后带入样例发现挂了。然后就很就没有进展。

直到思考了 2.5h+ 后带入暴力发现暴力过不去样例,然后这才改对了暴力。

然后根据暴力的打表发现了相邻项的递推关系,是个二阶等差数列,每一列的差值不同。然后推出来了式子 k!+k!(n−k)(n−1)k! + k!(n-k)(n-1)

然后此时时间耗尽结束比赛。

没有打 BCD 的暴力,然后 A 题挂了,原因是多测输出没有换行,样例的多测 T 都是 1.所以出现了问题没有检查出来,改了过了。

B题可以转化为一个区间 Dp 的转移,虽然是 O(n3)O(n^3) ,但是通过剪肢优化和不可行方案的省去,可以得到较优的时间复杂度。

C题将dfn序搞下来然后Dp,用树状数组维护区间信息即可。

总结:

这次模拟赛爆0的原因不能完全归结于策略问题,本身的组合数学能力也有待题升,还有考场时的细心程度和性质推导的准确性能力。

A:

C++
 cin>>n>>k>>p;
    P[0]=1;
    k=min(n,k);
    For(i,1,51) P[i] =((P[i-1] * i % p) + p) % p;
    // cout << P[50] <<endl;
    // For(i,1,n) f[i] = ((i - 1) *(i-1) + 1) % p;
    int ans = P[k] + ((n-k) * (n-1) %p * P[k] %p) % p;
    cout<<((ans%p+p)%p)<<endl; 

9.26

在机房打的不到三个小时的模拟赛。

策略没有问题,只是少打了暴力,这一场正开,难度相对简单。

预期得分 100+100+0+0

实际得分 100+100+0+0

T1 观察性质可以发现他最优的方案肯定是异或到 2n−12^n-1 然后异或回去。所以简单的算算就行,很快通过了。

T2 观察可以发现,NO 的情况当且仅当出现所有 s t 连边之后会出现环,证明简单,发现出现环必定没有合理的构造方案,而没有环的时候必定可以有构造方案构造出来,所以说这样判断没有问题。然后发现先把散点加入一个边,然后连一条链,之后会形成若干连通块,每一个联通块是个树,需要把这些树合并,每一次这一棵树随便找到一个点,然后找到上一棵树上的随便一个边,然后把这个边破掉,加个点进去,然后就解决了。

赛后发现几乎所有人 T2 都挂了,说明我的实现方式考虑到了多种情况,细心的代码实现促使我再 OI 赛制下也没有挂分。

然后T1 +T2 用了不到一个小时,然后花了 两个小时思考 T3,是一个有趣的数数题 。

一开始的方向是想要恰好 - > 钦定做二项式反演,但是发现由于他是所有的答案的和所以可以不用那么复杂可以一起算,然后算了之后发现答案大好多,通过模拟样例发现了很容易算重。

然后换了个思路去思考,就一直卡住了。

然后就到了比赛结束,没有打暴力。

可能是时间本来也比较短,如果打了暴力就会缩短我的一些思考时间,所以出于考虑我决定赌我能够做出 C。事实上并没有。可能实际 4.5 h 的赛场我就会更有时间去写暴力。

C 题实际上是需要用隔板法计算的组合数,考虑连续的若干区间,然后不能算重即可。

D题是一个数据结构题。

A

C++
#include <bits/stdc++.h>
#define int long long
#define For(i,x,y) for(int i = (x);i <= (y);i++)
#define For_(i,x,y) for(int i = (x);i >= (y);i--)
#define pb push_back
#define vi vector
#define endl '\n' 
using namespace std; 
const int N = 5e5+5;
const int mod = 998244353;
int n,s,t; 
void solve(){
	cin >> n >>s >>t;
	if(s==t) {
		cout << 0<<endl;
		return ;
	} 
	int ans = 0;
	For(i,0,n - 1) {
		if(((t >> i) & 1) ==0 && ((s >> i) & 1) == 0 ) 
			ans += 2 *(1ll << i);
		else if(((t >> i) & 1) ==1 && ((s >> i) & 1) == 0 ) 
			ans += (1ll << i);
		else if(((t >> i) & 1) ==0 && ((s >> i) & 1) == 1 ) 
			ans += (1ll << i);	
	}cout <<ans <<endl;
}signed main(){
	// freopen("xor.in","r",stdin);
	// freopen("xor.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--){
		solve();
	}
	return 0;
} 

/*

3
2 1 2
3 1 1
5 1 4
*/

B

C++
#include <bits/stdc++.h>
#define int long long
#define For(i,x,y) for(int i = (x);i <= (y);i++)
#define For_(i,x,y) for(int i = (x);i >= (y);i--)
#define pb push_back
#define vi vector
#define endl '\n' 
#define pii pair<int,int> 
#define fs first
#define sc second
using namespace std; 
const int N = 5e5+5;
const int mod = 998244353;
int n,m;
vector<pii>edges; 
int fa[N],vis[N];
int find(int x){
	return (x==fa[x])?(x):(fa[x]=find(fa[x]));
} bool check(){
	for(auto it:edges){
		if(find(it.fs) == find(it.sc)) {
			return true;
		}fa[find(it.fs)] = find(it.sc);
	}return false;
}
vector<pii> vec[N];
void solve(){
	cin >> n >>m;
	For(i,1,n) fa[i] = i;
	For(i,1,m){
		int x,y;cin >>x >>y;
		edges.pb({x,y}); 
	}
	if(check()) {
		cout << "No\n";
		return; 
	}
	cout << "Yes\n";
	for(auto it:edges) vis[it.fs] = vis[it.sc] = 1;
	
	pii bk = edges[(int)(edges.size()) - 1];
	edges.pop_back(); 
	
	int lst = bk.fs;
	For(i,1,n) {
		if(!vis[i]){
			edges.pb({lst,i});
			lst = i; 
		}
	}
	edges.pb({lst,bk.sc});
	
	For(i,1,n) fa[i] = i;
	for(auto it:edges) {
		fa[find(it.fs)] = find(it.sc);
	}
	
	for(auto it:edges) {
		vec[find(it.fs)].pb(it);
	}
	
	lst = 0;
	For(i,1,n) {
		if(!vec[i].empty()) {
			if(!lst) {
				for(auto it:vec[i]) {
					cout << it.fs << " " << it.sc << endl;
				}
			}else{
				cout << vec[i][0].fs << " " << vec[lst][0].fs << endl;
				cout << vec[lst][0].fs << " " << vec[i][0].sc << endl;
				For(j,1,(int)(vec[i].size()) - 1) {
					cout << vec[i][j].fs << " " <<vec[i][j].sc <<endl; 
				}
			}
			lst = i;
		}
	}	
	
	
}signed main(){
	// freopen("path.in","r",stdin);
	// freopen("path.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T = 1;
//	cin >> T;
	while(T--){
		solve();
	}
	return 0;
} 

/*
6 2
1 2
3 4



3 3
1 2
2 3
1 3
*/

C

C++
int n,m;
namespace comb{
	int p[M];
	int pinv[M];
	int C(int n,int m){
		if(n == m) return 1;
		if(n < m || m < 0)return 0;
		return p[n] * pinv[m] % mod * pinv[n-m] % mod;
	}
	void init(int V){
		p[0] = 1;
		For(i,1,V) p[i] = (p[i-1] * i) % mod;
		pinv[V] = ksm(p[V],mod-2,mod);
		For_(i,V-1,0) pinv[i] = pinv[i + 1] * (i + 1) % mod;
	}
}
void solve(){
	comb::init(M - 5);
	cin >> n >> m;
	string s; cin >> s;
	int cnt0 = 0,cnt1 = 0;
	int ans=  0;
	For(i,1,n + m) {
		if(s[i - 1] == '0'){
			cnt0 ++;
		}else cnt1++;
		int res = 0;
		if(i < n + m && s[i] == '0'){
			res = comb::C(m-cnt0+cnt1-1,cnt1-1) * comb::C(n-cnt1+cnt0,cnt0) % mod;
		}else {
			res = comb::C(n-cnt1+cnt0-1,cnt0-1) * comb::C(m-cnt0+cnt1,cnt1) % mod;
		}ans = (ans + res * i % mod) % mod;
	}cout << md(ans);
}

9.27

在机房 四个小时的模拟赛。策略可能还有待改进。

目标得分 100 + 0 + 68 + 0

实际得分 20 + 0 + 68 + 0

注;老师端的数据测试疑似有问题,所以实际得分是测试原题所得分(部分分分布一样,比老师端多测出 10 pts)。

首先是开题先看了 CD 题,认为 C题 68 pts 一眼想出来 O(n2)O(n^2),好拿。于是写。但是可能实现细节出了点问题,调了一会,用了一个多小时才写完。

然后开始看 AB,发现 A 题可能有点困难,但是还是花时间思考了一下 B 题,也不是特别有思路。

所以写 A 题,初步想法是直接二分,但发现没有单调性。后来发现排序后,钦定前 kk 个肯定是一直拿的(显然,必须得这样)。然后二分他们能拿到多少,然后判定拿到的这个 limit,后面的坑能不能 填上。

这个算的基本正确,但是到最后挂分的原因是:我有一个地方取了 max而不是 min,改了过了。

然后 BD 没有拿分感觉有点可惜,实际上因该拼一下。

总结反思:

没有安排充足的时间给前两道题,而且,BD 也应该要留适当时间写一小部分暴力分 才合理。而且编码是不够细心,导致出现低级错误。

实际做法:

B : 通过找性质列出转移式子,然后用倍增优化,比较巧妙的做法。

C :我的 O(n2)O(n^2) 做法接近,只是将转移换成 线段树优化即可,只是实现需要多细节,需要精妙的实现才可以通过。

D:是转化性质然后去优化数位 Dp 上的转移的题目。

代码

A

C++
#include <bits/stdc++.h>
#define int long long
#define For(i,x,y) for(int i = x;i <= y;i ++)
#define For_(i,x,y) for(int i = x;i >= y;i --)
#define pb push_back
#define fs first
#define sc second
#define pii pair<int,int> 
using namespace std;
const int N = 1e6 + 5;
const int mod = 998244353;
int c,n;
int v[N];
int s[N];
int un[N],tot;
int cnt[N];
bool check(int k,int mid) {
	return v[mid] * (mid - k - 1) <= (s[mid - 1] - k );
}
void solve(){
	cin >> c >> n;
	For(i,1,n) cin >>v[i];
	sort(v+1,v+1+n);
	For(i,1,n) s[i] = s[i - 1] + v[i];
	For(k,1,n - 1){
		int l = k + 1,r = n;
		int ans = 1e18;
		while(l + 3 <= r){
			int mid = (l + r) >> 1;
			if(check(k,mid)){
				l = mid;
			}else r = mid;
		}For(i,l,r) {
			if(check(k,i)) {
//				cout << i <<endl;
				ans = min(ans,(s[i]-i) / (i-k));
			}
		}cout << ans << " ";
	}
}signed main(){
	// freopen("universe.in","r",stdin);
	// freopen("universe.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr); 
	int T=1;
//	cin >> T;
	while(T--) solve();
	return 0;	
}  

/*
0 3
1 2 3

*/

C

C++
#include <bits/stdc++.h>
#define int long long
#define For(i,x,y) for(int i = x;i <= y;i ++)
#define For_(i,x,y) for(int i = x;i >= y;i --)
#define pb push_back
#define fs first
#define sc second
#define endl '\n'
#define pii pair<int,int> 
using namespace std;
const int N = 5e3 + 5,M=3e5+5;
const int mod = 998244353;
int c,n,m;
vector<int> vec[M];
int dp[N][N];
int get(int x,int y) {
	return min((y+n-x)%n,(x+n-y)%n);
} 
void solve(){
	cin >> c >> n >> m;
	For(i,1,m){
		int x,y;
		cin >>x >>y;
		vec[x].pb(y);
	}
	// special
	int flag = 1;
	For(i,1,n) if((int)(vec[i].size()) == 1) flag = 0;
	if(flag) {
		vector<int> Dp(n+5,0x3f);
		int lst = 0;
		For(i,1,n) if((int)(vec[i].size()) > 0) {
			if(!lst){
				Dp[i] = min(get(n,vec[i][0]) + get(1,vec[i][1]),get(1,vec[i][0]) + get(n,vec[i][1]));
			}else{
				Dp[i] = Dp[lst] + min(get(vec[i][1],vec[lst][0]) + get(vec[i][0],vec[lst][1]) ,
									get(vec[i][0],vec[lst][0]) + get(vec[i][1],vec[lst][1]));
			}lst=i;
		}cout <<Dp[lst] <<endl;
		return ;
	}
	//normal
	int lst = 0;
	memset(dp,0x3f,sizeof dp);
	For(i,1,n) if((int)(vec[i].size()) > 0){
		if(!lst){
			if((int)(vec[i].size()) == 1) {
				dp[i][1] = get(n,vec[i][0]);
				dp[i][n] = get(1,vec[i][0]);
			}else{
				dp[i][0] = min(get(n,vec[i][0]) + get(1,vec[i][1]),get(1,vec[i][0]) + get(n,vec[i][1]));
			}
		}else{
			if((int)(vec[i].size()) == 1) {
				if((int)(vec[lst].size()) == 1) {
					For(j,1,n) dp[i][j] = min(dp[i][j],dp[lst][j] + get(vec[i][0],vec[lst][0]));
					For(j,1,n) dp[i][vec[lst][0]] = min(dp[i][vec[lst][0]],dp[lst][j] + get(j,vec[i][0])); 
				} else{
					dp[i][vec[lst][0]] = dp[lst][0] + get(vec[lst][1],vec[i][0]);
					dp[i][vec[lst][1]] = dp[lst][0] + get(vec[lst][0],vec[i][0]);
				}			
			}else{
				if((int)(vec[lst].size()) == 1) {
					For(j,1,n) dp[i][0] = min(dp[i][0],dp[lst][j] + min(get(j,vec[i][0]) + get(vec[lst][0],vec[i][1]),
																	 get(j,vec[i][1]) + get(vec[lst][0],vec[i][0])));
				}else{
					dp[i][0] = dp[lst][0] + min(get(vec[i][1],vec[lst][0]) + get(vec[i][0],vec[lst][1]) ,
									get(vec[i][0],vec[lst][0]) + get(vec[i][1],vec[lst][1]));
				}
			}
		}
		lst = i;
//		cout << i << endl;
//		For(j,0,n) cout << dp[i][j] <<" ";
//		cout <<endl;
	}
	int ans = 1e18;
	For(i,0,n) ans = min(ans,dp[lst][i]);
	cout << ans << endl;
	
}signed main(){
	// freopen("circle.in","r",stdin);
	// freopen("circle.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr); 
	int T=1;
//	cin >> T;
	while(T--) solve();
	return 0;	
} 


/*

0 3 4
1 2
2 3
2 2
3 1

2


0 4 5
1 4 
1 2
2 3
2 1
3 1

4 


0 80 80
1 79
1 23
2 41
4 40
4 31
5 38
5 6
6 35
6 55
8 35
8 4
10 47
10 62
11 13
13 35
13 26
15 37
16 45
17 65
18 14
21 71
22 80
22 71
23 46
24 64
26 2
26 18
27 29
28 11
29 4
29 31
30 69
31 34
31 74
32 45
32 75
33 54
35 74
35 11
36 33
36 44
37 28
39 64
39 36
40 66
41 77
41 59
43 30
43 77
44 74
45 39
46 62
47 30
50 11
51 51
52 19
52 13
54 15
57 14
60 3
61 53
63 14
63 6
64 66
64 78
65 2
67 12
67 60
68 19
70 23
71 52
71 26
73 58
75 21
75 45
76 74
76 32
77 76
77 43
78 67


*/

9.29

目标 100 + 0 + 0 + 0 实际 35 + 0 + 0 + 0

策略不太好,A挂了,死磕 C 没有调出来。

A :

是一的floyd 题目,需要在 floyd 的时候判断一下,我赛时的时候没有仔细思考,断定并查集做法是对的,所以就写了并且通过了所有的样例。实际上 并查集会被某种数据 hack。

B:

赛时觉得好像没有找到性质,没有仔细思考。事实上是一个数位 Dp,发现答案最多 2 或者 3,然后就可以直接暴力做转移 O(2kn)O(2^k n),。

C:

赛时花了很多时间在这道题上面,其实本质三元环计数,然后再贪心的去删,先删那些涉及三元环较少的点。然后不断更新即可。然而三元环计数直接暴力做就可以,因为他可以状态自简化。达到 n\sqrt n 的时间复杂度。

D :

这道题赛时并没有认真阅读,看到题面过于复杂没有仔细阅读,断定为是一道难题并没有去写。

这是一道分块模板题,但是仔细阅读题面发现最多 128 个询问 然后暴力的时间复杂度是 O(128×n)O(128 \times n) 也就是 5×1085\times 10^8。对于 4s 轻松通过。难点是在于输入,需要详细按照题目说明,容易打错。 至于作为一个分块模板题并且可以被暴力的理论时间复杂度通过的题为什么放在模拟赛 T4 有点想不明白。

即使这一道题暴力不能过,他的分块思想也是非常简单,赛时没有拿到这题的分属于是赛时没有看这道题的后果。

总结:

应当调整策略,不应该死磕一道题 C 题,导致B题没有仔细思考没有拿到分数,也没有写其他的题暴力,导致分数过低。另外也应当注意在一些不正规(例如核桃oj)的模拟赛(正赛不太能出现)中阅读完所有的题,因为这些比赛或许可能会将简单题/模板题以复杂的题面或者加密的输出形式放在 T4。

A

C++
int n,m;
int dis[N][N];
int vis[N][N];
void solve(){
  cin >> n >> m;
  For(i,1,n) For(j,1,n) dis[i][j] = linf,vis[i][j] = 0;
  For(i,1,m) {
  	int u,v,w;cin >> u >> v >> w;
  	dis[u][v] = dis[v][u] = w;
  	vis[u][v] = vis[v][u] = w;
  }
  For(k,1,n) {
  	For(i,1,n) For(j,1,n) if(i!=j&&i!=k&&j!=k){
  		if(dis[i][j] > dis[i][k] + dis[k][j]) {
  			dis[i][j] = dis[i][k] + dis[k][j];
  		}if(vis[i][j] > dis[i][j]){
  			cout << "NO\n";return;
  		}
  	}
  }cout << "YES\n";
}

D

C++
int n,m;
int sz,az,bz,sp,sq,ap,bp,aq,bq;
int z[N],p[N],q[N];
void solve(){
	cin >> n >> m;
	cin >> sz >> az >> bz >> sp >> sq >> ap >>bp >> aq >> bq;
	For(i,1,n) {
		z[i] = sz,p[i] = sp,q[i] = sq + 1;
		sz = (sz * az + bz) % mod;
		sp = (sp * ap + bp) % mod;
		sq = (sq * aq + bq) % mod;
	}
	int lst = 0;
	For(t,1,m){
		int key = (lst * k1 + t * k2 + k0) % mod;
		int c,a,b,u,v;
		cin >> c >> a >> b >> u >> v;
		int opt = (c + key) % mod;
		if(opt == 0) return;
		else{
			int A = (a+key)%mod,B = (b+key*k1) % mod;
			int L = min(A,B),R=  (max(A,B));
			int x = (u + key * k2) % mod,y = ((v + key * k3) % mod) + 1;
			int cnt = 0;
			For(i,1,n) {
				if(z[i] >= L && z[i] <= R && p[i] * y <= q[i] * x){
					cnt ++;
				} 
			}cout << cnt << endl;
			lst = cnt;
		}
	}
}

10.10

目标:50 + 50+ 20 + 0

实际 : 90 + 55 + 20 + 0

实际分数比目标分数高的原因是因为这样的模拟赛数据很水。

T1 实际的策略应该找到第一个不是 A 然后再找后面所有的 T 然后去翻转然后贪心的得到字典序最大值。事实上,我是直接 n 方 暴力的做,然后加了一些剪肢,并且注意到样例比较水,所以受到启发,认为可能够卡过,事实上到最后有 2 个点没有卡过。获得较大收益。

正解是利用 二分+ 哈希,快速的得出区间反转后的一个字典序最大值。

T2 注意到是绝对众数问题,找到了很多关键性质,我思考到了如何快速的再 nlog⁡2nn \log ^ 2 n 的时间复杂度内过掉链的情况,然后思维受限,思考着怎么吧树上的连通块转成链,但事实上可能树链剖分可以做?会很复杂。所以我只打了暴力 + 链。

正解是 树形 Dp,利用绝对众数不多的性质,发现枚举这个众数的时间复杂度均摊下是对的然后就做完了。

T3 首先是打了暴力,然后拼了很久的 k = 1,一直在模拟样例,和手动找规律,随后一直没有想到怎么做。

正解 k=1 部分 就是通过锁定一些必要的位置,其他的位置贪心选,可以证明是对的。

T4 没有写暴力,其实应该写暴力,这次的暴力20pts 的分可以拿 40 pts,因为数据水。但事实上这样的事情不会出现在 ccf 上。但是还是应该拼一下暴力分。

总结:

没有打满暴力,即使暴力分较少,也需要拼一下。

T1

C++
    // #define double long double
	#define int long long
	const int mod = 998244353,inf = 0x3f3f3f3f,N = 5e5+5,M = 1e6+5,K = 3000+5;// 1000000007
	const long long linf = 0x3f3f3f3f3f3f3f3fLL;
}using namespace Data;
char rev(char c){
	if(c=='A') return 'T';
	if(c=='T') return 'A';
	if(c=='G') return 'C';
	if(c=='C') return 'G';
}
void solve(){
	string s;
	cin >> s;
	int x=0;
	For(i,0,sz(s) - 1) {
		if(s[i] != 'A') {
			x=i;break;
		}
	}vector<string > ans;
	For(i,x,sz(s) - 1){
		string t;
		if(s[i] == 'T'){
			For(j,0,x - 1) t += s[j];
			For_(j,i,x) t += rev(s[j]);
			For(j,i+1,sz(s) - 1) t += s[j];
			ans.pb(t);
		}
	}

	string ANS = s;
	for(auto it:ans) if(it < ANS) ANS = it;
	cout << ANS;
}signed main(){
	freopen("gene.in","r",stdin),freopen("gene.out","w",stdout);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int T=1,Case=0;
	// read(Case);
	// read(T);
	// cin >> T;
	For(_,1,T) {
        // cout<<"--------test"<<_<<":\n";
        solve();
    }return 0;
}	

T2

C++
nt n,c[N];
vector<int>mp[N];    
int vis[N];
int fa[N];
int find(int x){
    return (fa[x] == x) ? (x) : (fa[x] = find(fa[x]));
}int cnt[N];
    int ans= 0 ;
void soln20(){
    For(i,0,(1ll << n) - 1){
        For(j,1,n) vis[j] = 0;
        For(j,1,n) if((i >> ( j - 1) ) & 1) vis[j] = 1;
        For(j,1,n) if(vis[j]) fa[j] = j;
        For(j,1,n) {
            if(vis[j]){
                for(auto it: mp[j]) if(vis[it]) {
                    fa[find(it)] = find(j);
                }
            }
        }
        int nw = 0;
        int flag = 1;
        For(j,1,n) {
            if(vis[j]) {
                if(!nw) nw = find(j);
                else if(nw != find(j)) {
                    flag = 0;break;
                }
            }
        }
        if(!flag) continue;
        int tot = 0;
        For(j,1,n) cnt[j] = 0;
        For(j,1,n) if(vis[j]) cnt[c[j]] ++,tot ++;
        For(j,1,n) if(vis[j] && cnt[c[j]] * 2> tot){
            ans ++;break;           
        }
    }cout <<ans<<endl;
}
namespace lian{
    int cnt[N];
    int tmp[N];
    void sol(int l,int r){
        if(l == r) {
            ans ++ ;
            return ;
        }
        int mid = (l + r) >> 1;

        set<int> st;
        For(i,mid+1,r) tmp[c[i]] = 0;
        For(i,mid + 1,r) {
            tmp[c[i]] ++;
            if(tmp[c[i]] * 2 > i - mid) {
                st.insert(c[i]);
            }
        }For(i,l,mid) tmp[c[i]] = 0;
        For_(i,mid,l){
            tmp[c[i]] ++;
            if(tmp[c[i]] * 2> mid - i + 1) {
                st.insert(c[i]);
            }
        }

        for(auto it:st){
            For(i,l-1,r) cnt[i] = 0;
            For(i,l,r) if(c[i] == it) cnt[i] ++;
            For(i,l+1,r) cnt[i] += cnt[i-1];
            int base = r - mid + 2;
            For(i,0,base * 2) tmp[i] = 0;
            For(i,mid+1,r){
                tmp[base + i - mid - 2 * (cnt[i] - cnt[mid])] ++;
            }For(i,1,base * 2) tmp[i] += tmp[i - 1];
            For(i,l,mid) {
                ans += tmp[2 * (cnt[mid] - cnt[i - 1]) - (mid - i + 1)  - 1+ base];
            }
        }

        sol(l, mid);
        sol(mid + 1,r);
        return ;
    }
}
void sollian(){
    lian::sol(1,n);
    cout << ans<<endl;
}
void solve(){
	cin>>n;
    For(i,1,n) cin >> c[i];
    For(i,1,n - 1){
        int u,v;cin >> u >> v;
        mp[u].pb(v),mp[v].pb(u);
    }
    
    if(n <= 20) soln20();
    else  sollian();
}

T3

C++
int n,m,k;
int b[N];
int c[N];
bool check(vi a){
	For(i,1,n) c[i] = a[i - 1];
	For(i,1,n-m+1){
		sort(c+i,c+i+m);
	}For(i,1,n) if(c[i] != b[i]) return false;
	return true;
}namespace K1{
	int ans[N];
	int vis[N];
	void sol(){
		For(i,1,n) if(b[i] < b[i - 1] && i + m - 1<= n) ans[i + m - 1] = b[i],vis[i] =1;
		set<int> st;
		For(i,n-m+1,n) {
			if(!vis[i]) {
				st.insert(b[i]);
			}
		} ans[n] = *st.rbegin();st.erase(*st.rbegin());
		For_(i,n-m,2) {
			if(!vis[i]) {
				st.insert(b[i]);
			}if(!vis[i + m - 1]) {
				vis[i + m - 1] = 1;
				ans[i + m - 1] = *st.rbegin();
				st.erase(*st.rbegin());
			}
		}if(!vis[1]) st.insert(b[1]),vis[1] = 1;
		For(i,1,m) if(!vis[i]) ans[i] = *st.begin(),st.erase(*st.begin());
		For(i,1,n) cout << ans[i] << " ";cout << endl;
	}
}
void solve(){
	cin >> n >> m >> k;
	For(i,1,n) cin >> b[i];
	// if(k == 1) {
	// 	K1::sol();
	// 	return ;
	// }
	vector<int> a(n);
	For(i,1,n) a[i - 1]= i;
	int cnt = 0;
	do{	
		if(check(a)){
			cnt ++ ;
			if(cnt == k ){
				for(auto it:a) cout << it << " ";
			}
		}
		// cout << "work"<<endl;
	}while(next_permutation(all(a)));
}signed main(){
	freopen("sort.in","r",stdin),freopen("sort.out","w",stdout);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int T=1,Case=0;
	// read(Case);
	// read(T);
	// cin >> T;
	For(_,1,T) {
        // cout<<"--------test"<<_<<":\n";
        solve();
    }return 0;
}

10.14

目标 100 + 100+0+0

实际 100+80+0+0

T1 显然是一个结论题目,简单构造之后发现只需要二维数点就可以解决

T2 我想到了一个做法,通过对区间收缩然后做并查集,但实际上漏掉了一种考虑方式所以没有过。

事实上正解的做法可以使用异或哈希,来对每一个数随即一个哈希值,就可以巧妙的构造出所有合法的情况,然后对于所有的极小区间直接暴力算即可,他的时间复杂度是均摊的。

T3 考察了一个插入法的 Dp 设计。

考虑插入 DP,每一次考虑 aia_i 插入的时候能够放在前 i−1i-1 个数之间的哪个位置。

对于 opi∈{0,1}op_i \in \{0,1\}:确定了这个数是前面的所有数的最大值或最小值。

对于 opi∈{2,3}op_i \in \{2,3\}:限制了后面的数都要大于或小于这个数。

在 Dp 过程中记录能够填入的空位。

fi,jf_{i,j} 表示填到 aia_i,然后可以填数的位置有 j+1j+1 个。

对于 opi∈{0,1}op_i \in \{0,1\}:不会对后面限制,但是由于多了一个数,所以空位会多:fi−1,j−1→fi,jf_{i-1,j-1} \to f_{i,j}。

对于 opi∈{2,3}op_i \in \{2,3\}:会对后面有限制,所以空余位置减掉若干。所以 ∑j≤k≤nfi−1,k→fi,j\sum\limits_{j \le k\le n}f_{i-1,k} \to f_{i,j}。

转移可以后缀和,O(n2)O(n^2)。

赛时基本有大致的想法,没有最后想出来,需要提高计数的能力

T1

“cpp

int n; int a[N],b[N]; int tr[N]; void modify(int x){ for(;x<=n+1;x+=(x&(-x))) tr[x]++; return ; }int query(int x){ int res=0; for(;x;x-=(x&(-x))) res+=tr[x]; return res; }vector<int> vec[N]; void solve(){ cin >> n; For(i,0,n+2) a[i] = b[i] =tr[i]= 0,vec[i].clear(); vector<pii>rd; For(i,1,n) { int x,y;cin >> x >> y; rd.pb({x,y}); a[x] ++,b[y] ++; vec[x].pb(y); }For(i,1,n) a[i] += a[i-1],b[i] += b[i-1]; For(i,1,n) if(a[i] == n / 2 || b[i] == n / 2) { cout << 2 << endl; return ; }For_(i,n,1) { for(auto it:vec[i]) modify(it); int l = 1,r = n + 1; while(l + 3 <= r ){ int mid = (l + r) >> 1; if(query(mid) > n / 2) r= mid; else l = mid; }For(j,l,r) if(query(j) == n / 2) { cout << 3 << endl; return ; } }For(i,0,n+2) tr[i]=0; For(i,1,n) { for(auto it:vec[i]) modify(n-it+1); int l = 1,r = n + 1; while(l + 3 <= r ){ int mid = (l + r) >> 1; if(query(mid) > n / 2) r = mid; else l = mid; } // cout << l << ’ ’ << r << endl; For(j,l,r) if(query(j) == n / 2) { cout << 3 << endl; return ; } }

代码
cout << 4 << endl;

// cout << n << endl;
// for(auto it:rd) cout << it.fs << " " << it.sc<<endl;
// exit(0);

}signed main(){ // freopen(“line.in”,“r”,stdin),freopen(“line.out”,“w”,stdout); ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int T=1,Case=0; // read(Case); // read(T); cin >> T; For(,1,T) { // cout<<“--------test”<<<<”:\n”; solve(); }return 0; }

“

B

C++

nt n,c[N],v[N],f[N];
int lst[N],st[N],top;
int L[N],R[N];
int r[N];
int p[N];
void solve(){
	cin >> n;
	For(i,1,n) cin >> c[i];
	For(i,1,n) cin >> v[i];
	For(i,1,n) cin >> f[i];
	mem(L,0x3f);
	For(i,1,n) gmin(L[c[i]],i),gmax(R[c[i]],i);
	int cnt = 0;
	lst[0]=n+1;
	For_(i,n,1) {
		st[++top] = i;
		cnt += R[c[i]] == i;
		cnt -= L[c[i]] == i;
		while(top && L[c[st[top]]] >= i) --top;
		if(lst[cnt] && (!top || (st[top] >= lst[cnt]))) {
			r[i] = lst[cnt] - 1;
		}lst[cnt] = i;
	}For(i,1,n) if(r[i])p[r[i]] = i;
	For(i,1,n) gmax(p[i],p[i-1]);
	int ans = linf;
	For(i,1,n) {
		if(p[r[i]]==i){
			int res = 0 ;
			For(j,i,r[i]) {
				res += v[j] * f[j - i + 1];
			}gmin(ans,res);
		}
	}cout << ans << endl;
}signed main(){
	// freopen("std.in","r",stdin),freopen("std.out","w",stdout);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int T=1,Case=0;
	// read(Case);
	// read(T);
	// cin >> T;
	For(_,1,T) {
        // cout<<"--------test"<<_<<":\n";
        solve();
    }return 0;
}

c

CP
int n,a[N];
int dp[N][N];
int g[N][N];
void solve(){
	cin >> n;
	For(i,1,n) cin >> a[i];
	int flag = 0;
	For(i,1,n)For(j,i + 1,n){
		if((a[i] == 3 && a[j] == 1 )|| (a[i]== 2 && a[j] == 0)) flag = true; 
	}if(flag ) {cout << "0" << endl;return ;}
	dp[0][0] = 1;	
	For(i,1,n) {
		if(a[i] == 0 || a[i] ==1){
			For(j,1,n)dp[i][j] = md(dp[i][j] + dp[i-1][j-1]);
		}else{
			For_(j,n,0) dp[i][j] = md(dp[i-1][j] + dp[i][j + 1] + dp[i][j]);
		}
	}
	int ans = 0;
	For(i,0,n) ans = md(ans + dp[n][i]);
	cout << ans << endl;
}signed main(){
	// freopen("std.in","r",stdin),freopen("std.out","w",stdout);
    // ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int T=1;
	// read(T);
	For(_,1,T) {
        // cout<<"--------test"<<_<<":\n";
        solve();
    }return 0;
}


10.17

预期:100+0+0+0

实际:;65+0+0+0

T1 测试挂了我不知道原因,大概是数据有误,原题我可以通过;所以 65 不管了。T1 是简单构造题,我一开始思考了很久考虑去Dp求若干个等差数列的和,考虑建图,等操作。最后发现其实贪心能选就选,而且这样时间复杂度甚至均摊也是对的。

T2 比较精妙的 构造题,需要构造出若干菱形,然后相邻不同颜色即可。但是赛时没有时间写了。

T3 对于基本的情况都不太会做,那么对于所有答案的前缀,就更难想了,正确的做法是,可以通过将题目的限制转化为图形,然后问题的前缀就是在图上的图形的交集,然后就好做了,维护那些矩形即可,

T4 是一个比较套路的树形 Dp,赛时想了 2h左右,最后还是没有完全做出来。正确的做法是普通的类似树形背包的换根 DP,分讨多种情况,记录 fi,jf_i,j 表示i子树内深度 j 的线头状态即可,再记录一个 g,互相转移,由于不能直接除法,所以需要做一遍前后缀 dp,然后分讨,码量较大。但是套路经典,应该补充换根dp经典模型的熟练度掌握。

C++
espace Data;
int n;
int d[N];
int vis[N][N];
void solve(){
    cin >> n;
    int res = 0;
    For(i,1,240){
        For(j,1,i - 1){
            int cnt = 0;
            For(k, 1,i - 1) {
                if(vis[i][k] && vis[j][k]) cnt ++ ;
            }if(res + cnt <= n) {
                res += cnt;
                vis[j][i] = vis[i][j] = 1;
            }
        }
    }
    cout << 240 << endl;
    For(i,1,240) {
        For(j,i + 1,240){
            cout << vis[i][j] << ' ';
        }cout << endl;
    }
}signed main(){
	freopen("game.in","r",stdin),freopen("game.out","w",stdout);
    ios::sync_with_stdio(false), c

d

C++
using namespace Head;
namespace Data{
    // #define double long double
	#define int long long
	const int mod = 1000000007,inf = 0x3f3f3f3f,N = 1e5+5,M = 1e6+5,K = 3000+5;// 1000000007
	const long long linf = 0x3f3f3f3f3f3f3f3fLL;
}using namespace Data;
int n;
vector<int> mp[N];
int f[N][25],g[N][25],ans[N];
void dfs(int x,int fa){
	vi son;
	for(auto it: mp[x]) if(it!=fa) {
		dfs(it,x);
		son.pb(it);
	}
	int siz = sz(son);

	f[x][0] = 1;
	for(auto it : son) f[x][0] = (f[x][0] * ans[it]) % mod;

	// f[u][j] 
	For(j,1,20) {
		vector<int> f1(siz + 1,0),f2(siz + 1,0);
		int pi = 1;
		For(i,0,siz - 1) {
			f1[i] = f[son[i]][j - 1] * pi % mod;
			pi = (pi * ans[son[i]]) % mod;
		}pi = 1;
		For_(i,siz - 1,0) {
			f2[i] = f[son[i]][j - 1] * pi % mod;
			f2[i] = (f2[i] + f2[i + 1] * ans[son[i]] % mod) % mod;
 			pi = pi * ans[son[i]] % mod;
		}
		For(i,0,siz - 2) {
			f[x][j] = (f[x][j] + f1[i] * f2[i + 1] % mod) % mod;
		}
	}

	// g[u][j] f < g
	
	For(j,0,20) {
		vector<int> f1(siz + 1,0),f2(siz + 1,0);
		int pi = 1;
		For(i,0,siz - 1) {
			f1[i] = f[son[i]][j] * pi % mod;
			pi = (pi * ans[son[i]]) % mod;
		}pi = 1;
		For_(i,siz - 1,0) {
			f2[i] = g[son[i]][j + 1] * pi % mod;
			f2[i] = (f2[i] + f2[i + 1] * ans[son[i]] % mod) % mod;
 			pi = pi * ans[son[i]] % mod;
		}
		For(i,0,siz - 2) {
			g[x][j] = (g[x][j] + f1[i] * f2[i + 1] % mod) % mod;
		}
	}

	// g[u][j] f > g

	For(j,0,20) {
		vector<int> f1(siz + 1,0),f2(siz + 1,0);
		int pi = 1;
		For(i,0,siz - 1) {
			f1[i] = g[son[i]][j + 1] * pi % mod;
			pi = (pi * ans[son[i]]) % mod;
		}pi = 1;
		For_(i,siz - 1,0) {
			f2[i] = f[son[i]][j] * pi % mod;
			f2[i] = (f2[i] + f2[i + 1] * ans[son[i]] % mod) % mod;
 			pi = pi * ans[son[i]] % mod;
		}
		For(i,0,siz - 2) {
			g[x][j] = (g[x][j] + f1[i] * f2[i + 1] % mod) % mod;
		}
	}

	// ans u f

	For(j,0,20) {
		ans[x] = (ans[x] + f[x][j]) % mod;	
	}

	// g f 

	For(j,0,20) {
		vector<int> f1(siz + 1,0),f2(siz + 1,0);
		int pi = 1;
		For(i,0,siz - 1) {
			pi = (pi * ans[son[i]]) % mod;
			f1[i] = pi;
		}pi = 1;
		For_(i,siz - 1,0) {
 			pi = pi * ans[son[i]] % mod;
			f2[i] = pi;
		}
		For(i,0,siz - 1) {
			int res = 1;
			if(i) res = f1[i - 1];
			if(i < siz - 1) res = res * f2[i + 1] % mod;
			g[x][j] = (g[x][j] + f[son[i]][j] * res % mod ) % mod;
		}
	}

	// ans f g f

	For(j,1,20) {
		vector<int> f1(siz + 1,0),f2(siz + 1,0);
		int pi = 1;
		For(i,0,siz - 1) {
			f1[i] = pi * f[son[i]][j - 1] % mod;
			if(i) f1[i] = (f1[i] + f1[i - 1] * ans[son[i]] % mod) % mod;
			pi = (pi * ans[son[i]]) % mod;
		}pi = 1;
		For_(i,siz - 1,0) {
			f2[i] = pi * f[son[i]][j - 1] % mod;
			f2[i] = (f2[i] + f2[i + 1] * ans[son[i]] % mod) % mod;
 			pi = pi * ans[son[i]] % mod;
		}
		For(i,1,siz - 2) {
			int res = 1;
			res = (res * f1[i - 1]) % mod;
			res = (res * f2[i + 1]) % mod;
			ans[x] = (ans[x] + res * g[son[i]][j] % mod) % mod;
		}
	}

	// ans f f g

	For(j,1,20) {
		vector<int> f1(siz + 1,0),f2(siz + 1,0);
		int pi = 1;
		For(i,0,siz - 1) {
			f1[i] = pi * f[son[i]][j - 1] % mod;
			if(i) f1[i] = (f1[i] + f1[i - 1] * ans[son[i]] % mod) % mod;
			pi = (pi * ans[son[i]]) % mod;
		}pi = 1;
		For_(i,siz - 1,0) {
			f2[i] = pi * g[son[i]][j] % mod;
			f2[i] = (f2[i] + f2[i + 1] * ans[son[i]] % mod) % mod;
 			pi = pi * ans[son[i]] % mod;
		}
		For(i,1,siz - 2) {
			int res = 1;
			res = (res * f1[i - 1]) % mod;
			res = (res * f2[i + 1]) % mod;
			ans[x] = (ans[x] + res * f[son[i]][j - 1] % mod) % mod;
		}
	}

	// ans g f f

	For(j,1,20) {
		vector<int> f1(siz + 1,0),f2(siz + 1,0);
		int pi = 1;
		For(i,0,siz - 1) {
			f1[i] = pi * g[son[i]][j] % mod;
			if(i) f1[i] = (f1[i] + f1[i - 1] * ans[son[i]] % mod) % mod;
			pi = (pi * ans[son[i]]) % mod;
		}pi = 1;
		For_(i,siz - 1,0) {
			f2[i] = pi * f[son[i]][j - 1] % mod;
			f2[i] = (f2[i] + f2[i + 1] * ans[son[i]] % mod) % mod;
 			pi = pi * ans[son[i]] % mod;
		}
		For(i,1,siz - 2) {
			int res = 1;
			res = (res * f1[i - 1]) % mod;
			res = (res * f2[i + 1]) % mod;
			ans[x] = (ans[x] + res * f[son[i]][j - 1] % mod) % mod;
		}
	}

	// ans  g

	vector<int> f1(siz + 1,0),f2(siz + 1,0);
	For(i,0,siz - 1) f1[i] =( (i) ? (f1[i - 1]) : (1ll) ) * ans[son[i]] % mod;
	For_(i,siz - 1,0) f2[i] = ((i < siz - 1) ? (f2[i + 1]) : (1ll)) * ans[son[i]] % mod;
	For(i,0,siz - 1) {
		int res = 1;
		if(i) res = res * f1[i - 1] % mod;
		if(i < siz - 1) res = res * f2[i + 1] % mod;
		ans[x] = (ans[x] + res * g[son[i]][0] % mod) % mod;
 	}

}
void solve(){
	cin >> n;
	For(i,1,n) mp[i].clear();
	For(i,0,n+1){
		ans[i] = 0;
		For(j,0,22) f[i][j] = g[i][j] = 0;
	}For(i,1,n - 1){
		int u,v;
		cin >> u >> v;
		mp[u].pb(v),mp[v].pb(u);
	}dfs(1,0);
	cout << ans[1] << endl;
}signed main(){
	// freopen("std.in","r",stdin),freopen("std.out","w",stdout);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int T=1,Case=0;
	// read(Case);
	// read(T);
	cin >> T;
	For(_,1,T) {
        // cout<<"--------test"<<_<<":\n";
        solve();
    }return 0;
}
原文