Codeforces Round #649 (Div. 2)题解

Problem A

让你求最长子数组,可以不被x整除。那么整除问题,我们直接取模做方便一点。然后,考虑怎么样会是-1的情况,很显然所有元素都是x的倍数,无论我们怎么选,都会是x的倍数。然后考虑最优情况,那肯定是总和加起来不是x的倍数那么答案一定是n。剩下的情况是怎么样的呢,剩下的情况就是总和可以被整除但是,有元素不能被整除,而且题目里面给了提示,说只能从首尾删除元素,那么我们放两个指针,开始扫,扫到不能被整除的元素就停止,比较两边大小输出即可。

Problem B

我们只需要发现一个性质,就是三个元素递增或者递减,那么他们只会使得长度最长,但是对我们所定义的差并没有贡献,所以发现这种的就把中间的元素删去就好了,至于最少两个这个条件完全是在坑爹的,因为第一个和最后一个元素,一定是满足条件的。

Problem C

首先我们发现,题目给定了a数组一定是非严格单调递增的,那么mex的问题我们可以先考虑小的,非严格递增那么无非是两种情况,后者大于前者,后者等于前者,那么模拟样例我们可以发现,如果后者大于前者,那么我们把这个Ai-1放到Bi的位置一定成立,应为两个a元素不相等,而且前面的情况都是合法的,如果相等的话,我们直接找不在集合里面的就可以了。

#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<iostream>
#include<set>
#include<cstring>
#include<cmath>
using namespace std;
#define rep(i,f_start,f_end) for (int i=f_start;i<=f_end;++i)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define MT(x,i) memset(x,i,sizeof(x) )
#define rev(i,start,end) for (int i=start;i<end;i++)
#define inf 0x3f3f3f3f
#define mp(x,y) make_pair(x,y)
#define lowbit(x) (x&-x)
#define MOD 1000000007
#define exp 1e-8
#define N 1000005 
#define fi first 
#define se second
#define pb push_back
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
typedef vector <int> VI;
typedef pair<int ,int> PII;
typedef pair<int ,PII> PIII;
ll gcd (ll a,ll b) {return b?gcd (b,a%b):a; }
inline int read() {
    char ch=getchar(); int x=0, f=1;
    while(ch<'0'||ch>'9') {
        if(ch=='-') f=-1;
        ch=getchar();
    } while('0'<=ch&&ch<='9') {
        x=x*10+ch-'0';
        ch=getchar();
    } return x*f;
}

const int maxn=1e6+10;
bool vis[maxn];
int a[maxn],b[maxn];

int main () {
    int n;
    scanf ("%d",&n);
    rep (i,1,n) scanf ("%d",&a[i]);
    MT (b,-1);
    rep (i,1,n) {
        if (a[i]!=a[i-1]) {
            b[i]=a[i-1];
            vis[b[i]]=true;
        }
    }
    vis[a[n]]=1;
    int m=0;
    rep (i,1,n) {
        while (vis[m]) m++;
        if (b[i]==-1)  {
            b[i]=m;
            vis[b[i]]=true;
        }
        printf ("%d ",b[i]);
    }
    return 0;
}
posted @ 2020-09-04 14:14  Luglucky  阅读(123)  评论(0编辑  收藏  举报