fork download
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC optimize("unroll-loops")
  3. #pragma GCC optimize("inline")
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define MD (1000000007U)
  7. void*wmem;
  8. char memarr[96000000];
  9. template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  10. static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  11. (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  12. (*arr)=(T*)(*mem);
  13. (*mem)=((*arr)+x);
  14. }
  15. template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  16. walloc1d(arr, x2-x1, mem);
  17. (*arr) -= x1;
  18. }
  19. template<class S, class T> inline S chmin(S &a, T b){
  20. if(a>b){
  21. a=b;
  22. }
  23. return a;
  24. }
  25. template<class S, class T> inline S chmax(S &a, T b){
  26. if(a<b){
  27. a=b;
  28. }
  29. return a;
  30. }
  31. template<class T> struct Arr1d{
  32. int n;
  33. int mem;
  34. T*d;
  35. T& operator[](int a){
  36. return d[a];
  37. }
  38. void sort(){
  39. reset();
  40. std::sort(d, d+n);
  41. }
  42. int set_cumulative_sum;
  43. int cumulative_sum_mem;
  44. T*cumulative_sum;
  45. void setSum(void){
  46. int i;
  47. set_cumulative_sum = 1;
  48. if(cumulative_sum_mem < n+1){
  49. delete[] cumulative_sum;
  50. cumulative_sum = new T[n+1];
  51. cumulative_sum_mem = n+1;
  52. }
  53. cumulative_sum[0] = 0;
  54. for(i=(0);i<(n);i++){
  55. cumulative_sum[i+1] = cumulative_sum[i] + d[i];
  56. }
  57. }
  58. T getSum(int i, int j){
  59. if(set_cumulative_sum==0){
  60. setSum();
  61. }
  62. return cumulative_sum[j+1] - cumulative_sum[i];
  63. }
  64. void reset(){
  65. set_cumulative_sum = 0;
  66. }
  67. void constructor(){
  68. n = mem = 0;
  69. d = NULL;
  70. set_cumulative_sum = 0;
  71. cumulative_sum_mem = 0;
  72. cumulative_sum = NULL;
  73. }
  74. void destructor(){
  75. delete[] d;
  76. d = NULL;
  77. mem = n = 0;
  78. set_cumulative_sum = 0;
  79. cumulative_sum_mem = 0;
  80. delete[] cumulative_sum;
  81. cumulative_sum = NULL;
  82. }
  83. void constructor(int nn){
  84. constructor();
  85. malloc(nn);
  86. }
  87. void memory_expand(int nn){
  88. if(mem < nn){
  89. delete[] d;
  90. d = new T[nn];
  91. mem = nn;
  92. }
  93. }
  94. void malloc(int nn){
  95. reset();
  96. memory_expand(nn);
  97. n = nn;
  98. }
  99. void setN(int nn){
  100. reset();
  101. memory_expand(nn);
  102. n = nn;
  103. }
  104. void set(vector<T> &a){
  105. int i;
  106. int nn = a.size();
  107. setN(nn);
  108. for(i=(0);i<(nn);i++){
  109. d[i] = a[i];
  110. }
  111. }
  112. void set(int nn, T a[]){
  113. int i;
  114. setN(nn);
  115. for(i=(0);i<(nn);i++){
  116. d[i] = a[i];
  117. }
  118. }
  119. void free(){
  120. destructor();
  121. }
  122. Arr1d(){
  123. constructor();
  124. }
  125. Arr1d(int nn){
  126. constructor(nn);
  127. }
  128. ~Arr1d(){
  129. destructor();
  130. }
  131. }
  132. ;
  133. #define main dummy_main
  134. int main(){
  135. wmem = memarr;
  136. return 0;
  137. }
  138. #undef main
  139. Arr1d<long long> t1;
  140. Arr1d<long long> t2;
  141. class Solution{
  142. public:
  143. int minWastedSpace(vector<int>& packages, vector<vector<int>>& boxes){
  144. int i;
  145. dummy_main();
  146. long long res = 4611686016279904256LL;
  147. long long mx = -1;
  148. t1.malloc(100000+1);
  149. t2.malloc(100000+1);
  150. for(i=(0);i<(100000+1);i++){
  151. t1[i] = t2[i] = 0;
  152. }
  153. for(auto i : packages){
  154. auto cTE1_r3A = ((1));
  155. auto RZTsC2BF = (( i));
  156. t1[i]+=cTE1_r3A;
  157. t2[i]+=RZTsC2BF;
  158. chmax(mx, i);
  159. }
  160. for(auto v : boxes){
  161. int n = v.size();
  162. int s = -1;
  163. long long tmp = 0;
  164. sort(v.begin(), v.end());
  165. if(v[n-1] < mx){
  166. continue;
  167. }
  168. for(i=(0);i<(n);i++){
  169. tmp += v[i] * t1.getSum(s+1, v[i]) - t2.getSum(s+1, v[i]);
  170. s = v[i];
  171. }
  172. chmin(res, tmp);
  173. }
  174. if(res == 4611686016279904256LL){
  175. return -1;
  176. }
  177. return res % MD;
  178. }
  179. }
  180. ;
  181. // cLay version 20210607-1
  182.  
  183. // --- original code ---
  184. // #define main dummy_main
  185. // {}
  186. // #undef main
  187. //
  188. // Arr1d<ll> t1, t2;
  189. //
  190. // class Solution {
  191. // public:
  192. // int minWastedSpace(vector<int>& packages, vector<vector<int>>& boxes) {
  193. // dummy_main();
  194. // ll res = ll_inf, mx = -1;
  195. // t1.malloc(1d5+1);
  196. // t2.malloc(1d5+1);
  197. // rep(i,1d5+1) t1[i] = t2[i] = 0;
  198. //
  199. // for(auto i : packages){
  200. // (t1[i], t2[i]) += (1, i);
  201. // mx >?= i;
  202. // }
  203. // for(auto v : boxes){
  204. // int n = v.size(), s = -1;
  205. // ll tmp = 0;
  206. // sort(v.begin(), v.end());
  207. // if(v[n-1] < mx) continue;
  208. // rep(i,n){
  209. // tmp += v[i] * t1.getSum(s+1, v[i]) - t2.getSum(s+1, v[i]);
  210. // s = v[i];
  211. // }
  212. // res <?= tmp;
  213. // }
  214. //
  215. // if(res == ll_inf) return -1;
  216. // return res % MD;
  217. // }
  218. // };
  219.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty