https://codeforces.com/contest/1088/problem/C

题解:

因为有n+1次机会;完全可以改变所有值,使得数组第n+1次求余后成为等差数列。

但是如果正向操作,后面的操作会影响前面已经完成的元素,所以逆向操作。

只要计入后面每次加的值就行,为了防止溢出x,所以求余一下;

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG

using namespace std;
typedef long long ll;
const int N=10000;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m;
int a[N];
int b[N];
int c[N];
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    scanf("%d",&n);
    a[0]=-1;
    int flag=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i-1]>=a[i])
            flag=1;
       // b[i]=n+1-(a[i]%(n+1));
    }
     if(!flag){
        cout<<0<<endl;
        return 0;
    }
    ll sum=0;
     int cnt=0;
    for(int i=n;i>=1;i--){
        int temp=(a[i]+sum)%(n+1);
        if(temp<i){
           // cout<<1<<i<<i-temp<<endl;
            b[i]=i-temp;
            cnt++;
            sum+=i-temp;
        }else if(temp>i){
           // cout<<1<<i<<n+1-temp+i<<endl;
            b[i]=n+1+i-temp;
            sum+=n+1+i-temp;
            cnt++;
        }
        sum%=n+1;
    }
    if(cnt==0){
        cout<<cnt<<endl;
        return 0;
    }
    cout<<++cnt<<endl;
    for(int i=1;i<=n;i++){
            if(b[i])
        cout<<1<<" "<<i<<" "<<b[i]<<endl;
    }
    cout<<2<<" "<<n<<" "<<n+1<<endl;

   // cout << "Hello world!" << endl;
    return 0;
}