Codeforces Round #525 (Div. 2) -C. Ehab and a 2-operation task

15 篇文章 0 订阅
2 篇文章 0 订阅

博主链接

题目链接

Note

​ In the first sample, the array is already increasing so we don’t need any operations.

​ In the second sample:

​ In the first step: the array becomes [8,6,3].

​ In the second step: the array becomes [0,2,3].

题意:

给你一个n,然后n个数a[1~n],现在你可以对数组进行两种操作:

  • 对a[1~i]所有的数+x
  • 对a[1~i]所有的数对x取模

要求你在n+1次操作内将数组a变成一个递增序列,并输出每次的操作(答案不唯一)

题解:

答案说了可以n+1次,那么就先对每个位置都进行一次操作1,让所有数在着n次1操作结束后对n取模值等于下表i,因为每次操作影响范围为1i,所以可以选择倒着扫,保证处理过的数不会再变化。最后进行一次操作2,对1n进行对n取模

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e4+7;
const int mod=1e9+7;
int a[maxn];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    cout<<n+1<<endl;
    ll sum=0;
    int ans=0;
    for(int i=n;i>=1;i--){
        ans=(i-(a[i]+sum)%(n+1)+n+1)%(n+1);
        printf("1 %d %d\n",i,ans);
        sum+=ans;
    }
    printf("2 %d %d\n",n,n+1);
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值