[codeforces 1042C]Array Product

time limit per test:1 second
memory limit per test:256 megabytes

You are given an array aconsisting of n n n integers. You can perform the following operations with it:

Choose some positions i i i and j ( 1 ≤ i , j ≤ n , i ≠ j ) j (1≤i,j≤n,i≠j) j(1i,jn,i̸=j), write the value of ai⋅aj into the j-th cell and remove the number from the i-th cell;
Choose some position iand remove the number from the i i i-th cell (this operation can be performed no more than once and at any point of time, not necessarily in the beginning).

The number of elements decreases by one after each operation. However, the indexing of positions stays the same. Deleted numbers can’t be used in the later operations.

Your task is to perform exactly n − 1 n−1 n1 operations with the array in such a way that the only number that remains in the array is maximum possible. This number can be rather large, so instead of printing it you need to print any sequence of operations which leads to this maximum number. Read the output format to understand what exactly you need to print.
Input

The first line contains a single integer n ( 2 ≤ n ≤ 2 ⋅ 105 ) n(2≤n≤2⋅105) n(2n2105) — the number of elements in the array.

The second line contains n n nintegers a 1 , a 2 , … , a n ( − 1 0 9 ≤ a i ≤ 1 0 9 ) a_1,a_2,…,a_n (−10^9≤a_i≤10^9) a1,a2,,an(109ai109) — the elements of the array.

Output

Print n − 1 n−1 n1 lines. The k k k-th line should contain one of the two possible operations.

The operation of the first type should look like this: 1 1 1 i k i_k ik j k j_k jk, where 1 1 1 is the type of operation, i k i_k ik and j k j_k jk are the positions of the chosen elements.

The operation of the second type should look like this: 2 2 2 i k ik ik, where 2 is the type of operation, i k ik ik is the position of the chosen element. Note that there should be no more than one such operation.
If there are multiple possible sequences of operations leading to the maximum number — print any of them.

Input

5
5 -2 0 1 -3

Output

2 3
1 1 2
1 2 4
1 4 5

Input

5
5 2 0 4 0

Output

1 3 5
2 5
1 1 2
1 2 4

Input

2
2 -1

Output

2 2

Input

4
0 -10 0 0

Output

1 1 2
1 2 3
1 3 4

Input

4
0 0 0 0

Output

1 1 2
1 2 3
1 3 4

Note

Let X X X be the removed number in the array. Let’s take a look at all the examples:

The first example has, for example, the following sequence of transformations of the array: [ 5 , − 2 , 0 , 1 , − 3 ] → [ 5 , − 2 , X , 1 , − 3 ] → [ X , − 10 , X , 1 , − 3 ] → [ X , X , X , − 10 , − 3 ] → [ X , X , X , X , 30 ] [5,−2,0,1,−3]→[5,−2,X,1,−3]→[X,−10,X,1,−3]→[X,X,X,−10,−3]→[X,X,X,X,30] [5,2,0,1,3][5,2,X,1,3][X,10,X,1,3][X,X,X,10,3][X,X,X,X,30]. Thus, the maximum answer is 30. Note, that other sequences that lead to the answer 30 30 30 are also correct.

The second example has, for example, the following sequence of transformations of the array: [ 5 , 2 , 0 , 4 , 0 ] → [ 5 , 2 , X , 4 , 0 ] → [ 5 , 2 , X , 4 , X ] → [ X , 10 , X , 4 , X ] → [ X , X , X , 40 , X ] [5,2,0,4,0]→[5,2,X,4,0]→[5,2,X,4,X]→[X,10,X,4,X]→[X,X,X,40,X] [5,2,0,4,0][5,2,X,4,0][5,2,X,4,X][X,10,X,4,X][X,X,X,40,X]

The following answer is also allowed:

1 5 3
1 4 2
1 2 1
2 3

Then the sequence of transformations of the array will look like this: [ 5 , 2 , 0 , 4 , 0 ] → [ 5 , 2 , 0 , 4 , X ] → [ 5 , 8 , 0 , X , X ] → [ 40 , X , 0 , X , X ] → [ 40 , X , X , X , X ] [5,2,0,4,0]→[5,2,0,4,X]→[5,8,0,X,X]→[40,X,0,X,X]→[40,X,X,X,X] [5,2,0,4,0][5,2,0,4,X][5,8,0,X,X][40,X,0,X,X][40,X,X,X,X]

The third example can have the following sequence of transformations of the array: [ 2 , − 1 ] → [ 2 , X ] [2,−1]→[2,X] [2,1][2,X]

The fourth example can have the following sequence of transformations of the array: [ 0 , − 10 , 0 , 0 ] → [ X , 0 , 0 , 0 ] → [ X , X , 0 , 0 ] → [ X , X , X , 0 ] [0,−10,0,0]→[X,0,0,0]→[X,X,0,0]→[X,X,X,0] [0,10,0,0][X,0,0,0][X,X,0,0][X,X,X,0]

The fifth example can have the following sequence of transformations of the array: [ 0 , 0 , 0 , 0 ] → [ X , 0 , 0 , 0 ] → [ X , X , 0 , 0 ] → [ X , X , X , 0 ] [0,0,0,0]→[X,0,0,0]→[X,X,0,0]→[X,X,X,0] [0,0,0,0][X,0,0,0][X,X,0,0][X,X,X,0]

题意:
给一个长度为 n n n的序列,有两种操作:
1 1 1 i i i j j j :将 i i i位置上的数字删除(给 i i i位置填一个X),然后将 j j j位置上的数字变为 a i ∗ a j a_i*a_j aiaj
2 2 2 i i i :将 i i i位置上的数字删除(给 i i i位置填一个X),这个操作最多做一次

要求做正好 n − 1 n-1 n1次操作,让最后剩下来的数字最大。

题 解 : 题解:
考虑没有0的情况:
1.如果有奇数个负数,那么就删除最大的负数,然后其他都全部通过操作 1 1 1乘到同一个位置就好了。
2.如果有偶数个负数,那么久所有的数字乘起来就好了。
考虑有0的情况:
先将所有的0乘到同一个位置。
1.如果有奇数个负数,那么将最大的负数乘到0上,然后删掉0,然后其他全部数字通过操作 1 1 1乘到同一个位置。
2.如果有偶数个负数,先删掉0,然后其他全部数字通过操作 1 1 1乘到同一个位置。

#include<bits/stdc++.h>
#define LiangJiaJun main
#define pa pair<int,int>
using namespace std;
vector<pa>fa,fb,f;
int n,a[200004];
bool vis[200004];
int w33ha(){
    memset(vis,0,sizeof(vis));
    fa.clear();
    fb.clear();
    f.clear();
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]==0){
            f.push_back(make_pair(a[i],i));
        }
        if(a[i]<0){
            fb.push_back(make_pair(a[i],i));
        }
        if(a[i]>0){
            fa.push_back(make_pair(a[i],i));
        }
    }
    sort(fb.begin(),fb.end());
    sort(fa.begin(),fa.end());
    if(f.size()==0){
        if(fb.size()&1){
            printf("2 %d\n",fb[fb.size()-1].second);
            int bg=-1,gt=fb[fb.size()-1].second;
            for(int i=1;i<=n;i++){
                if(i!=gt){
                    bg=i;
                }
            }
            if(bg==-1)return 0;
            for(int i=1;i<=n;i++){
                if(i!=gt&&bg!=i){
                    printf("1 %d %d\n",i,bg);
                }
            }
            return 0;
        }
        else{
            for(int i=2;i<=n;i++){
                printf("1 %d 1\n",i,1);
            }
            return 0;
        }
    }
    else{
        if(fb.size()&1){
            int cnt=0;
            for(int i=1;i<f.size();i++){
                printf("1 %d %d\n",f[i].second,f[0].second);
                ++cnt;
                vis[f[i].second]=1;
            }
            ++cnt;
            printf("1 %d %d\n",fb[fb.size()-1].second,f[0].second);
            vis[fb[fb.size()-1].second]=1;
            if(cnt<n-1)printf("2 %d\n",f[0].second);
            else return 0;
            vis[f[0].second]=1;
            int ge=-1;
            for(int i=1;i<=n;i++){
                if(!vis[i]){ge=i;break;}
            }
            for(int i=1;i<=n;i++){
                if(!vis[i]&&i!=ge)printf("1 %d %d\n",i,ge);
            }
            return 0;
        }
        else{
            int cnt=0;
            for(int i=1;i<f.size();i++){
                printf("1 %d %d\n",f[i].second,f[0].second);
                ++cnt;
                vis[f[i].second]=1;
            }

            if(cnt<n-1)printf("2 %d\n",f[0].second);
            else return 0;
            ++cnt;
            vis[f[0].second]=1;
            int ge=-1;
            for(int i=1;i<=n;i++){
                if(!vis[i]){ge=i;break;}
            }
            for(int i=1;i<=n;i++){
                if(!vis[i]&&i!=ge)printf("1 %d %d\n",i,ge);
            }
            return 0;
        }
    }
    return 0;
}
int LiangJiaJun(){
    while(scanf("%d",&n)!=EOF)w33ha();
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值