fork download
  1. /*
  2.   Cred : SunnyYeahBoi
  3.   It's my last chance (⌐■_■)
  4.   Problem :
  5. */
  6.  
  7. #include<bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. #define int long long
  12. #define double long double
  13. #define endl "\n"
  14. #define NAME "a"
  15.  
  16. const int MAXN = 1e6 + 5;
  17. const int inf = 1e18;
  18. const int MOD = 1e9 + 7;
  19.  
  20. void FileInput(){
  21. if(fopen(NAME".inp" , "r") == NULL)
  22. freopen(NAME".inp" , "w" , stdout);
  23. freopen(NAME".inp" , "r" , stdin);
  24. freopen(NAME".out" , "w" , stdout);
  25. }
  26.  
  27. int n , w;
  28. int a[MAXN];
  29. int b[MAXN];
  30. int c[MAXN];
  31.  
  32. int count(){
  33. map<int , int> cntC;
  34. for(int i = 1 ; i <= n ; i++)
  35. cntC[c[i]]++;
  36. int res = 0;
  37. for(int i = 1 ; i <= n ; i++)
  38. for(int j = 1 ; j <= n ; j++)
  39. if(a[i] == b[j])
  40. res += cntC[a[i]];
  41. return res;
  42. }
  43.  
  44. void solve(){
  45. cin >> n >> w;
  46.  
  47. for(int i = 1 ; i <= n ; i++)
  48. cin >> a[i];
  49. for(int i = 1 ; i <= n ; i++)
  50. cin >> b[i];
  51. for(int i = 1 ; i <= n ; i++)
  52. cin >> c[i];
  53.  
  54. if(w == 1){
  55. cout << count() << endl;
  56. }else if(w == 2){
  57. sort(a + 1 , a + 1 + n);
  58. sort(b + 1 , b + 1 + n);
  59. sort(c + 1 , c + 1 + n);
  60. map<int , int> cntC;
  61. for (int i = 1 ; i <= n ; i++)
  62. cntC[c[i]]++;
  63.  
  64. int res = 0;
  65. for(int i = 1 ; i <= n ; i++){
  66. for(int j = 1 ; j <= n ; j++){
  67. if(a[i] == b[j]){
  68. int T2 = upper_bound(c + 1 , c + 1 + n , a[i] + b[j] - 1) - c - 1;
  69. res += T2;
  70. }else if(a[i] != b[j]){
  71. // a = c
  72. if(b[j] < 2 * a[i])
  73. res += cntC[a[i]];
  74. // b = c
  75. if(a[i] < 2 * b[j])
  76. res += cntC[b[j]];
  77. }
  78. }
  79. }
  80.  
  81. cout << res << endl;
  82. }else if(w == 3){
  83. sort(c + 1 , c + 1 + n);
  84. int res = 0;
  85. for(int i = 1 ; i <= n ; i++)
  86. for(int j = 1 ; j <= n ; j++){
  87. int T2 = upper_bound(c + 1 , c + 1 + n , a[i] + b[j]) - c - 1;
  88. int T1 = upper_bound(c + 1 , c + 1 + n , abs(a[i] - b[j])) - c;
  89. res += T2 - T1 + 1;
  90. }
  91. cout << res << endl;
  92. }
  93. }
  94.  
  95. int32_t main(){
  96. //FileInput();
  97. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  98. int t = 1;
  99. // cin >> t;
  100. while(t--)
  101. solve();
  102. return 0;
  103. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty