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. inline int my_getchar_unlocked(){
  16. static char buf[1048576];
  17. static int s = 1048576;
  18. static int e = 1048576;
  19. if(s == e && e == 1048576){
  20. e = fread_unlocked(buf, 1, 1048576, stdin);
  21. s = 0;
  22. }
  23. if(s == e){
  24. return EOF;
  25. }
  26. return buf[s++];
  27. }
  28. inline void rd(int &x){
  29. int k;
  30. int m=0;
  31. x=0;
  32. for(;;){
  33. k = my_getchar_unlocked();
  34. if(k=='-'){
  35. m=1;
  36. break;
  37. }
  38. if('0'<=k&&k<='9'){
  39. x=k-'0';
  40. break;
  41. }
  42. }
  43. for(;;){
  44. k = my_getchar_unlocked();
  45. if(k<'0'||k>'9'){
  46. break;
  47. }
  48. x=x*10+k-'0';
  49. }
  50. if(m){
  51. x=-x;
  52. }
  53. }
  54. inline void rd(long long &x){
  55. int k;
  56. int m=0;
  57. x=0;
  58. for(;;){
  59. k = my_getchar_unlocked();
  60. if(k=='-'){
  61. m=1;
  62. break;
  63. }
  64. if('0'<=k&&k<='9'){
  65. x=k-'0';
  66. break;
  67. }
  68. }
  69. for(;;){
  70. k = my_getchar_unlocked();
  71. if(k<'0'||k>'9'){
  72. break;
  73. }
  74. x=x*10+k-'0';
  75. }
  76. if(m){
  77. x=-x;
  78. }
  79. }
  80. inline int rd_int(void){
  81. int x;
  82. rd(x);
  83. return x;
  84. }
  85. struct MY_WRITER{
  86. char buf[1048576];
  87. int s;
  88. int e;
  89. MY_WRITER(){
  90. s = 0;
  91. e = 1048576;
  92. }
  93. ~MY_WRITER(){
  94. if(s){
  95. fwrite_unlocked(buf, 1, s, stdout);
  96. }
  97. }
  98. }
  99. ;
  100. MY_WRITER MY_WRITER_VAR;
  101. void my_putchar_unlocked(int a){
  102. if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
  103. fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
  104. MY_WRITER_VAR.s = 0;
  105. }
  106. MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
  107. }
  108. inline void wt_L(char a){
  109. my_putchar_unlocked(a);
  110. }
  111. inline void wt_L(const char c[]){
  112. int i=0;
  113. for(i=0;c[i]!='\0';i++){
  114. my_putchar_unlocked(c[i]);
  115. }
  116. }
  117. template<class T, class U> inline T GCD_L(T a, U b){
  118. T r;
  119. while(b){
  120. r=a;
  121. a=b;
  122. b=r%a;
  123. }
  124. return a;
  125. }
  126. template<class T, class U> void reduceFraction(T&a, U&b){
  127. T g=GCD_L(a,b);
  128. a/=g;
  129. b/=g;
  130. }
  131. int N;
  132. int As;
  133. int Bs;
  134. long long A[100000];
  135. long long B[100000];
  136. int main(){
  137. int Lj4PdHRW;
  138. wmem = memarr;
  139. int KL2GvlyY = rd_int();
  140. for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
  141. int KrdatlYV;
  142. int i;
  143. int j;
  144. long long xu;
  145. long long xd;
  146. long long yu;
  147. long long yd;
  148. long long zu;
  149. long long zd;
  150. rd(As);
  151. {
  152. int cTE1_r3A;
  153. for(cTE1_r3A=(0);cTE1_r3A<(As);cTE1_r3A++){
  154. rd(A[cTE1_r3A]);
  155. }
  156. }
  157. rd(Bs);
  158. {
  159. int xr20shxY;
  160. for(xr20shxY=(0);xr20shxY<(Bs);xr20shxY++){
  161. rd(B[xr20shxY]);
  162. }
  163. }
  164. if(As != Bs){
  165. wt_L("NO");
  166. wt_L('\n');
  167. continue;
  168. }
  169. if(As==0){
  170. wt_L("YES");
  171. wt_L('\n');
  172. continue;
  173. }
  174. N = As;
  175. sortA_L(N, A);
  176. sortA_L(N, B);
  177. for(KrdatlYV=(0);KrdatlYV<(2);KrdatlYV++){
  178. for(i=(0);i<(N);i++){
  179. B[i] *= -1;
  180. }
  181. sortA_L(N, B);
  182. for(i=(1);i<(N);i++){
  183. if(A[i-1] == A[i] && B[i-1] != B[i]){
  184. goto ao_dF3pO;
  185. }
  186. if(A[i-1] != A[i] && B[i-1] == B[i]){
  187. goto ao_dF3pO;
  188. }
  189. }
  190. if(A[0]==A[N-1]){
  191. wt_L("YES");
  192. wt_L('\n');
  193. goto Q5VJL1cS;
  194. }
  195. xu = B[N-1] - B[0];
  196. xd = A[N-1] - A[0];
  197. reduceFraction(xu, xd);
  198. yu = B[0] * xd - A[0] * xu;
  199. yd = xd;
  200. for(i=(0);i<(N);i++){
  201. zu = xu * A[i] + yu;
  202. zd = xd;
  203. reduceFraction(zu, zd);
  204. if(zd < 0){
  205. {
  206. auto jbtyPBGc = (-1);
  207. zu *= jbtyPBGc;
  208. zd *= jbtyPBGc;
  209. }
  210. }
  211. if(zd != 1 || zu != B[i]){
  212. goto ao_dF3pO;
  213. }
  214. }
  215. wt_L("YES");
  216. wt_L('\n');
  217. goto Q5VJL1cS;
  218. ao_dF3pO:;
  219. }
  220. wt_L("NO");
  221. wt_L('\n');
  222. Q5VJL1cS:;
  223. }
  224. return 0;
  225. }
  226. // cLay varsion 20201031-1
  227.  
  228. // --- original code ---
  229. // int N, As, Bs;
  230. // ll A[1d5], B[1d5];
  231. // {
  232. // REP(rd_int()){
  233. // int i, j;
  234. // ll xu, xd, yu, yd, zu, zd;
  235. // rd(As,A(As),Bs,B(Bs));
  236. // if(As != Bs) wt("NO"), continue;
  237. // if(As==0) wt("YES"), continue;
  238. //
  239. // N = As;
  240. // sortA(N, A); sortA(N, B);
  241. //
  242. // rep(2){
  243. // rep(i,N) B[i] *= -1;
  244. // sortA(N, B);
  245. //
  246. // rep(i,1,N){
  247. // if(A[i-1] == A[i] && B[i-1] != B[i]) break_continue;
  248. // if(A[i-1] != A[i] && B[i-1] == B[i]) break_continue;
  249. // }
  250. //
  251. // if(A[0]==A[N-1]) wt("YES"), break_continue;
  252. //
  253. // xu = B[N-1] - B[0];
  254. // xd = A[N-1] - A[0];
  255. // reduceFraction(xu, xd);
  256. // yu = B[0] * xd - A[0] * xu;
  257. // yd = xd;
  258. //
  259. // rep(i,N){
  260. // zu = xu * A[i] + yu;
  261. // zd = xd;
  262. // reduceFraction(zu, zd);
  263. // if(zd < 0) (zu, zd) *= -1;
  264. // if(zd != 1 || zu != B[i]) break_continue;
  265. // }
  266. // wt("YES"), break_continue;
  267. // }
  268. // wt("NO");
  269. // }
  270. // }
  271.  
Time limit exceeded #stdin #stdout 5s 4536KB
stdin
Standard input is empty
stdout
Standard output is empty