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. Android Studio 新建项目结构分析

    这是我刚刚新建的项目  默认都是Android模式的项目结构,但这并不是真实的目录结构 把他换成Project模式 项目的真实目录结构 1app 项目的代码,资源 2 gradle  wrappere ...

  2. [leetcode](4.21)3. 最长重复子串

    给定字符串 S,找出最长重复子串的长度.如果不存在重复子串就返回 0. 示例 1: 输入:"abcd" 输出:0 解释:没有重复子串. 示例 2: 输入:"abbaba& ...

  3. JavaWeb-BeginTomcat

    上手Tomcat 1.Ubuntu 18.04 下载/安装Tomcat 以下内容参考链接 安装JDK sudo apt-get update sudo apt-get install default- ...

  4. PNG,GIF,JPG的区别及如何选

    GIF: 1:256色 2: 无损,编辑 保存时候,不会损失. 3:支持简单动画. 4:支持boolean透明,也就是要么完全透明,要么不透明 JPEG: 1:millions of colors 2 ...

  5. 基于jquery二维码生成插件qrcode

    1.首先在页面中加入jquery库文件和qrcode插件. ? 1 2 <script type="text/javascript" src="jquery.js& ...

  6. Docker compose 调用外部文件及指定hosts 例子

    cat docker-compose.yml version: '3.4' services: klvchen: image: ${IMAGE_NAME} restart: always # dock ...

  7. js 字符串转数组

    var obj = "123456".replace(/(.)(?=[^$])/g, "$1,").split(",");    conso ...

  8. Human Motion Analysis with Wearable Inertial Sensors——阅读1

    Human Motion Analysis with Wearable Inertial Sensors——阅读 博主认为对于做室内定位和导航的人这是一篇很很棒的文章,不是他的技术很牛,而是这是一篇医 ...

  9. 判断字符串a和b是否互为旋转词

    旋转词:把字符串str的任意部分移动到后面形成的新字符串叫做字符串str的旋转词. 比如abc的旋转词有 abc,acb,cba,... 判断str1和str2是否互为旋转词,其最优解可以是时间复杂度 ...

  10. PVS桌面主镜像配置后,实际用户登录,配置未生效

    1.打开系统属性——高级——用户配置文件下的[设置] 2.打开用户配置文件,可以看到[复制]项灰化 3.使用windwows enable 工具启动上述灰化项,运行附件的exe文件后,任务栏出现下图标 ...