0815模拟赛

· · 个人记录

总结一下T1挂大分,输出不分大小写,鉴定为打CF打的

这套题思维难度不打,就不细讲了,大致讲一下思路吧

T1

0/100

无脑结论题,注意考虑v在首位和末位的情况

还有不要像我一样不看输出格式

#include<bits/stdc++.h>
#define N 100005
using namespace std;

int t,n,x,st;
string s;
bool a[N][5];//ANV

inline void file(){
    ios::sync_with_stdio(false);
    cin.tie(0);
}

int main(){
    file();
    cin>>t;
    while(t--){
        for(int i=0;i<26;++i){
            cin>>x;
            if(x&1) a[i][1]=1;//A
            else a[i][1]=0;
            if(x&2) a[i][2]=1;//N
            else a[i][2]=0;
            if(x&4) a[i][3]=1;//V
            else a[i][3]=0;
        }
        cin>>s;
        n=s.size();
        if(!a[s[n-1]-'a'][2]){
            puts("No");
            continue;
        }
        x=-1;
        bool fl=1;
        for(int i=0;i<n;++i){
            if((!a[s[i]-'a'][1])&&(!a[s[i]-'a'][2])){
                if(x!=-1){
                    puts("No");
                    fl=0;
                    break;
                }
                x=i;
            }
        }
        if(!fl) continue;
        if(x==-1){
            for(int i=0;i<n-2;++i){
                if(a[s[i]-'a'][2]&&a[s[i+1]-'a'][3]){
                    puts("Yes");
                    fl=0;
                    break;
                }
            }
        }else{
            if(x&&a[s[x-1]-'a'][2]){
                puts("Yes");
                fl=0;
            }
        }
        if(fl) puts("No");
    }
    return 0;
}

T2

100/100

主要是看到操作3的反转容易想到文艺平衡树

前面的插入和删除也很好实现

注意这里有可能在split的时候把点拆成两个,要开两倍空间

比我聪明的你应该能想到双向链表的做法吧,实现有点麻烦,就不在此赘述

#include<bits/stdc++.h>
#define N 500005
#define int long long
using namespace std;

string s;
int n,m,x,y,z,tot,u,v,rt[N];
int ch[N][2],num[N],sz[N],cnt[N],col[N],la[N];

inline void file(){
    ios::sync_with_stdio(false);
    cin.tie(0);
}

inline void pushup(int p){
    sz[p]=sz[ch[p][0]]+sz[ch[p][1]]+cnt[p];
}

inline void pushdown(int p){
    if(la[p]){
        swap(ch[p][0],ch[p][1]);
        la[ch[p][0]]^=1;
        la[ch[p][1]]^=1;
        la[p]=0;
    }
}

inline int node(int x,int y){
    tot++;
    sz[tot]=x;
    num[tot]=rand();
    cnt[tot]=x,col[tot]=y;
    la[tot]=ch[tot][0]=ch[tot][1]=0;
    return tot;
}

inline int merge(int x,int y){
    if(!x||!y) return x|y;
    if(num[x]<num[y]){
        pushdown(x);
        ch[x][1]=merge(ch[x][1],y);
        pushup(x);
        return x;
    }else{
        pushdown(y);
        ch[y][0]=merge(x,ch[y][0]);
        pushup(y);
        return y;
    }
}

inline void split(int now,int k,int &x,int &y){
    if(!now){
        x=y=0;
        return;
    }
    pushdown(now);
    if(sz[ch[now][0]]+cnt[now]<=k){
        x=now;
        split(ch[x][1],k-sz[ch[now][0]]-cnt[now],ch[x][1],y);
    }else if(sz[ch[now][0]]<k){
        x=node(k-sz[ch[now][0]],col[now]);
        y=node(cnt[now]-k+sz[ch[now][0]],col[now]);
        if(cnt[x]==0) x=ch[now][0];
        else ch[x][0]=ch[now][0];
        if(cnt[y]==0) y=ch[now][1];
        else ch[y][1]=ch[now][1];
        pushup(x),pushup(y);    
        return;
    }else{
        y=now;
        split(ch[y][0],k,x,ch[y][0]);
    }
    pushup(now);
}

inline void print(int x){
    if(!x) return;
    pushdown(x);
    print(ch[x][0]);
    cout<<cnt[x]<<" "<<col[x]<<"\n";
    print(ch[x][1]);
}

signed main(){
    file();
    srand((unsigned)time(NULL));
    cin>>n>>m;
    while(m--){
        cin>>s;
        if(s=="push"){
            cin>>x>>y>>z;
            rt[z]=merge(rt[z],node(x,y));
        }else if(s=="pop"){
            cin>>x>>y;
            split(rt[y],sz[rt[y]]-x,u,v);
            while(ch[v][0]) v=ch[v][0];
            cout<<col[v]<<"\n";
            rt[y]=u,v=0,u=0;
        }else{
            cin>>y>>x;
            la[rt[y]]^=1;
            rt[x]=merge(rt[x],rt[y]);   
            rt[y]=0;
        }
    }
    return 0;
}

T3

容易发现每个点最终对答案贡献为$(I+A^{a_i})

区间询问时把他们乘起来即可,用线段树来维护

这道题的难点就在于推第二行结论时涉及高难度的矩阵计算

考场上遇到这种直接打暴力吧

小技巧:线段树在结构体内直接重定义+运算可以减小码量

#include<bits/stdc++.h>
#define N 100005
#define mod 998244353
#define int long long
using namespace std;

int n,m,op,x,y;
struct mat{
    int n,m,a[4][4];
    mat(){}
    mat(int n,int m):n(n),m(m){} 
    mat operator+(mat b)const{
        mat x(n,m);
        for(int i=1;i<=n;++i){
            for(int j=1;j<=m;++j){
                x.a[i][j]=a[i][j]+b.a[i][j];
                x.a[i][j]%=mod;
            }
        }
        return x;
    }
    mat operator*(mat b)const{
        mat x(n,b.m);
        x.init();
        for(int i=1;i<=n;++i){
            for(int j=1;j<=b.m;++j){
                for(int k=1;k<=m;++k){
                    x.a[i][j]+=(a[i][k]*b.a[k][j])%mod;
                    x.a[i][j]%=mod;
                }
            }
        }
        return x;
    }
    void init(){memset(a,0,sizeof a);}
}s[N],I,G;
struct tree{
    int l,r;
    mat ls,rs,s,ms;
}tr[N<<2];

inline void file(){
    ios::sync_with_stdio(false);
    cin.tie(0);
}

inline void pushup(int p){
    tr[p].s=tr[p<<1].s*tr[p<<1|1].s;
    tr[p].ms=tr[p<<1].ms+tr[p<<1|1].ms+tr[p<<1].rs*tr[p<<1|1].ls;
    tr[p].ls=tr[p<<1].ls+tr[p<<1].s*tr[p<<1|1].ls;
    tr[p].rs=tr[p<<1|1].rs+tr[p<<1].rs*tr[p<<1|1].s;
}

inline void build(int p,int l,int r){
    tr[p].l=l,tr[p].r=r;
    if(l==r){
        cin>>x;
        tr[p].s=tr[p].ls=tr[p].rs=tr[p].ms=I+s[x];
        return;
    }
    int mid=l+r>>1;
    build(p<<1,l,mid);
    build(p<<1|1,mid+1,r);
    pushup(p);
}

inline void modify(int p,int x,int k){
    if(tr[p].l==tr[p].r){
        tr[p].s=tr[p].ls=tr[p].rs=tr[p].ms=I+s[k];
        return;
    }
    int mid=tr[p].l+tr[p].r>>1;
    if(x<=mid) modify(p<<1,x,k);
    else modify(p<<1|1,x,k);
    pushup(p);
}

inline tree ask(int p,int l,int r){
    if(l<=tr[p].l&&tr[p].r<=r) return tr[p];
    int mid=tr[p].l+tr[p].r>>1;
    tree a1,a2,ans;
    if(l<=mid) ans=a1=ask(p<<1,l,r);
    if(r>mid) ans=a2=ask(p<<1|1,l,r);
    if(l<=mid&&r>mid){
        ans.s=a1.s*a2.s;
        ans.ms=a1.ms+a2.ms+a1.rs*a2.ls; 
        ans.ls=a1.ls+a1.s*a2.ls;
        ans.rs=a2.rs+a1.rs*a2.s;
    }
    return ans;
}

inline void init_mt(){
    I=s[1]=mat(3,3),G=mat(3,1);
    I.init(),s[1].init(),G.init();
    s[1].a[1][1]=2;
    s[1].a[1][2]=2;
    s[1].a[1][3]=mod-1;
    s[1].a[2][1]=1;
    s[1].a[3][2]=1;
    I.a[1][1]=1;
    I.a[2][2]=1;
    I.a[3][3]=1;
    G.a[1][1]=0;
    G.a[2][1]=1;
    G.a[3][1]=1;
}

signed main(){
    file();
    cin>>n>>m;
    init_mt();
    for(int i=2;i<=100002;++i) s[i]=s[i-1]*s[1];
    build(1,1,n);
    while(m--){
        cin>>op>>x>>y;
        if(op==1) modify(1,x,y);
        else cout<<(ask(1,x,y).ms*G).a[1][1]<<"\n";
    }
}

T4