博主链接

题目链接

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;
}