Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. int mod = 1000007;
  6. int main() {
  7. int n,t;
  8. cin >> n;
  9. int cs = 350;
  10. int size = (n/cs)+1;
  11. int arr[size][350];
  12. double arr_sum[size];
  13. for(int i = 0; i < size; i++)
  14. {
  15. for(int j = 0; j < 350; j++)
  16. {
  17. arr[i][j] = 0;
  18. }
  19. arr_sum[i] = 1100000000;
  20. }
  21. int last = 0;
  22. for(int j = 0; j < 350; j++)
  23. {
  24. if(arr[size-1][j] != 0)
  25. {
  26. last++;
  27. }
  28. }
  29.  
  30. for(int i = 0; i < n; i++)
  31. {
  32. cin >> arr[i/350][i%350];
  33. arr_sum[i/350]=min((double)arr[i/350][i%350]/2, arr_sum[i/350]);
  34. }
  35.  
  36. for(int i = 0; i < n; i++) {
  37. double temp = arr[i / 350][i % 350] / 2;
  38. int failedblockindex = -1;
  39. for (int j = (i / 350) + 1; j < size; j++) {
  40. if (arr_sum[j] < temp) {
  41. failedblockindex = j;
  42. break;
  43. } else {
  44. temp = max((double) arr_sum[j], temp);
  45. }
  46. }
  47. for (int j = 0; j < i / 350; j++) {
  48. if (arr_sum[j] < temp) {
  49. failedblockindex = j;
  50. break;
  51. } else {
  52. temp = max((double) arr_sum[j], temp);
  53. }
  54. }
  55.  
  56.  
  57. int index = -1;
  58. for (int j = 0; j < 350; j++) {
  59. if (arr[failedblockindex][index] < temp && arr[failedblockindex][index] != 0) {
  60. index = j;
  61. break;
  62. }
  63. }
  64. if (failedblockindex == -1) {
  65. double temp3 = (double) arr[i / 350][i % 350] / 2;
  66. for (int j = i % 350; j < 350; j++) {
  67. if (arr[i / 350][j] < temp3 && arr[i / 350][j] != 0) {
  68. index = j;
  69. break;
  70. } else temp3 = max(temp3, (double) arr[i / 350][j] / 2);
  71. }
  72. if (index != -1)
  73. cout << (index - i) << " ";
  74. else {
  75. for (int j = 0; j < i % 350; j++) {
  76. if (arr[i / 350][j] < temp && arr[i / 350][j] != 0) {
  77. index = j;
  78. break;
  79. } else temp = max(temp, (double) arr[i / 350][j] / 2);
  80. }
  81. if (index == -1) cout << -1 << " ";
  82. else {
  83. cout << n - (i%350-index) << " ";
  84. // else cout << n - (350 - index - 1) << " "; //MAYBE CHECK SIZE =1
  85. }
  86.  
  87. }
  88. } else if (failedblockindex > i / 350 && failedblockindex != -1) {
  89. cout << (350 - i + 1 + ((failedblockindex - 1 - (i / 350)) * 350) + 350 - index) << " ";
  90. } else if(failedblockindex != -1 && failedblockindex < i / 350){
  91. cout << (350 - i + 1 + ((size - 1 - (i / 350)) * 350) + last + index + (failedblockindex - 1) * 350) << " ";
  92. }
  93. else
  94. {
  95. cout << -1 << " ";
  96. }
  97. }
  98.  
  99.  
  100.  
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement