Array Product(模拟)

Array Product

http://codeforces.com/problemset/problem/1042/C

You are given an array aa consisting of nn integers. You can perform the following operations with it:

  1. Choose some positions ii and jj (1i,jn,ij1≤i,j≤n,i≠j), write the value of aiajai⋅aj into the jj-th cell and remove the number from the ii-th cell;
  2. Choose some position ii and remove the number from the ii-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 n1n−1 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 nn (2n21052≤n≤2⋅105) — the number of elements in the array.

The second line contains nn integers a1,a2,,ana1,a2,…,an (109ai109−109≤ai≤109) — the elements of the array.

Output

Print n1n−1 lines. The kk-th line should contain one of the two possible operations.

The operation of the first type should look like this: 1 ik jk1 ik jk, where 11 is the type of operation, ikik and jkjk are the positions of the chosen elements.

The operation of the second type should look like this: 2 ik2 ik, where 22 is the type of operation, ikik 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.

Examples

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 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][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][X,X,X,−10,−3]→[X,X,X,X,30]. Thus, the maximum answer is 3030. Note, that other sequences that lead to the answer 3030 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][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][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][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][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].

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].

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].

 

简单的模板,要注意的就是只能删除一次

杂乱无章的代码。。。

 1 #include <iostream>
 2 #include<vector>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<set>
 6 using namespace std;
 7 
 8 int a[200005];
 9 vector<pair<int,int> >zheng,fu,ling;
10 
11 int main(){
12     std::ios::sync_with_stdio(false);
13     int n;
14     cin>>n;
15     set<int>s;
16     for(int i=1;i<=n;i++){
17         cin>>a[i];
18         if(a[i]==0){
19             ling.push_back(make_pair(a[i],i));
20         }
21         else if(a[i]>0){
22             zheng.push_back(make_pair(a[i],i));
23         }
24         else{
25             fu.push_back(make_pair(a[i],i));
26         }
27 
28     }
29     if((zheng.size()==0)&&(ling.size()>=0)&&(fu.size()==1)){
30         for(int i=2;i<=n;i++){
31             cout<<1<<" "<<i-1<<" "<<i<<endl;
32         }
33         return 0;
34     }
35     if((zheng.size()==0)&&(fu.size()==0)){
36         for(int i=1;i<ling.size();i++){
37             cout<<1<<" "<<ling[i-1].second<<" "<<ling[i].second<<endl;
38         }
39         return 0;
40     }
41     if(fu.size()>2){
42         sort(fu.begin(),fu.end());
43     }
44     int tmp1=-1,tmp2=-1,tmp3=-1,tmp4=-1;
45     int fulen;
46     if(fu.size()>0){
47         fulen=fu.size();
48         if(fu.size()%2){
49             fulen--;
50             tmp4=fu[fulen].second;
51         }
52         for(int i=1;i<fulen;i++){
53             cout<<1<<" "<<fu[i-1].second<<" "<<fu[i].second<<endl;
54         }
55         if(fu.size()==fulen)
56             tmp1=fu[fulen-1].second;
57         else if(fulen)
58             tmp1=fu[fulen-1].second;
59     }
60     if(ling.size()>0){
61         for(int i=1;i<ling.size();i++){
62             cout<<1<<" "<<ling[i-1].second<<" "<<ling[i].second<<endl;
63         }
64         tmp2=ling[ling.size()-1].second;
65     }
66     if(zheng.size()>0){
67         for(int i=1;i<zheng.size();i++){
68             cout<<1<<" "<<zheng[i-1].second<<" "<<zheng[i].second<<endl;
69         }
70         tmp3=zheng[zheng.size()-1].second;
71     }
72     if(tmp2!=-1&&tmp4!=-1){
73         cout<<1<<" "<<tmp2<<" "<<tmp4<<endl;
74         cout<<2<<" "<<tmp4<<endl;
75     }
76     else if(tmp2==-1&&tmp4!=-1){
77         cout<<2<<" "<<tmp4<<endl;
78     }
79     else if(tmp2!=-1&&tmp4==-1){
80         cout<<2<<" "<<tmp2<<endl;
81     }
82     if(tmp1!=-1&&tmp3!=-1){
83         cout<<1<<" "<<tmp1<<" "<<tmp3<<endl;
84     }
85 }
View Code

 

posted on 2018-09-27 22:12  Fighting_sh  阅读(152)  评论(0编辑  收藏  举报

导航