D. Equalize Them All
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array aa consisting of nn integers. You can perform the following operations arbitrary number of times (possibly, zero):

  1. Choose a pair of indices (i,j)(i,j) such that |i−j|=1|i−j|=1 (indices ii and jj are adjacent) and set ai:=ai+|ai−aj|ai:=ai+|ai−aj|;
  2. Choose a pair of indices (i,j)(i,j) such that |i−j|=1|i−j|=1 (indices ii and jj are adjacent) and set ai:=ai−|ai−aj|ai:=ai−|ai−aj|.

The value |x||x| means the absolute value of xx. For example, |4|=4|4|=4, |−3|=3|−3|=3.

Your task is to find the minimum number of operations required to obtain the array of equal elements and print the order of operations to do it.

It is guaranteed that you always can obtain the array of equal elements using such operations.

Note that after each operation each element of the current array should not exceed 10181018 by absolute value.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of elements in aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤2⋅1050≤ai≤2⋅105), where aiai is the ii-th element of aa.

Output

In the first line print one integer kk — the minimum number of operations required to obtain the array of equal elements.

In the next kk lines print operations itself. The pp-th operation should be printed as a triple of integers (tp,ip,jp)(tp,ip,jp), where tptp is either 11 or 22 (11means that you perform the operation of the first type, and 22 means that you perform the operation of the second type), and ipip and jpjp are indices of adjacent elements of the array such that 1≤ip,jp≤n1≤ip,jp≤n, |ip−jp|=1|ip−jp|=1. See the examples for better understanding.

Note that after each operation each element of the current array should not exceed 10181018 by absolute value.

If there are many possible answers, you can print any.

Examples
input

Copy
5
2 4 6 6 6
output

Copy
2
1 2 3
1 1 2
input

Copy
3
2 8 10
output

Copy
2
2 2 1
2 3 2
input

Copy
4
1 1 1 1
output

Copy
0

这个题目比较简单,非常简单

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 100;
int a[maxn];
int vis[maxn];
struct node
{
int tp, x, y;
node(int tp = 0, int x = 0, int y = 0) :tp(tp), x(x), y(y){}
}exa[maxn];
int main()
{
int n;
cin >> n;
int ans = 0, mark = 0,flag=0;
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
vis[a[i]]++;
if(vis[a[i]]>ans)
{
ans = vis[a[i]];
mark = a[i];
flag = i;
}
}
int cnt = 0;
for(int i=flag;i>=1;i--)
{
if (a[i] == mark) continue;
if(a[i]>mark)
{
exa[cnt] = node(2,i, i+1);
cnt++;
}
else
{
exa[cnt] = node(1, i, i + 1);
cnt++;
}
}
for(int i=flag;i<=n;i++)
{
if (a[i] == mark) continue;
if(a[i]>mark)
{
exa[cnt] = node(2, i, i - 1);
cnt++;
}
else
{
exa[cnt] = node(1, i, i - 1);
cnt++;
}
}
printf("%d\n", cnt);
for(int i=0;i<cnt;i++)
{
printf("%d %d %d\n", exa[i].tp, exa[i].x, exa[i].y);
}
return 0;
}

  


D. Equalize Them All Codeforces Round #550 (Div. 3)的更多相关文章

  1. (原创)Codeforces Round #550 (Div. 3) D. Equalize Them All

    D. Equalize Them All time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. Codeforces Round #550 (Div. 3) D. Equalize Them All (贪心,模拟)

    题意:有一组数,可以选择某个数\(a_i\)相邻的一个数\(a_j\),然后可以让\(a_i\)加上或者减去\(|a_i-a_j|\),问最少操作多少次使得数组中所有数相同. 题解:不难发现,每次操作 ...

  3. CodeForces Round #550 Div.3

    http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...

  4. Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths

            F. Graph Without Long Directed Paths time limit per test 2 seconds memory limit per test 256 ...

  5. F. Graph Without Long Directed Paths Codeforces Round #550 (Div. 3)

    F. Graph Without Long Directed Paths time limit per test 2 seconds memory limit per test 256 megabyt ...

  6. Codeforces Round #550 (Div. 3) E. Median String (模拟)

    Median String time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  7. (原创)Codeforces Round #550 (Div. 3) A Diverse Strings

    A. Diverse Strings time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #550 (Div. 3)E. Median String

    把字符串看作是26进制的数,从后往前翻译,那么就可以把两个串变成对应的26进制的数字,那么只要把两个数加起来除以二就得到中间的串对应的数了,同理再转化回来就行了.但是这样会有一个问题就是串的长度有2e ...

  9. Codeforces Round #550 (Div. 3) E. Median String (思维,模拟)

    题意:给你两个字符串\(s\)和\(t\),保证\(t\)的字典序大于\(s\),求他们字典序中间的字符串. 题解:我们假设题目给的不是字符串,而是两个10禁止的正整数,那么输出他们之间的数只要把他两 ...

随机推荐

  1. Python正则进阶

    目录 1.Python正则表达式模块 1.1 正则表达式处理字符串主要有四大功能 1.2 Python中re模块使用正则表达式的两种方法 1.3 正则表达式对象的常用方法 1.4 匹配对象的属性与方法 ...

  2. .Net Core 读取配置文件 appsettings.json

    1. 首先些一个类 public class MySettings { public string P1 { get; set; } public string P2 { get; set; } } ...

  3. java8 Stream sorted()的一次调用链记录

    代码 public static void main (String[] args) { Stream.of("d2", "a2", "b1" ...

  4. 5.枚举和注解_EJ

    第30条: 用enum代替int常量 枚举类型是指由一组固定的常量组成合法值得类型.例如一年中的季节,太阳系中的行星或一副牌中的花色.在开发中我们经常在类使用static final来定义一个int常 ...

  5. #WEB安全基础 : HTML/CSS | 0x4HTML模块化

    想让你的网页变得整洁吗?找我就对了,当然你会认识几个新元素,和它们交朋友吧! 我帮你联系一下这几个新元素,这样交朋友就变得简单了 images里放着图片   以下是index.html的代码 < ...

  6. margin:0 auto是什么意思

    一.margin设置对象外边距 二.margin后面如果只有两个参数的话,第一个表示top和bottom,第二个表示left和right 因为0 auto

  7. phpcms调用指定文章内容模型的ID

    一.使用GET调用Phpcms V9指定id页面数据方法 {pc:get sql="SELECT * FROM cmsyou_news WHERE id='55'" cache=& ...

  8. margin塌陷与BFC总结

    只给出关键点,具体效果不做太多示范,真正的东西只有自己试了才能记住 BFC BFC触发: 1.position:absolute/fixed 2.float:left/right 3.display: ...

  9. FileInputStream、FileReader、FileWriter和File

    FileInputStream提供了对文件的字节读取 用于读取诸如图像数据之类的原始字节流       如:FileInputStream fis=new FileInputStream(new Fi ...

  10. HDFS客户端的权限错误:Permission denied

    报错:Permission denied: user=root, access=WRITE, inode="hadoop":hadoop:supergroup:rwxr-xr-x ...