fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define MD (1000000007U)
  5. struct Rand{
  6. unsigned x;
  7. unsigned y;
  8. unsigned z;
  9. unsigned w;
  10. Rand(void){
  11. x=123456789;
  12. y=362436069;
  13. z=521288629;
  14. w=(unsigned)time(NULL);
  15. }
  16. Rand(unsigned seed){
  17. x=123456789;
  18. y=362436069;
  19. z=521288629;
  20. w=seed;
  21. }
  22. inline unsigned get(void){
  23. unsigned t;
  24. t = (x^(x<<11));
  25. x=y;
  26. y=z;
  27. z=w;
  28. w = (w^(w>>19))^(t^(t>>8));
  29. return w;
  30. }
  31. inline double getUni(void){
  32. return get()/4294967296.0;
  33. }
  34. inline int get(int a){
  35. return (int)(a*getUni());
  36. }
  37. inline int get(int a, int b){
  38. return a+(int)((b-a+1)*getUni());
  39. }
  40. inline long long get(long long a){
  41. return(long long)(a*getUni());
  42. }
  43. inline long long get(long long a, long long b){
  44. return a+(long long)((b-a+1)*getUni());
  45. }
  46. inline double get(double a, double b){
  47. return a+(b-a)*getUni();
  48. }
  49. inline int getExp(int a){
  50. return(int)(exp(getUni()*log(a+1.0))-1.0);
  51. }
  52. inline int getExp(int a, int b){
  53. return a+(int)(exp(getUni()*log((b-a+1)+1.0))-1.0);
  54. }
  55. }
  56. ;
  57. unsigned long long HashMap_ullP_L[4];
  58. template<class KEY, class VAL> struct HashMap{
  59. char*used;
  60. KEY*key;
  61. VAL*val;
  62. int mem;
  63. int n;
  64. int mask;
  65. HashMap(){
  66. mem = 0;
  67. }
  68. ~HashMap(){
  69. free();
  70. }
  71. void expand(int nn){
  72. if(mem >= nn){
  73. return;
  74. }
  75. if(mem){
  76. free();
  77. }
  78. mem = nn;
  79. used = new char[nn];
  80. key = new KEY[nn];
  81. val = new VAL[nn];
  82. }
  83. void free(){
  84. if(mem){
  85. mem = 0;
  86. delete[] used;
  87. delete[] key;
  88. delete[] val;
  89. }
  90. }
  91. void init(int nn){
  92. int i;
  93. n = 1;
  94. nn = nn + (nn + 1) / 2;
  95. while(n < nn){
  96. n *= 2;
  97. }
  98. mask = n - 1;
  99. expand(n);
  100. for(i=(0);i<(n);i++){
  101. used[i] = 0;
  102. }
  103. }
  104. inline int getHash(const int a){
  105. unsigned long long d = a;
  106. d = (((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) & mask;
  107. return d;
  108. }
  109. inline int getHash(const unsigned a){
  110. unsigned long long d = a;
  111. d = (((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) & mask;
  112. return d;
  113. }
  114. inline int getHash(const long long a){
  115. unsigned long long d = a;
  116. d = (((((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) >> 32) * HashMap_ullP_L[2]) & mask;
  117. return d;
  118. }
  119. inline int getHash(const unsigned long long a){
  120. unsigned long long d = a;
  121. d = (((((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) >> 32) * HashMap_ullP_L[2]) & mask;
  122. return d;
  123. }
  124. inline int getHash(const pair<int,int> a){
  125. unsigned long long d = (((unsigned long long)a.first) << 32) + ((unsigned long long)a.second);
  126. d = (((((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) >> 32) * HashMap_ullP_L[2]) & mask;
  127. return d;
  128. }
  129. inline VAL& operator[](const KEY a){
  130. int k = getHash(a);
  131. for(;;){
  132. if(used[k]==1 && key[k]==a){
  133. break;
  134. }
  135. if(used[k]==0){
  136. used[k] = 1;
  137. key[k] = a;
  138. break;
  139. }
  140. k = (k+1) & mask;
  141. }
  142. return val[k];
  143. }
  144. inline bool exist(const KEY a){
  145. int k = getHash(a);
  146. for(;;){
  147. if(used[k]==1 && key[k]==a){
  148. return true;
  149. }
  150. if(used[k]==0){
  151. break;
  152. }
  153. k = (k+1) & mask;
  154. }
  155. return false;
  156. }
  157. template<class S> inline bool exist(const KEY a, S &res){
  158. int k = getHash(a);
  159. for(;;){
  160. if(used[k]==1 && key[k]==a){
  161. res = val[k];
  162. return true;
  163. }
  164. if(used[k]==0){
  165. break;
  166. }
  167. k = (k+1) & mask;
  168. }
  169. return false;
  170. }
  171. }
  172. ;
  173. #define main dummy_main
  174. int main(){
  175. {
  176. int i;
  177. int j;
  178. int k;
  179. Rand rnd;
  180. for(i=(0);i<(20);i++){
  181. rnd.get(2);
  182. }
  183. for(i=(0);i<(4);i++){
  184. for(j=(0);j<(32);j++){
  185. k = rnd.get(1,62);
  186. HashMap_ullP_L[i] |= (1ULL << k);
  187. }
  188. HashMap_ullP_L[i] |= (1ULL << 0);
  189. HashMap_ullP_L[i] |= (1ULL << 63);
  190. }
  191. }
  192. return 0;
  193. }
  194. #undef main
  195. HashMap<int,int> hs;
  196. class Solution{
  197. public:
  198. int countPairs(vector<int>& A){
  199. int i;
  200. dummy_main();
  201. int N = A.size();
  202. int nx = 1;
  203. long long res = 0;
  204. sort(A.begin(), A.end());
  205. hs.init(N);
  206. for(i=(0);i<(N);i++){
  207. hs[A[i]] = 0;
  208. }
  209. for(i=(0);i<(N);i++){
  210. while(A[i] > nx){
  211. nx *= 2;
  212. }
  213. if(A[i] == nx){
  214. res += hs[A[i]];
  215. }
  216. if(hs.exist(nx-A[i])){
  217. res += hs[nx-A[i]];
  218. }
  219. hs[A[i]]++;
  220. }
  221. return res % MD;
  222. }
  223. }
  224. ;
  225. // cLay version 20210103-1
  226.  
  227. // --- original code ---
  228. // #define main dummy_main
  229. // {}
  230. // #undef main
  231. //
  232. // HashMap<int,int> hs;
  233. //
  234. // class Solution {
  235. // public:
  236. // int countPairs(vector<int>& A) {
  237. // dummy_main();
  238. // int N = A.size(), nx = 1;
  239. // ll res = 0;
  240. // sort(A.begin(), A.end());
  241. // hs.init(N);
  242. // rep(i,N) hs[A[i]] = 0;
  243. // rep(i,N){
  244. // while(A[i] > nx) nx *= 2;
  245. // if(A[i] == nx) res += hs[A[i]];
  246. // if(hs.exist(nx-A[i])) res += hs[nx-A[i]];
  247. // hs[A[i]]++;
  248. // }
  249. // return res % MD;
  250. // }
  251. // };
  252.  
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