fork download
  1. #include <bits/stdc++.h>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int t, n, minIndex, maxIndex, num, min, max;
  8. cin>>t;
  9. while(t--){
  10. cin>>n;
  11. int a[n];
  12. min = INT_MAX;
  13. max = INT_MIN;
  14. minIndex = maxIndex = -1;
  15. for(int i=0; i<n; i++){
  16. cin>>a[i];
  17. if(a[i]>max){
  18. max=a[i];
  19. maxIndex=i;
  20. }
  21. if(a[i]<min){
  22. min=a[i];
  23. minIndex=i;
  24. }
  25. }
  26. //first part
  27. min = INT_MAX;
  28. for(int i=0; i<minIndex; i++){
  29. if(a[i]<min){
  30. min=a[i];
  31. cout<<'1';
  32. }else{
  33. cout<<'0';
  34. }
  35. }
  36. //second part
  37. for(int i=minIndex; i<=maxIndex; i++){
  38. if(i==minIndex || i==maxIndex){
  39. cout<<'1';
  40. continue;
  41. }
  42. cout<<'0';
  43. }
  44.  
  45. //third part
  46. max = INT_MIN;
  47. char an[n-maxIndex];
  48. for(int i=n-1; i>maxIndex; i--){
  49. if(a[i]>max){
  50. max=a[i];
  51. an[i] = '1';
  52. }else{
  53. an[i] = '0';
  54. }
  55. }
  56. for(int i=n-maxIndex-1; i>=0; i--){
  57. cout<< an[i];
  58. }
  59. cout<<endl;
  60. }
  61. return 0;
  62. }
Success #stdin #stdout 0s 5316KB
stdin
5
6
1 3 5 4 7 2
4
13 10 12 20
7
1 2 3 4 5 6 7
2
2 1
3
1 1 1
stdout
10001
1101
1000001
11O
110