暑假集训csp提高模拟8

赛时rank 19,T1 100,T2 20,T3 10,T4 0

T2
\(\Huge{并查集没有路径压缩挂了80pts}\)

\(rank\,2\)挂成19,随机零食没了。

题目名称看着就离谱

T1 基础的生成函数练习题(gf)

[ABC093C] Same Integers

签到题。

考虑有几个奇偶性相同的。

若最多的有三个,输出(2*c-b-a)/2;

反之,若奇数多,将所有的奇数加一后,输出(2*c-b-a)+1;

反之,若偶数多,将所有的偶数加一后,输出(2*c-b-a)+1;

点此查看代码
#include<bits/stdc++.h>
#include<bits/extc++.h>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
using namespace std;
#define infile(x) freopen(x,"r",stdin)
#define outfile(x) freopen(x,"w",stdout)
#define errfile(x) freopen(x,"w",stderr)
using ll=long long;using ull=unsigned long long;using db = double;
#ifdef LOCAL
    FILE *InFile = infile("in.in"),*OutFile = outfile("out.out");
    // FILE *ErrFile=errfile("err.err");
#else
    FILE *Infile = stdin,*OutFile = stdout;
    //FILE *ErrFile = stderr;
#endif
ll a[4];
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cout.tie(nullptr)->sync_with_stdio(false);
    cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+1+3);
	int tot1 = 0,tot2 = 0;
	for(int i = 1;i <= 3; ++i){
		tot1 += (a[i] & 1);
		tot2 += !(a[i] & 1);
	}
	if(tot1 == 3 || tot2 == 3){
		cout<<(a[3]-a[2])/2+(a[3]-a[1])/2;
	}
	else{
		int ans = 0;
		if(tot1 == 2){
			for(int i = 1;i <= 3; ++i){
				if(a[i]&1) a[i]++;
			}
			ans++;
		}
		else{
			for(int i = 1;i <= 3; ++i){
				if(!(a[i]&1)) a[i]++;
			}
			ans++;
		}
		cout<<(a[3]-a[2])/2+(a[3]-a[1])/2+1<<'\n';
	}
}

T2 简单的拉格朗日反演练习题(lagrange)

Qpwoeirut and Vertices

简单题。

考虑求出最小生成树,求出最小生成树上\(i\sim i+1\)的路径最大值,用ST表维护最大值即可。

并查集一定要路径压缩啊!!

点此查看代码
#include<bits/stdc++.h>
#include<bits/extc++.h>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
using namespace std;
#define infile(x) freopen(x,"r",stdin)
#define outfile(x) freopen(x,"w",stdout)
#define errfile(x) freopen(x,"w",stderr)
using ll=long long;using ull=unsigned long long;using db = double;
#ifdef LOCAL
    FILE *InFile = infile("in.in"),*OutFile = outfile("out.out");
    FILE *ErrFile=errfile("err.err");
#else
    FILE *Infile = stdin,*OutFile = stdout;
    //FILE *ErrFile = stderr;
#endif
const int N = 2e5 + 10;
int fa[N],u[N],v[N],n,m,q,tim[N],siz[N];
vector<pair<int,int> > edge[N];
#define pii pair<int,int>
#define mk make_pair
int get_fa(int x){return (x==fa[x]?x:fa[x]=get_fa(fa[x]));}
inline void merge(int x,int y,int i){
    int fx = get_fa(x),fy = get_fa(y);
    if(fx == fy) return;
    if(siz[fx] > siz[fy]) swap(x,y),swap(fx,fy);
    fa[fx] = fy;
    siz[fy] += siz[fx];
    edge[fy].push_back(mk(fx,i));
    edge[fx].push_back(mk(fy,i));
}
int a[N],ans[N],st[18][N];
inline void pre(){
    int t = log2(n)+1;
    // memset(st,0,sizeof st);
    for(int i = 1;i <= n; ++i) st[0][i] = a[i];
    for(int j = 1;j <= t; ++j){
        for(int i = 1;i + (1<<j) - 1 <= n; ++i){
            st[j][i] = max(st[j-1][i],st[j-1][i+(1<<(j-1))]);
        }
    }
}
inline void pre1(){
    int t = log2(n)+1;
    // memset(st,0,sizeof st);
    for(int i = 1;i <= n; ++i) st[0][i] = ans[i];
    for(int j = 1;j <= t; ++j){
        for(int i = 1;i + (1<<j) - 1 <= n; ++i){
            st[j][i] = max(st[j-1][i],st[j-1][i+(1<<(j-1))]);
        }
    }
}
inline int query(int l,int r){
    if(l > r) return 0;
    int k = log2(r-l+1);
    return max(st[k][l],st[k][r-(1<<k)+1]);
}
namespace TCS{
    int dfn[N],siz[N],fa[N],son[N],top[N],tot,ori[N],dep[N];
    void dfs1(int x){
        siz[x] = 1;
        dep[x] = dep[fa[x]] + 1;
        for(auto i : edge[x]){
            int y = i.first;
            if(y == fa[x]) continue;
            fa[y] = x;
            dfs1(y);
            siz[x] += siz[y];ori[y] = i.second;
            if(siz[son[x]] < siz[y]) son[x] = y;
        }
    }
    void dfs2(int x,int t){
        dfn[x] = ++tot;
        a[tot] = ori[x];
        top[x] = t;
        if(son[x]) dfs2(son[x],t);
        else return;
        for(auto i:edge[x]){
            int y = i.first;
            if(y == fa[x] || y == son[x]) continue;
            dfs2(y,y);
        }
    }
    inline int Query(int x,int y){
        int fx = top[x],fy = top[y],ans = 0;
        while(fx != fy){
            if(dep[fx] < dep[fy]) swap(x,y),swap(fx,fy);
            ans = max(ans,query(dfn[fx],dfn[x]));
            x = fa[fx];
            fx = top[x];
        }
        if(dep[x] > dep[y]) swap(x,y);
        ans = max(ans,query(dfn[x]+1,dfn[y]));
        return ans;
    }
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cout.tie(nullptr)->sync_with_stdio(false);
    cin>>n>>m>>q;
    for(int i = 1;i <= n; ++i) fa[i] = i;
    for(int i = 1,u,v;i <= m; ++i){
        cin>>u>>v;
        merge(u,v,i);
    }
    int s = get_fa(1);
    TCS::dfs1(s);TCS::dfs2(s,s);
    pre();
    for(int i = 1;i < n; ++i) ans[i] = TCS::Query(i,i+1);
    pre1();
    int l,r;
    for(int i = 1;i <= q; ++i){
        cin>>l>>r;
        if(l == r){cout<<0<<'\n';continue;}
        cout<<query(l,r-1)<<'\n';
    }
}

T3 容易的多元拉格朗日反演练习题(multi)

[AGC056D] Subset Sum Game

大难题,谁家出题人往csp模拟赛里放AGC的D题啊

不会啊,防AK题,跳了

T4 朴素的抽象代数题(algebra)

难题,找循环节,懒得打了。

总结:唐。

posted @ 2024-07-26 17:23  CuFeO4  阅读(36)  评论(4编辑  收藏  举报