【 Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task】构造题


C. Ehab and a 2-operation task

题意

给你一个数组,有两种操作,
第一种操作是选择一段前缀全部加上x
第二种操作是选择一段前缀全部%x
最终用不超过n+1个操作构造一个递增数组

做法

我们考虑有Mod操作,所以其实数字可以加到特别大,最后一次Mod降下来就可以
而我们从后往前构造,就保证之后的操作不会影响之前的操作
然后我们只要让第i个数字%Mod=i就可以了。
由于数字最大值为1e5,所以这里Mod我选择的是1e5+7
之后每个数字先加上之前操作的贡献再%Mod
这是数字是小于Mod的,我们只要加上一些让它变成Mod+i就可以了。

代码

#include<stdio.h>
typedef long long ll;
const int maxn = 1e5+5;
const int Mod=100007;
int a[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    ll tt=0;
    printf("%d\n",n+1);
    for(int i=n;i>=1;i--)
    {
        ll fin=i+Mod;
        ll now=(tt+a[i])%Mod;
        printf("1 %d %d\n",i,(fin-now+Mod)%Mod);
        tt=(tt+(fin-now+Mod)%Mod)%Mod;
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_38891827/article/details/84824080