Educational Codeforces Round 67 (Rated for Div. 2)

A

B

记录每种字母的出现次数前缀和,然后p[i][j]表示字母j出现至少i次的最靠前的位置,然后直接搜取最大即为答案,O(26(n+m)+Σ|ti|),差点想到二分去了,复杂度会多个log

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
int n,s[N][26],p[N][26],sum[26];
char str[N];
int main()
{
    scanf("%d",&n);
    scanf("%s",str+1);
    for(int i=1;i<=n;i++)
    for(int j=0;j<26;j++)
    if(j==str[i]-‘a‘)s[i][j]=s[i-1][j]+1;else s[i][j]=s[i-1][j];
    for(int i=1;i<=n;i++)
    for(int j=0;j<26;j++)
    p[i][j]=n+1;
    for(int i=1;i<=n;i++)
    for(int j=0;j<26;j++)
    p[s[i][j]][j]=min(p[s[i][j]][j],i);
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%s",str+1);
        for(int i=0;i<26;i++)sum[i]=0;
        int len=strlen(str+1),ans=0;
        for(int i=1;i<=len;i++)sum[str[i]-‘a‘]++;
        for(int i=0;i<26;i++)ans=max(ans,p[sum[i]][i]);
        printf("%d\n",ans);
    }
}

C

瞎构造一波即可。对于ti=0的直接覆盖,ti=1的代入检验。

#include<bits/stdc++.h>
using namespace std;
const int N=1007;
int n,m,cnt,now,R[N],a[N],b[N];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)R[i]=i;
    while(m--)
    {
        int op,x,y;scanf("%d%d%d",&op,&x,&y);
        if(op==1)
        {
            for(int i=x;i<=y;i++)R[i]=max(R[i],y);
        }
        else a[++cnt]=x,b[cnt]=y;
    }
    for(int i=n;i>=1;i--)R[i]=R[R[i]];
    for(int i=1;i<=cnt;i++)if(R[a[i]]>=b[i]){puts("NO");return 0;}
    puts("YES");
    now=n+1;
    for(int i=1;i<=n;i++)
    {
        printf("%d ",now);
        if(R[i]==i)now--;else now++;
    }
}

D

太难了,FST了一片,显然我也FST了。正解是这样的,首先判掉每种数个数不同的情况,然后接着判不可行的。对任意区间排序,等价于交换逆序对,然后扫描b数组,然后将a数组中等于b[i]的最左的数的位置j交换一下,然后判断a[i...j]是否存在<b[i]的数,存在则无解,反之,这个数将不会再用到,改成无穷大。显然可以用线段树维护。

#include<bits/stdc++.h>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
const int N=3e5+7;
int n,m,a[N],b[N],n1[N],n2[N],mn[N<<2];
queue<int>q[N];
void build(int l,int r,int rt)
{
    if(l==r){mn[rt]=a[l];return;}
    int mid=l+r>>1;
    build(lson),build(rson);
    mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
}
void update(int k,int v,int l,int r,int rt)
{
    if(l==r){mn[rt]=v;return;}
    int mid=l+r>>1;
    if(k<=mid)update(k,v,lson);else update(k,v,rson);
    mn[rt]=min(mn[rt<<1],mn[rt<<1|1]);
}
int query(int L,int R,int l,int r,int rt)
{
    if(L<=l&&r<=R)return mn[rt];
    int mid=l+r>>1,ret=1e9;
    if(L<=mid)ret=min(ret,query(L,R,lson));
    if(R>mid)ret=min(ret,query(L,R,rson));
    return ret;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]),n1[i]=n2[i]=0;
        for(int i=1;i<=n;i++)scanf("%d",&b[i]);
        for(int i=1;i<=n;i++)n1[a[i]]++,n2[b[i]]++;
        bool flag=0;for(int i=1;i<=n;i++)if(n1[i]!=n2[i]){flag=1;break;}
        if(flag){puts("NO");continue;}
        for(int i=1;i<=n;i++)while(!q[i].empty())q[i].pop();
        build(1,n,1);
        for(int i=1;i<=n;i++)q[a[i]].push(i);
        for(int i=1;i<=n;i++)
        {
            int pos=q[b[i]].front(),tmp=query(1,pos,1,n,1);
            q[b[i]].pop();
            update(pos,1e9,1,n,1);
            if(tmp<b[i])flag=1;
        }
        if(flag)puts("NO");else puts("YES");
    }
}

E

直接换根DP即可。

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+7;
typedef long long ll;
int n;
ll ans,sz[N],f[N];
vector<int>G[N];
void dfs(int u,int fa)
{
    sz[u]=1;
    for(int i=0;i<G[u].size();i++)if(G[u][i]!=fa)dfs(G[u][i],u),sz[u]+=sz[G[u][i]];
}
void dfs2(int u,int fa)
{
    for(int i=0;i<G[u].size();i++)if(G[u][i]!=fa)
    f[G[u][i]]=f[u]+n-2*sz[G[u][i]],dfs2(G[u][i],u);
}
int main()
{
    scanf("%d",&n);
    for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),G[x].push_back(y),G[y].push_back(x);
    dfs(1,0);
    for(int i=1;i<=n;i++)f[1]+=sz[i];
    dfs2(1,0);
    for(int i=1;i<=n;i++)ans=max(ans,f[i]);
    printf("%I64d",ans);
}

FG

没写,咕咕咕

result:新号打的。rank53,rating=1754

原文地址:https://www.cnblogs.com/hfctf0210/p/11116308.html

时间: 2024-10-10 22:59:30

Educational Codeforces Round 67 (Rated for Div. 2)的相关文章

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

get人生第七场CF! 成绩:(exACM) rank AC3/7 Penalty104 rating() 题目:Educational Codeforces Round 58 (Rated for Div. 2) 错题题解: C. Division and Union 原文地址:https://www.cnblogs.com/xht37/p/10260260.html

Educational Codeforces Round 59 (Rated for Div. 2) DE题解

Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contest/1107/problem/D 题意: 给出一个n*(n/4)的矩阵,这个矩阵原本是一些01矩阵,但是现在四个四个储存进二进制里面,现在给出的矩阵为0~9以及A~F,表示0~15. 然后问这个矩阵能否压缩为一个(n/x)*(n/x)的矩阵,满足原矩阵中大小为x*x的子矩阵所有数都相等(所有子矩阵构