fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. void*wmem;
  5. char memarr[96000000];
  6. template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  7. static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  8. (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  9. (*arr)=(T*)(*mem);
  10. (*mem)=((*arr)+x);
  11. }
  12. template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
  13. sort(a, a+N);
  14. }
  15. template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  16. int i;
  17. pair<T1, T2>*arr;
  18. walloc1d(&arr, N, &mem);
  19. for(i=(0);i<(N);i++){
  20. arr[i].first = a[i];
  21. arr[i].second = b[i];
  22. }
  23. sort(arr, arr+N);
  24. for(i=(0);i<(N);i++){
  25. a[i] = arr[i].first;
  26. b[i] = arr[i].second;
  27. }
  28. }
  29. template<class T1> void rsortA_L(int N, T1 a[], void *mem = wmem){
  30. sortA_L(N, a, mem);
  31. reverse(a, a+N);
  32. }
  33. template<class T1, class T2> void rsortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  34. sortA_L(N, a, b, mem);
  35. reverse(a, a+N);
  36. reverse(b, b+N);
  37. }
  38. template<class T> struct Arr1d{
  39. int n;
  40. int mem;
  41. T*d;
  42. T& operator[](int a){
  43. return d[a];
  44. }
  45. void sort(){
  46. reset();
  47. std::sort(d, d+n);
  48. }
  49. int set_cumulative_sum;
  50. int cumulative_sum_mem;
  51. T*cumulative_sum;
  52. void setSum(void){
  53. int i;
  54. set_cumulative_sum = 1;
  55. if(cumulative_sum_mem < n+1){
  56. delete[] cumulative_sum;
  57. cumulative_sum = new T[n+1];
  58. cumulative_sum_mem = n+1;
  59. }
  60. cumulative_sum[0] = 0;
  61. for(i=(0);i<(n);i++){
  62. cumulative_sum[i+1] = cumulative_sum[i] + d[i];
  63. }
  64. }
  65. T getSum(int i, int j){
  66. if(set_cumulative_sum==0){
  67. setSum();
  68. }
  69. return cumulative_sum[j+1] - cumulative_sum[i];
  70. }
  71. int set_const_len_left;
  72. int const_len_left_mem;
  73. int*const_len_left;
  74. void setConstLenLeft(void){
  75. int i;
  76. set_const_len_left = 1;
  77. if(const_len_left_mem < n){
  78. delete[] const_len_left;
  79. const_len_left = new int[n];
  80. const_len_left_mem = n;
  81. }
  82. for(i=(0);i<(n);i++){
  83. const_len_left[i] = 1;
  84. }
  85. for(i=(1);i<(n);i++){
  86. if(d[i]==d[i-1]){
  87. const_len_left[i] = const_len_left[i-1] + 1;
  88. }
  89. }
  90. }
  91. int ConstLenLeft(int st, T val){
  92. if(!set_const_len_left){
  93. setConstLenLeft();
  94. }
  95. if(val != d[st]){
  96. return 0;
  97. }
  98. return const_len_left[st];
  99. }
  100. int ConstLenLeft(int st){
  101. if(!set_const_len_left){
  102. setConstLenLeft();
  103. }
  104. return const_len_left[st];
  105. }
  106. int ConstLenLeftCyclic(int st, T val){
  107. if(!set_const_len_left){
  108. setConstLenLeft();
  109. }
  110. st %= n;
  111. if(st < 0){
  112. st += n;
  113. }
  114. if(val != d[st]){
  115. return 0;
  116. }
  117. if(const_len_left[st] != st+1 || d[st] != d[n-1]){
  118. return const_len_left[st];
  119. }
  120. if(const_len_left[n-1] == n){
  121. return 1073709056;
  122. }
  123. return const_len_left[st] + const_len_left[n-1];
  124. }
  125. int ConstLenLeftCyclic(int st){
  126. if(!set_const_len_left){
  127. setConstLenLeft();
  128. }
  129. st %= n;
  130. if(st < 0){
  131. st += n;
  132. }
  133. if(const_len_left[st] != st+1 || d[st] != d[n-1]){
  134. return const_len_left[st];
  135. }
  136. if(const_len_left[n-1] == n){
  137. return 1073709056;
  138. }
  139. return const_len_left[st] + const_len_left[n-1];
  140. }
  141. int set_const_len_right;
  142. int const_len_right_mem;
  143. int*const_len_right;
  144. void setConstLenRight(void){
  145. int i;
  146. set_const_len_right = 1;
  147. if(const_len_right_mem < n){
  148. delete[] const_len_right;
  149. const_len_right = new int[n];
  150. const_len_right_mem = n;
  151. }
  152. for(i=(0);i<(n);i++){
  153. const_len_right[i] = 1;
  154. }
  155. for(i=(n-1)-1;i>=(0);i--){
  156. if(d[i]==d[i+1]){
  157. const_len_right[i] = const_len_right[i+1] + 1;
  158. }
  159. }
  160. }
  161. int ConstLenRight(int st, T val){
  162. if(!set_const_len_right){
  163. setConstLenRight();
  164. }
  165. if(val != d[st]){
  166. return 0;
  167. }
  168. return const_len_right[st];
  169. }
  170. int ConstLenRight(int st){
  171. if(!set_const_len_right){
  172. setConstLenRight();
  173. }
  174. return const_len_right[st];
  175. }
  176. int ConstLenRightCyclic(int st, T val){
  177. if(!set_const_len_right){
  178. setConstLenRight();
  179. }
  180. if(val != d[st]){
  181. return 0;
  182. }
  183. st %= n;
  184. if(st < 0){
  185. st += n;
  186. }
  187. if(const_len_right[st] != n-st || d[st] != d[0]){
  188. return const_len_right[st];
  189. }
  190. if(const_len_right[0] == n){
  191. return 1073709056;
  192. }
  193. return const_len_right[st] + const_len_right[0];
  194. }
  195. int ConstLenRightCyclic(int st){
  196. if(!set_const_len_right){
  197. setConstLenRight();
  198. }
  199. st %= n;
  200. if(st < 0){
  201. st += n;
  202. }
  203. if(const_len_right[st] != n-st || d[st] != d[0]){
  204. return const_len_right[st];
  205. }
  206. if(const_len_right[0] == n){
  207. return 1073709056;
  208. }
  209. return const_len_right[st] + const_len_right[0];
  210. }
  211. int set_dhist;
  212. int dhist_mem;
  213. int*dhist;
  214. T dhist_mn;
  215. T dhist_mx;
  216. void setDHist(void){
  217. int i;
  218. int len;
  219. set_dhist = 1;
  220. if(n==0){
  221. return;
  222. }
  223. dhist_mn = dhist_mx = d[0];
  224. for(i=(1);i<(n);i++){
  225. if(dhist_mn > d[i]){
  226. dhist_mn = d[i];
  227. }
  228. if(dhist_mx < d[i]){
  229. dhist_mx = d[i];
  230. }
  231. }
  232. len = dhist_mx - dhist_mn + 1;
  233. if(dhist_mem < len){
  234. delete[] dhist;
  235. dhist = new int[len];
  236. dhist_mem = len;
  237. }
  238. for(i=(0);i<(len);i++){
  239. dhist[i] = 0;
  240. }
  241. for(i=(0);i<(n);i++){
  242. dhist[d[i] - dhist_mn]++;
  243. }
  244. }
  245. int dHist(T x){
  246. if(set_dhist==0){
  247. setDHist();
  248. }
  249. if(n == 0 || x < dhist_mn || x > dhist_mx){
  250. return 0;
  251. }
  252. return dhist[x - dhist_mn];
  253. }
  254. void reset(){
  255. set_cumulative_sum = 0;
  256. set_const_len_left = 0;
  257. set_const_len_right = 0;
  258. set_dhist = 0;
  259. }
  260. void memory_expand(int nn){
  261. if(mem < nn){
  262. delete[] d;
  263. d = new T[nn];
  264. mem = nn;
  265. }
  266. }
  267. void malloc(int nn){
  268. reset();
  269. memory_expand(nn);
  270. n = nn;
  271. }
  272. void setN(int nn){
  273. reset();
  274. memory_expand(nn);
  275. n = nn;
  276. }
  277. void set(vector<T> &a){
  278. int i;
  279. int nn = a.size();
  280. setN(nn);
  281. for(i=(0);i<(nn);i++){
  282. d[i] = a[i];
  283. }
  284. }
  285. void set(int nn, T a[]){
  286. int i;
  287. setN(nn);
  288. for(i=(0);i<(nn);i++){
  289. d[i] = a[i];
  290. }
  291. }
  292. void free(){
  293. destructor();
  294. }
  295. void constructor(){
  296. n = mem = 0;
  297. d = NULL;
  298. set_cumulative_sum = 0;
  299. cumulative_sum_mem = 0;
  300. cumulative_sum = NULL;
  301. set_const_len_left = 0;
  302. const_len_left_mem = 0;
  303. const_len_left = NULL;
  304. set_const_len_right = 0;
  305. const_len_right_mem = 0;
  306. const_len_right = NULL;
  307. set_dhist = 0;
  308. dhist_mem = 0;
  309. dhist = NULL;
  310. }
  311. void constructor(int nn){
  312. constructor();
  313. malloc(nn);
  314. }
  315. void destructor(){
  316. delete[] d;
  317. d = NULL;
  318. mem = n = 0;
  319. set_cumulative_sum = 0;
  320. cumulative_sum_mem = 0;
  321. delete[] cumulative_sum;
  322. cumulative_sum = NULL;
  323. set_const_len_left = 0;
  324. const_len_left_mem = 0;
  325. delete[] const_len_left;
  326. const_len_left = NULL;
  327. set_const_len_right = 0;
  328. const_len_right_mem = 0;
  329. delete[] const_len_right;
  330. const_len_right = NULL;
  331. set_dhist = 0;
  332. dhist_mem = 0;
  333. delete[] dhist;
  334. dhist = NULL;
  335. }
  336. Arr1d(){
  337. constructor();
  338. }
  339. Arr1d(int nn){
  340. constructor(nn);
  341. }
  342. ~Arr1d(){
  343. destructor();
  344. }
  345. }
  346. ;
  347. #define main dummy_main
  348. int main(){
  349. wmem = memarr;
  350. return 0;
  351. }
  352. #undef main
  353. Arr1d<int> arr;
  354. int v[100];
  355. int f[100];
  356. class Solution{
  357. public:
  358. vector<int> frequencySort(vector<int>& A){
  359. int i;
  360. dummy_main();
  361. int N = A.size();
  362. vector<int> res;
  363. arr.set(A);
  364. for(i=(0);i<(N);i++){
  365. {
  366. auto Q5VJL1cS = (A[i]);
  367. auto e98WHCEY = ( -arr.dHist(A[i]));
  368. v[i] = Q5VJL1cS;
  369. f[i] = e98WHCEY;
  370. }
  371. }
  372. rsortA_L(N, f, v);
  373. for(i=(0);i<(N);i++){
  374. res.push_back(v[i]);
  375. }
  376. return res;
  377. }
  378. }
  379. ;
  380. // cLay varsion 20201031-1
  381.  
  382. // --- original code ---
  383. // #define main dummy_main
  384. // {}
  385. // #undef main
  386. //
  387. // Arr1d<int> arr;
  388. // int v[100], f[100];
  389. //
  390. // class Solution {
  391. // public:
  392. // vector<int> frequencySort(vector<int>& A) {
  393. // dummy_main();
  394. // int N = A.size();
  395. // vector<int> res;
  396. //
  397. // arr.set(A);
  398. // rep(i,N) (v[i], f[i]) = (A[i], -arr.dHist(A[i]));
  399. //
  400. // rsortA(N, f, v);
  401. // rep(i,N) res.push_back(v[i]);
  402. //
  403. // return res;
  404. // }
  405. // };
  406.  
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