https://codeforces.com/contest/1144/problem/D

题意:给定数组,进行操作:
要求将数组元素变成全部相同,保证可以完成,给出操作序列(注意操作过程中数组的数字不能超过10^18)

题解:找到一个众数,向两边操作

/*
*@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
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
int a[N];
int b[N];
char str;
struct node{
    int op,i,j;
}e[N];
int main()
{
#ifdef DEBUG
	freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
#endif
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    //scanf("%d",&t);
    //while(t--){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        b[a[i]]++;
    }
    cnt=0;
    int maxl=0;
    for(int i=0;i<=200000;i++){
        if(b[i]>cnt){
            maxl=i;
            cnt=b[i];
        }
    }
    int pos=0;
    for(int i=1;i<=n;i++){
       if(a[i]==maxl){
            pos=i;
       }
    }
    cnt=0;
    for(int i=pos-1;i>=1;i--){
        if(a[i+1]-a[i]>0){
            e[++cnt].op=1;
            e[cnt].i=i;
            e[cnt].j=i+1;
            a[i]=a[i+1];
        }else if(a[i+1]-a[i]<0){
            e[++cnt].op=2;
            e[cnt].i=i;
            e[cnt].j=i+1;
            a[i]=a[i+1];
        }
    }
    for(int i=pos+1;i<=n;i++){
        if(a[i-1]-a[i]>0){
            e[++cnt].op=1;
            e[cnt].i=i;
            e[cnt].j=i-1;
            a[i]=a[i-1];
        }else if(a[i-1]-a[i]<0){
            e[++cnt].op=2;
            e[cnt].i=i;
            e[cnt].j=i-1;
            a[i]=a[i-1];
        }
    }
    cout<<cnt<<endl;
    for(int i=1;i<=cnt;i++){
        cout<<e[i].op<<" "<<e[i].i<<" "<<e[i].j<<endl;
    }
    //}

#ifdef DEBUG
	printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
    //cout << "Hello world!" << endl;
    return 0;
}