fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. typedef long long ll;
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(false);
  9. cout.tie(NULL);
  10. cin.tie(NULL);
  11. ll n;
  12. cin>>n;
  13. ll a[200010];
  14. for(ll i=0;i<n;i++)
  15. cin>>a[i];
  16. vector<ll> v,s,m;
  17. for(ll i=0;i<n;i++)
  18. {
  19. if(a[i]==0)
  20. {
  21. v.push_back(i);
  22. }
  23. else if(a[i]<0)
  24. {
  25. s.push_back(a[i]);
  26. }
  27. }
  28. ll k,l;
  29. if(s.size()%2!=0)
  30. {
  31. sort(s.begin(),s.end());
  32. for(ll i=0;i<n;i++)
  33. {
  34. if(a[i]==s[s.size()-1])
  35. {
  36. a[i]=0;
  37. v.push_back(i);
  38. break;
  39. }
  40. }
  41. sort(v.begin(),v.end());
  42. }
  43. if(v.size()!=n){
  44. for(ll i=0;i<(v.size()-1);i++)
  45. {
  46. cout<<1<<" "<<v[i]+1<<" "<<v[i+1]+1<<endl;
  47. }
  48. if(v.size()>0)
  49. {
  50. cout<<2<<" "<<v[v.size()-1]+1<<endl;
  51. }
  52. l=n;
  53. for(ll i=0;i<n;i++)
  54. {
  55. if(a[i]!=0)
  56. {
  57. l=i;
  58. break;
  59. }
  60. }
  61. for(ll i=l;i<(n-1);i++)
  62. {
  63. k=(l+1);
  64. while(a[k]==0 && k<n)
  65. {
  66. k++;
  67. if(k>=n)
  68. break;
  69. }
  70. if(k<n)
  71. {
  72. cout<<1<<" "<<l+1<<" "<<k+1<<endl;
  73. l=k;
  74. i=(l-1);
  75. }
  76. }}
  77. else
  78. {
  79. for(ll i=0;i<(v.size()-1);i++)
  80. {
  81. cout<<1<<" "<<v[i]+1<<" "<<v[i+1]+1<<endl;
  82. }
  83. }
  84. return 0;
  85.  
  86. }
Runtime error #stdin #stdout 0s 4556KB
stdin
Standard input is empty
stdout
Standard output is empty