题意,题解都在代码里
代码:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int maxn=2e5+5;
int s[maxn];
int cnt[maxn];
signed main(){
/*
Equalize Them All 使他们全相等
Choose a pair of indices (i,j) such that |i−j|=1 (indices i and j are adjacent) and set ai:=ai+|ai−aj|;
Choose a pair of indices (i,j) such that |i−j|=1 (indices i and j are adjacent) and set ai:=ai−|ai−aj|.
*/
int n;cin>>n;
int mx=0;
for(int i=0;i<n;i++){
cin>>s[i];
cnt[s[i]]++;
if(cnt[s[i]]>cnt[mx])mx=s[i];//for maxcnt
}
cout<<n-cnt[mx]<<"\n";// for min cnt;
int index=0;
for(int i=0;i<n;i++){
if(s[i]==mx){
index=i;
break;
}
}
//for index mx
while(index>0){
index--;
if(s[index]<mx)printf("1 %d %d\n",index+1,index+2);//for example 2 8(index)
else if(s[index]>mx) printf("2 %d %d\n",index+1,index+2);//for example 10 8(index)
s[index]=mx;
}
/*for(int i=0;i<n;i++)cout<<s[i]<<" "; //for check
cout<<endl;*/
for(int i=0;i<n;i++){// the back of index
if(s[i]>mx)printf("2 %d %d\n",i+1,i);//for 8(mx) 10(i)
else if(s[i]<mx) printf("1 %d %d\n",i+1,i);//for 8(mx) 6(i)
}
return 0;
}