不会用set所以就用队列来模拟,大体思想是(没有)反正数据弱就每次取2个放回一个这样循环跑
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <vector>
#include <map>
#include <cstring>
#include <set>
using namespace std;
typedef long long LL;
const int MOD=1e9+7;
LL Pow(LL a,LL b);
const int MAXN=1e6+7;
const int MAX=0x3f3f3f3f;
queue<int>a,b,c,d;
int main()
{
ios::sync_with_stdio(false);
int n;
LL a1=0,b1=-MOD;
scanf("")
LL number;
int k0=0,k1=0,k2=0;
int pos=0;
for(int i=1;i<=n;i++)
{
cin>>number;
if(number==0)
a.push(i);
else if(number<0)
{
c.push(i);
if(b1<number)
{
b1=number;
pos=i;
}
//a1++;
// num1[k1++]=i;
}
else
{
b.push(i);
// num[k2++]=i;
}
}
int now,l,r;
while(a.size()>1)//a=0
{
l=a.front();
a.pop();
r=a.front();
a.pop();
cout<<"1"<<" "<<l<<" "<<r<<endl;
a.push(r);
}
while(b.size()>1)//b>0
{
l=b.front();
b.pop();
r=b.front();
b.pop();
cout<<"1"<<" "<<l<<" "<<r<<endl;
b.push(r);
}
if(c.size()%2==1)
{
if(c.size()==1)
{
l=c.front();
c.pop();
if(a.size()==0)
cout<<"2"<<" "<<l<<endl;
else
{
r=a.front();
a.pop();
cout<<"1"<<" "<<l<<" "<<r<<endl;
a.push(r);
}
}
else
{
while(c.size()>1)
{
l=c.front();
c.pop();
r=c.front();
c.pop();
if(l==pos&&a.size()!=0)
{
c.push(r);
r=a.front();
a.pop();
cout<<"1"<<" "<<l<<" "<<r<<endl;
a.push(r);
}
else if(l==pos&&a.size()==0)
{
c.push(r);
cout<<"2"<<" "<<l<<endl;
}
else if(a.size()!=0&&r==pos)
{
c.push(l);
l=a.front();
a.pop();
cout<<"1"<<" "<<l<<" "<<r<<endl;
a.push(l);
}
else if(r==pos&&a.size()==0)
{
c.push(l);
cout<<"2"<<" "<<r<<endl;
}
else
{
cout<<"1"<<" "<<l<<" "<<r<<endl;
c.push(r);
}
}
}
}
else
{
if(c.size()!=0)
{
while(c.size()>1)
{
l=c.front();
c.pop();
r=c.front();
c.pop();
cout<<"1"<<" "<<l<<" "<<r<<endl;
c.push(r);
}
}
}
if(a.size()!=0&&(b.size()!=0||c.size()!=0))///a为0 b为正数 c负数
{
cout<<"2"<<" "<<a.front()<<endl;
}
if(b.size()!=0&&c.size()!=0)
{
cout<<"1"<<" "<<b.front()<<" "<<c.front()<<endl;
}
return 0;
}
LL Pow(LL a,LL b)
{
LL ans=1;
while(b!=0)
{
if(b&1!=0)
{
ans=ans*a;
}
a*=a;
b>>=1;
}
return ans;
}
。。