原题链接:http://codeforces.com/contest/1042/problem/C
Array Product
You are given an array consisting of integers. You can perform the following operations with it:
- Choose some positions and , write the value of into the -th cell and remove the number from the -th cell;
- Choose some position and remove the number from the -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 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 — the number of elements in the array.
The second line contains integers — the elements of the array.
Output
Print lines. The -th line should contain one of the two possible operations.
The operation of the first type should look like this: , where is the type of operation, and are the positions of the chosen elements.
The operation of the second type should look like this: , where is the type of operation, 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:
. Thus, the maximum answer is
. Note, that other sequences that lead to the answer
are also correct.
The second example has, for example, the following sequence of transformations of the array:
. 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:
.
The third example can have the following sequence of transformations of the array:
.
The fourth example can have the following sequence of transformations of the array:
.
The fifth example can have the following sequence of transformations of the array:
.
题解
辣鸡贪心加大模拟,就是因为贴了这道题我的 没了, 。
代码
#include<bits/stdc++.h>
using namespace std;
const int M=2e5+5;
int que[M],c1[M],c2[M],pos,del,n,tot;
bool vis[M];
void in(){scanf("%d",&n);for(int i=1;i<=n;++i)scanf("%d",&que[i]);}
void ac()
{
for(int i=1;i<=n;++i)if(!que[i])c1[++c1[0]]=i;else if(que[i]<0)c2[++c2[0]]=pos=i;
for(int i=1;i<=n;++i)if(que[i]<0&&que[i]>que[pos])pos=i;
for(int i=1;i<c1[0];++i)printf("1 %d %d\n",c1[i],c1[i+1]),++tot,vis[c1[i]]=1;del=c1[c1[0]];
if(c1[0]&&(c2[0]&1))printf("1 %d %d\n",c1[c1[0]],pos),++tot,del=pos,vis[c1[c1[0]]]=1;
else if(c2[0]&1)del=pos;
if(tot==n-1)return;
if(del)printf("2 %d\n",del),vis[del]=1;
for(int i=1,p;i<=n;++i)
{
if(vis[i])continue;
for(p=i+1;p<=n;++p)if(!vis[p])break;
if(p>n)break;
printf("1 %d %d\n",i,p);
}
}
int main(){in();ac();}