首页 > 其他分享 >暑假集训CSP提高模拟25

暑假集训CSP提高模拟25

时间:2024-08-20 19:26:57浏览次数:8  
标签:25 int long 集训 FILE using define CSP mod

赛时rank 5,T1 100,T2 85,T3 50,T4 5

T2 Tarjan意外挂了,在Tarjan里判割边会挂?

T3 \(O(nm^2)\)暴力能拿50?特判样例能拿60?

可持久化线段树

没啥好说的,主席树板子。

点此查看代码
#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)
#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
using ll=long long;using ull=unsigned long long;
using db = double;using ldb = long double;
const int N = 1e5 + 10,mod = 998244353;
int a[N],n,m;
class ChairMan_Tree{
private:
    struct segment_tree{
        int ls,rs;
        ll val,lazy;
#define ls(k) tree[k].ls
#define rs(k) tree[k].rs
#define val(k) tree[k].val
#define lazy(k) tree[k].lazy
    }tree[N*50];
    int cnt;
    inline void pushup(int k){val(k) = (val(ls(k)) + val(rs(k)))%mod;}
public:
    int rt[N];
    void build(int &k,int l,int r){
        k = ++cnt;
        if(l == r) return val(k) = a[l],void();
        int mid = (l + r) >> 1;
        build(ls(k),l,mid);build(rs(k),mid+1,r);
        pushup(k);
    }
    void update(int pre,int &now,int l,int r,int L,int R,int val){
        now = ++cnt;
        tree[now] = tree[pre];
        val(now) = (val(now) + 1ll*(min(r,R) - max(L,l)+1)*val%mod)%mod;
        if(L <= l && r <= R) 
            return lazy(now) = (lazy(now) + val)%mod,void();
        int mid = (l + r) >> 1;
        if(L <= mid) update(ls(pre),ls(now),l,mid,L,R,val);
        if(R > mid) update(rs(pre),rs(now),mid+1,r,L,R,val);
    }
    int query(int k,int l,int r,int L,int R){
        if(!k) return 0;
        if(L <= l && r <= R) return val(k);
        int mid = (l + r) >> 1,res = 1ll * (min(R,r) - max(L,l) + 1) * lazy(k) % mod;
        if(L <= mid) res = (res + query(ls(k),l,mid,L,R))%mod;
        if(R > mid) res = (res + query(rs(k),mid+1,r,L,R))%mod;
        return res;
    }
}T;
inline void solve(){
    cin>>n>>m;
    for(int i = 1;i <= n; ++i) cin>>a[i];
    T.build(T.rt[0],1,n);
    int op,l,r,x,tot = 0;
    while(m--){
        cin>>op;
        if(op == 1){
            cin>>l>>r>>x;
            tot++;
            T.rt[tot] = 0;
            T.update(T.rt[tot-1],T.rt[tot],1,n,l,r,x);
        }
        if(op == 2){
            cin>>l>>r;
            cout<<T.query(T.rt[tot],1,n,l,r)<<'\n';
        }
        if(op == 3){
            cin>>x;
            tot -= x;
        }
    }
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cout.tie(nullptr)->sync_with_stdio(false);
    solve();    
}

但是可以直接用线段树暴力撤销,区间加减求和即可。

Little Busters !

考虑先将所有为\(Lun\)的边建图,然后Tarjan缩点,将缩完点后的树边删去。

然后再考虑将\(Qie\)的边加入,用并查集维护联通性,如果一个\(Qie\)边所连得两点已经联通,那么就删去,反之就加上。

最后再判图是否联通即可

点此查看代码
#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)
#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
using ll=long long;using ull=unsigned long long;
using db = double;using ldb = long double;
const int N = 1e5 + 10;
struct EDGE{int to,next;}edge[N<<2];
int head[N],cnt = 1;
inline void add(int u,int v){
    edge[++cnt] = {v,head[u]};
    head[u] = cnt;
}
int dfn[N],low[N],tot,g[N],num;
int sta[N],top;
vector<int> dcc[N];
bitset<N> vis;
int u[N<<1],v[N<<1],n,m;
bitset<N<<1> del;
string w[N<<1];
void Tarjan(int x,int f){
    sta[++top] = x;
    dfn[x] = low[x] = ++num;
    vis[x] = true;
    for(int i = head[x]; i;i = edge[i].next){
        int y = edge[i].to;
        if(!dfn[y]){
            Tarjan(y,i);
            low[x] = min(low[x],low[y]);
        }
        else if(i != (f^1)) low[x] = min(low[x],dfn[y]);
    }
    if(dfn[x] == low[x]){
        g[x] = ++tot;
        vis[x] = false;
        dcc[tot].emplace_back(x);
        while(sta[top] != x){
            vis[sta[top]] = false;
            g[sta[top]] = tot;
            dcc[tot].emplace_back(sta[top]);
            top--;
        }
        top--;
    }
}
int fa[N];
int get_fa(int x){return x == fa[x]?x:fa[x] = get_fa(fa[x]);}
inline void solve(){
    cin>>n>>m;
    for(int i = 1;i <= n; ++i) fa[i] = i;
    vector<int> q;
    for(int i = 1;i <= m; ++i){
        cin>>u[i]>>v[i]>>w[i];
        if(w[i][0] == 'L') add(u[i],v[i]),add(v[i],u[i]);
        else q.push_back(i);
    }
    for(int i = 1;i <= n; ++i){if(!dfn[i]) Tarjan(i,0);}
    for(int now = 1;now <= tot; ++now){
        for(int i = 1;i < dcc[now].size(); ++i)
            fa[dcc[now][i]] = dcc[now][0];
    }
    for(int i = 1;i <= m; ++i){
        if(w[i][0] != 'L') continue;
        int fu = get_fa(u[i]),fv = get_fa(v[i]);
        if(fu != fv) del[i] = true;
    }
    for(auto i : q){
        int fu = get_fa(u[i]),fv = get_fa(v[i]);
        if(fu == fv){
            del[i] = true;
            continue;
        }
        fa[fu] = fv;
    }
    int tot = 0;
    for(int i = 1;i <= n; ++i) if(fa[i] == i) tot++;
    if(tot > 1) return cout<<"NO\n",void();
    vector<int> ans;
    for(int i = 1;i <= m; ++i) if(!del[i]) ans.push_back(i);
    cout<<"YES\n";
    cout<<ans.size()<<'\n';
    for(auto i : ans) cout<<u[i]<<' '<<v[i]<<'\n';
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cout.tie(nullptr)->sync_with_stdio(false);
    solve();
}

魔卡少女樱

[ABC276G] Count Sequences

发现只利用\(a_i \not\equiv a_{i+1}\pmod 3\)的性质难以处理,那么考虑将其差分

设其差分数组为\(b\),那么有\(b_1=1,b_i=a_i-a_{i-1}\),易知\(\forall i\in [2,n],b_i\not\equiv 0\pmod 3\)

可以先对\(b_i\)对\(3\)取模,所以\(\forall i\in[2,n],b_i\in\{1,2\}, b_1\in\{1,2,3\}\)

由于\(b_i\in\{1,2\}\),可以先钦定有\(j\)个\(b_i=2\),方案数先乘一个\(C_{n-1}^j\),然后枚举\(b_{1\sim n}\)有\(cnt\)个3,就是\(cnt=\left\lfloor\frac{m-j-n+1}{2}\right\rfloor\),考虑插板法。

总可能数为

\[\sum_{k=0}^{n-1}C_{n-1}^k\sum_{j=0}^{cnt}C_{n+j}^j \]

点此查看代码
#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)
#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
using ll=long long;using ull=unsigned long long;
using db = double;using ldb = long double;
const int mod = 998244353,N = 2e7 + 10;
int n,m,fac[N],inv[N],sum[N];
inline int power(int a,int b,int mod){
    int res = 1;
    for(; b;b >>= 1,a = 1ll * a * a % mod)
        if(b & 1) res = 1ll * res * a % mod;
    return res;
}
inline int C(int n,int m){
    if(m>n) return 0;
    return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
inline void solve(){
    cin>>n>>m;
    fac[0] = 1;
    for(int i = 1;i <= 20000000; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
    inv[20000000] = power(fac[20000000],mod-2,mod);
    for(int i = 20000000-1;i >= 0; --i) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
    sum[0] = 1;
    for(int i = 1;i < m; ++i) sum[i] = (sum[i-1] + C(i+n-1,n-1))%mod;
    int ans = 0;
    for(int i = 0;i < 3; ++i)
        for(int j = 0;j < n && j + n - 1 + i <= m; ++j)
            ans = (ans + 1ll * C(n-1,j)*sum[(m-j-i-n+1)/3]%mod)%mod;
    cout<<ans;
}
signed main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cout.tie(nullptr)->sync_with_stdio(false);
    solve();
}

声之形

不会了

标签:25,int,long,集训,FILE,using,define,CSP,mod
From: https://www.cnblogs.com/hzoi-Cu/p/18370117

相关文章

  • 【四旋翼】四旋翼无人机的几何跟踪控制(含弹道 位置误差 速度误差)【含Matlab源码 7256
    ✅博主简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,Matlab项目合作可私信或扫描文章底部QQ二维码。......
  • 【图像加密解密】6维超混沌系统和DNA编码的图像加密解密【含Matlab源码 7257期】
    ✅博主简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,Matlab项目合作可私信或扫描文章底部QQ二维码。......
  • 【2025毕设热门选题】《基于SpringBoot+Vue的校园资产管理系统》功能规划和开题报告
    博主介绍:8年资深码农、211小硕,全网10万+粉丝。文科生转码,所以非常懂小白学习历程。java领域优质创作者,擅长小白基础课程教学和项目讲解辅导。专注于Java技术领域和大学生毕业项目实战讲解已经5年,服务10000+小白客户。技术范围:自己手撸SpringBoot、Vue、javaweb网站、小程......
  • CSP 2023 普及组第一轮 - CSP/J 2023初试题详细解析
    基础选择题:CSP2023普及组第一轮-CSP/S2023初试题基础部分解析-CSDN博客程序阅读第一题:CSP2023普及组第一轮-CSP/S2023初试题程序阅读第一题解析-CSDN博客程序阅读第二题:CSP2023普及组第一轮-CSP/S2023初试题程序阅读第二题解析-CSDN博客程序阅读第三......
  • 暑假集训CSP提高模拟 25
    暑假集训CSP提高模拟25组题人:@KafuuChinocpp|@H_Kaguya\(T1\)P235.可持久化线段树\(0pts\)弱化版:SP11470TTM-Tothemoon标记永久化主席树板子。点击查看代码constllp=998244353;lla[100010];structPDS_SMT{ llroot[100010],rt_sum; structSegme......
  • delphi加密C#解密(AES-256)
    因为公司内部业务需要,用delphi加密的内容(流和字符串)要用C#解密,因为不懂delphi,我这里只是问同事要了代码,贴上delphi加密:共两个文件(AES.pas和ElAES.pas)AES.pas:(**************************************************************)(*......
  • leetcode面试经典150题-125. 验证回文串
    https://leetcode.cn/problems/valid-palindrome/description/?envType=study-plan-v2&envId=top-interview-150 packageleetcode150import("strings""testing")funcTestIsPalindrome(t*testing.T){s:="0P"......
  • CSP24
    学了些DP学校题库有\(BUG\)首先要满足条件\(x,y\)的二进制有1的位必然包含\(a\),然后让\(s-2a\),也就是除去二进制包含\(a\)有1的位,然后\(<0\)肯定无解,其次是如果有与\(a\)同一级的含\(1\)二进制位也不合法点击查看代码#include<bits/stdc++.h>#definespeed()ios::sync......
  • 2024.8.4~2024.8.18济南北斗学友集训
    8.9晚上原神(原题之神)争霸赛(挑选写过的6题进行比赛)rk前7名可以许一个50r以内的愿望100+100+0+100+??+(30+)=330+18:05Begin18:??T1100pts18:??T2100pts18:54T4100pts19:42T5??ptsO(kn)worst(intree)......
  • CSP 模拟 24
    T1与和\(a\operatorname{\&}b=x\\\\a+b=y\),\(x\)为\(a\)和\(b\)二进制下的公共部分,设为\(w\),\(a-w\)与\(b-w\)无公共部分,所以\(a+b-2w\)与\(w\)无公共部分,根据这个判一下就好了。std::cout<<(((y-2*x)&x)?"Yes\n":"No\n");T2函......