fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <iomanip>
  13. #include <cstring>
  14. #define dibs reserve
  15. #define OVER9000 1234567890
  16. #define patkan 9
  17. #define tisic 47
  18. #define soclose 10e-7
  19. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  20. #define chocolate win
  21. #define ff first
  22. #define ss second
  23. #define abs(x) ((x < 0)?-(x):(x))
  24. #define E(i) (*it)[i]
  25. // mylittlepony
  26. using namespace std;
  27.  
  28. int main() {
  29. // freopen("gift.in","r",stdin);
  30. int T;
  31. scanf(" %d",&T);
  32.  
  33. for(int t =0; t < T; t++) {
  34. int N,Q;
  35. cin >> N >> Q;
  36. vector< vector<int> > A(N);
  37. for(int i =0; i < N; i++) for(int j =0; j < 5; j++) {
  38. double d;
  39. scanf("%lf",&d);
  40. A[i].push_back((int)(d*1000));}
  41.  
  42. map<int,int> M[5];
  43. for(int i =0; i < N; i++) for(int j =0; j < 5; j++)
  44. M[j][A[i][j]] =0;
  45. for(int i =0; i < 5; i++) {
  46. int a =0;
  47. ALL_THE(M[i],it) {it->ss =a; a++;}}
  48.  
  49. int S[M[0].size()+1][M[1].size()+1][M[2].size()+1][M[3].size()+1][M[4].size()+1];
  50. memset(S,0,sizeof(S));
  51. for(int i =0; i < N; i++) {
  52. for(int j =0; j < 5; j++) A[i][j] =M[j][A[i][j]];
  53. S[A[i][0]+1][A[i][1]+1][A[i][2]+1][A[i][3]+1][A[i][4]+1]++;}
  54.  
  55. int z[5]; int y[5];
  56. for(y[0] =1; y[0] <= M[0].size(); y[0]++)
  57. for(y[1] =1; y[1] <= M[1].size(); y[1]++)
  58. for(y[2] =1; y[2] <= M[2].size(); y[2]++)
  59. for(y[3] =1; y[3] <= M[3].size(); y[3]++)
  60. for(y[4] =1; y[4] <= M[4].size(); y[4]++)
  61. for(int x =1; x < (1<<5); x++) {
  62. int k =0;
  63. for(int i =0; i < 5; i++) {
  64. z[i] =y[i]-((x>>i)&1);
  65. k +=((x>>i)&1);}
  66. int a =S[z[0]][z[1]][z[2]][z[3]][z[4]];
  67. S[y[0]][y[1]][y[2]][y[3]][y[4]] +=(2*(k%2)-1)*a;}
  68.  
  69. printf("Case %d:\n",t+1);
  70. for(int q =0; q < Q; q++) {
  71. int P[2][5];
  72. int R[2][5];
  73. for(int i =0; i < 10; i++) {
  74. double d;
  75. scanf(" %lf",&d);
  76. P[i/5][i%5] =(int)(d*1000);
  77. if(i/5 == 0) P[0][i%5]--;
  78. R[i/5][i%5] =0;
  79. ALL_THE(M[i%5],it) if(it->ff <= P[i/5][i%5]) R[i/5][i%5] =it->ss+1;
  80. }
  81.  
  82. int ans =0;
  83. for(int i =0; i < (1<<5); i++) {
  84. int x =0;
  85. vector<int> V(5,0);
  86. for(int j =0; j < 5; j++) {
  87. if((i&(1<<j)) != 0) {
  88. V[j] =R[1][j];
  89. x++;}
  90. else V[j] =R[0][j];}
  91. ans +=(2*(x%2)-1)*S[V[0]][V[1]][V[2]][V[3]][V[4]];}
  92. printf("%d\n",ans);}
  93. }
  94. return 0;}
  95.  
  96. // look at my code
  97. // my code is amazing
Success #stdin #stdout 0s 3436KB
stdin
1
10 3
5.0 6.0 6.0 5.0 4.0
1.0 9.0 3.0 8.0 0.0
1.0 7.0 7.0 5.0 5.0
4.0 0.0 1.0 9.0 8.0
6.0 0.0 5.0 6.0 0.0
6.0 7.0 6.0 5.0 4.0
1.0 4.0 5.0 6.0 6.0
5.0 7.0 8.0 9.0 8.0
1.0 3.0 3.0 7.0 9.0
1.0 2.0 8.0 4.0 8.0
0.0 1.0 2 3.0 4 5.0 6.0 7.0 8.0 9.0
4.0 0.0 1.0 5 0.0 6.0 7.0 6 9.0 8.0
3.0 2.0 5 7.0 8.0 5.0 5.0 6 8.0 9.0
stdout
Case 1:
3
4
0