Educational Codeforces Round #67

This is a really tragic problem of D ....... FST hundreds of people qwq .........

Topic links: poke me

A Stickers and Toys

A egg there may be only a toy, or just a sticker, or both. Give you the number of egg, toy, sticker, and you do not know the specific circumstances of each egg inside. Now you ask for at least the worst case how many egg broke down, at least to get a toy and a sticker.
drawer principle? nothing to say.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#define MAXN 200010
using namespace std;
int n,m,T,a,b;
 
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("ce.in","r",stdin);
    #endif
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&a,&b);
        int ans=max(n-a+1,n-b+1);
        cout<<ans<<endl;
    }
    return 0;
}

B Letters Shop

Give you a string s, and then asked a number of (String t), asked every time you need to take at least s of long prefixes, after re-combination can spell t.
Just write about it okay QAQ

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#define MAXN 200010
using namespace std;
int n,m;
int cnt[26],pos[26][MAXN],cur_cnt[26];
char s[MAXN],cur[MAXN];
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("ce.in","r",stdin);
    #endif
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
    {
        cnt[s[i]-'a']++;
        pos[s[i]-'a'][cnt[s[i]-'a']]=i;
    }
    scanf("%d",&m);
    for(int p=1;p<=m;p++)
    {
        scanf("%s",cur+1);
        int len=strlen(cur+1),ans=0;
        memset(cur_cnt,0,sizeof(cur_cnt));
        for(int i=1;i<=len;i++)
        {
            cur_cnt[cur[i]-'a']++;
            ans=max(ans,pos[cur[i]-'a'][cur_cnt[cur[i]-'a']]);
        }
        printf("%d\n",ans);
    }
    return 0;
}

C Vasya And Array

Given you some requirements, t = 1, required to sequences within a given interval monotonically falling, when 0 t =, required to sequences within a given interval the presence of at least one set \ (a_i, a_j \) satisfies \ (i < j \) and \ (a_i> a_j \) . lets you construct sequence.

We make a difference for the entire sequence. First monotonous not drop zone pull out the discussion, monotonous, not fall, then we can make them equal.
Then deal with the case of t = 0 ..... We can choose any interval not a and an equal number of previously required, so that he differential value -1. If no then this number, then the sequence constructed out of QAQ, returns false.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#define MAXN 200010
#define inf 0x3f3f3f3f
using namespace std;
int n,m;
int a[MAXN],done[MAXN],ans[MAXN];
struct Node{int op,l,r;}node[MAXN];
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("ce.in","r",stdin);
    #endif
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&node[i].op,&node[i].l,&node[i].r);
    }
    for(int i=2;i<=n;i++) a[i]=-inf;
    for(int i=1;i<=m;i++)
    {
        if(node[i].op==0) continue;
        for(int j=node[i].l+1;j<=node[i].r;j++) a[j]=0;
    }
    // for(int i=1;i<=n;i++) printf("%d ",a[i]); puts("");
    for(int i=1;i<=m;i++)
    {
        if(node[i].op==1) continue;
        bool flag=false;
        for(int j=node[i].l+1;j<=node[i].r;j++)
        {
            if(a[j]==-1) 
            {
                flag=true;
                break;
            }
            if(a[j]==-inf) 
            {
                a[j]=-1;
                flag=true;
                break;
            }
        }
        if(flag==false)
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    // for(int i=1;i<=n;i++) printf("%d ",a[i]); puts("");
    cout<<"YES"<<endl;
    for(int i=1;i<=n;i++) if(a[i]==-inf) a[i]=0;
    for(int i=1;i<=n;i++)  ans[i]=ans[i-1]+a[i];
    int minn=0;
    for(int i=1;i<=n;i++) minn=min(minn,ans[i]);
    for(int i=1;i<=n;i++) ans[i]+=-minn+1;
    for(int i=1;i<=n;i++) printf("%d ",ans[i]); puts("");
    return 0;
}

D Subarray Sorting

The most tragic of a question, a lot of people watching the race when all had. Then a large number of FST .........

Give you two sequences, A and B, each section can be arbitrarily selected sort (the default ordering from small to large), asked whether the operation from A to B.
think of when competition idea is, as long as the number two sequences inside are the same, certainly can not go because of the large little earlier, so long as the lexicographical a is greater than B on the line.
but it is easy to fork out ...... For example, a = 2 6 3 7, B = 2376

Consider positive solutions:
we built a tree line of A, minimum maintenance interval.
Then we consider B into them one by one, for example, the current process is B [i], this number appears in position A which is v us. demand [1, v] minimum, if the minimum value is less than b [i], it is impossible, returns false. otherwise, we change v is a large number (according to the meaning of problems a [i], b [i ] <= n, n + 1 can be changed so)
why this is the sub?
because if the discharge b [i] time, if the previous minimum value of a [j], which is in position B k , then obviously j <-> connection with the will of v k <-> after i intersect, and according to the principle of sort of a small number can not go behind the big numbers, so we changed completely illegal, quite in this position has been determined in the number B may be put, so to n + 1 so as not to affect the subsequent operations.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define MAXN 300010
using namespace std;
int n,T;
int a[MAXN],b[MAXN],minn[MAXN<<2],cnt[MAXN];
vector<int>pos[MAXN];
inline int ls(int x){return x<<1;}
inline int rs(int x){return x<<1|1;}
inline void push_up(int x){minn[x]=min(minn[ls(x)],minn[rs(x)]);}
inline void build(int x,int l,int r)
{
    if(l==r) {minn[x]=a[l];return;}
    int mid=(l+r)>>1;
    build(ls(x),l,mid);
    build(rs(x),mid+1,r);
    push_up(x);
}
inline void update(int x,int l,int r,int pos,int k)
{
    if(l==r) 
    {
        minn[x]=k;
        return;
    }
    int mid=(l+r)>>1;
    if(pos<=mid) update(ls(x),l,mid,pos,k);
    else update(rs(x),mid+1,r,pos,k);
    push_up(x);
}
inline int query(int x,int l,int r,int ll,int rr)
{
    if(ll<=l&&r<=rr) return minn[x];
    int mid=(l+r)>>1,cur_ans=0x3f3f3f3f;
    if(ll<=mid) cur_ans=min(cur_ans,query(ls(x),l,mid,ll,rr));
    if(mid<rr) cur_ans=min(cur_ans,query(rs(x),mid+1,r,ll,rr));
    return cur_ans;
}
inline bool solve()
{
    for(int i=1;i<=n;i++)
    {
        int siz=(int)pos[b[i]].size();
        if(siz<=cnt[b[i]]) return false;
        int now=pos[b[i]][cnt[b[i]]++];
        if(query(1,1,n,1,now)<b[i]) return false;
        update(1,1,n,now,n+1);
    }
    return true;
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("ce.in","r",stdin);
    #endif
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++) pos[i].clear(),cnt[i]=0;
        for(int i=1;i<=n;i++) 
        {
            scanf("%d",&a[i]);
            pos[a[i]].push_back(i);
        }
        for(int i=1;i<=n;i++) scanf("%d",&b[i]);
        build(1,1,n);
        if(solve()==true) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

E Tree Painting

Starter Edition meaning of the questions: Any pick a point for the root, find the largest sub-tree and the size.
I feel a bit like a changed root DP, the first to seek out again dfs subtree size to (say 1) as the root and then you come back a change dfs root, like

#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define MAXN 200010
using namespace std;
int n,t;
int head[MAXN],siz[MAXN];
long long ans;
struct Edge{int nxt,to;}edge[MAXN<<1];
inline void add(int from,int to)
{
    edge[++t].nxt=head[from],edge[t].to=to;
    head[from]=t;
}
inline void dfs(int x,int pre)
{
    siz[x]=1;
    for(int i=head[x];i;i=edge[i].nxt)
    {
        int v=edge[i].to;
        if(v==pre) continue;
        dfs(v,x);
        siz[x]+=siz[v];
        // printf("[%d %d] %d\n",x,v,siz[x]);
    }
}
inline void change_root(int x,int pre,long long w)
{
    ans=max(ans,w);
    for(int i=head[x];i;i=edge[i].nxt)
    {
        int v=edge[i].to;
        if(v==pre) continue;
        change_root(v,x,(w-siz[v])+(n-siz[v]));
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("ce.in","r",stdin);
    #endif
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        add(x,y),add(y,x);
    }
    dfs(1,0);
    // for(int i=1;i<=n;i++)
        // printf("siz[%d]=%d\n",i,siz[i]);
    for(int i=1;i<=n;i++) ans+=siz[i];
    // printf("ans=%lld\n",ans);
    change_root(1,0,ans);
    printf("%lld\n",ans);
    return 0;
}

This chicken dish is then the question will not write ......... behind the
first muttered it .......

(Well, the last question is intended to offer thanks about my race when BLUESKY007 fairy qwq)

Guess you like

Origin www.cnblogs.com/fengxunling/p/11119382.html