Codeforces Global Round 7 总结

Posted mollnn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Global Round 7 总结相关的知识,希望对你有一定的参考价值。

A

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

signed main() {
    int t,n;
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--) {
        cin>>n;
        if(n==1) {
            cout<<-1<<endl;
        }
        else {
            cout<<2;
            for(int i=1;i<n;i++) cout<<3;
            cout<<endl;
        }
    }
}

B

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

#define int long long
const int N = 1000005;

int n,a[N],b[N],c[N];

signed main() {
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>b[i];
    }
    a[1]=b[1];
    c[1]=0;
    for(int i=2;i<=n;i++) {
        c[i]=max(c[i-1],a[i-1]);
        a[i]=b[i]+c[i];
    }
    for(int i=1;i<=n;i++) cout<<a[i]<<" ";
}

C

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

#define int long long
const int mod = 998244353;
const int N = 1000005;

int n,k,a[N],p[N];

struct item {
    int id,x;
    bool operator < (const item &b) const {
        return x<b.x;
    }
} b[N];

signed main() {
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i], b[i]={i,a[i]};
    sort(b+1,b+n+1);
    int ans=0;
    for(int i=n-k+1;i<=n;i++) {
        ans+=b[i].x;
        p[i-n+k]=b[i].id;
    }
    sort(p+1,p+k+1);
    int tans=1;
    for(int i=1;i<k;i++) tans=tans*(p[i+1]-p[i])%mod;
    cout<<ans<<" "<<tans<<endl;
}

D

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

// Input: str[] (0-index)
// Method: solve()
// Output: a[] (i -> i*2+1)
namespace man {
const int N = 4100005;
char str[N], s[N<<1];
int a[N<<1];

int manacher(int len){
    a[0] = 0;
    int ans = 0, j;
    for(int i = 0; i < len; ){
        while(i-a[i]>0 && s[i+a[i]+1]==s[i-a[i]-1])
              a[i]++;
        if(ans < a[i])ans = a[i];
        j = i+1;
        while(j<=i+a[i] && i-a[i]!=i+i-j-a[i+i-j]){
            a[j] = min(a[i+i-j], i+a[i]-j);
            j++;
        }
        a[j] = max(i+a[i]-j, 0);
        i = j;
    }
    return ans;
}

int solve(){
    int len;
    len = 2*strlen(str)+1;
    for(int i=0;i<=2*len;i++) a[i]=0;
    for(int i = 0; str[i] != ''; i++){
        s[i+i] = '';
        s[i+i+1] = str[i];
    }
    s[len-1] = '';
    return manacher(len);
}
}

int t,k;
char str[2000005];
int n;

signed main() {
    ios::sync_with_stdio(false);
    cin>>t;
    while(t--) {
        cin>>str;
        n=strlen(str);
        int ans=0;
        for(k=0;k<n/2;k++) if(str[k]!=str[n-k-1]) break;
        for(int i=k;i<n-k;i++) man::str[i-k]=str[i];
        man::str[n-k-k]=0;
        man::solve();
        for(int i=0;i<2*(n-k-k);i++) if(i-man::a[i]==0) ans=max(ans,man::a[i]);
        for(int i=0;i<2*(n-k-k);i++) if(i+man::a[i]==2*(n-k-k)) ans=max(ans,man::a[i]);
        for(int i=0;i<2*(n-k-k);i++) if(i-man::a[i]==0) if(ans==man::a[i]) {
            for(int i=0;i<k+ans;i++) cout<<str[i];
            for(int i=n-k;i<n;i++) cout<<str[i];
            cout<<endl;
            goto E;
        }
        for(int i=0;i<2*(n-k-k);i++) if(i+man::a[i]==2*(n-k-k)) if(ans==man::a[i]) {
            for(int i=0;i<k;i++) cout<<str[i];
            for(int i=n-k-ans;i<n;i++) cout<<str[i];
            cout<<endl;
            goto E;
        }
        for(int i=0;i<k;i++) cout<<str[i];
        for(int i=n-k;i<n;i++) cout<<str[i];
        cout<<endl;
        E:cout<<"";
        for(int i=0;i<=2*n+3;i++) str[i]=0, man::s[i]=man::str[i]=0;
    }
}

E

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

#define int long long
const int N = 2000005;

int val[N],tag[N],a[N],b[N],p[N],n;

void pushdown(int p) {
    if(tag[p]) {
        val[p*2]+=tag[p];
        val[p*2+1]+=tag[p];
        tag[p*2]+=tag[p];
        tag[p*2+1]+=tag[p];
        tag[p]=0;
    }
}

void pushup(int p) {
    val[p]=max(val[p*2],val[p*2+1]);
}

void modify(int p,int l,int r,int ql,int qr,int x) {
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr) {
        tag[p]+=x;
        val[p]+=x;
    }
    else {
        pushdown(p);
        modify(p*2,l,(l+r)/2,ql,qr,x);
        modify(p*2+1,(l+r)/2+1,r,ql,qr,x);
        pushup(p);
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i], p[a[i]]=i;
    for(int i=1;i<=n;i++) cin>>b[i];
    int ans=n;
    cout<<ans<<" ";
    modify(1,1,n,1,p[n],1);
    for(int i=1;i<n;i++) {
        modify(1,1,n,1,b[i],-1);
        while(val[1]<=0) {
            --ans;
            modify(1,1,n,1,p[ans],1);
        }
        cout<<ans<<" ";
    }
}

以上是关于Codeforces Global Round 7 总结的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Global Round 7 题解(未完)(ABCD)

Codeforces Global Round 7 总结

Codeforces Global Round 7

Codeforces Global Round 7 题解

Codeforces Global Round 7 D2. Prefix-Suffix Palindrome (Hard version) -- manacher

Codeforces Global Round 7 D2. Prefix-Suffix Palindrome (Hard version)(Manacher算法+输出回文字符串)