fork download
  1. #include <bits/stdc++.h>
  2.  
  3. //_ ************************** Advanced PBDS ***********************************
  4.  
  5. #include <ext/pb_ds/assoc_container.hpp>
  6. #include <ext/pb_ds/tree_policy.hpp>
  7.  
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10.  
  11. template<class T>
  12. using ordered_set = tree<
  13. T,
  14. null_type,
  15. less<T>,
  16. rb_tree_tag,
  17. tree_order_statistics_node_update
  18. >;
  19.  
  20.  
  21. //_ ****************************************************************************
  22.  
  23. #define int long long int
  24. #define double long double
  25. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  26.  
  27.  
  28. const int M = 1000000007;
  29. const int N = 3e5+9;
  30. const int INF = 2e9+1;
  31. const int LINF = 2000000000000000001;
  32.  
  33. inline int power(int a, int b, int mod=M) {
  34. int x = 1;
  35. a %= mod;
  36. while (b) {
  37. if (b & 1) x = (x * a) % mod;
  38. a = (a * a) % mod;
  39. b >>= 1;
  40. }
  41. return x;
  42. }
  43.  
  44.  
  45. //_ ***************************** START Below *******************************
  46.  
  47.  
  48.  
  49.  
  50. vector<int> a;
  51. vector<int> b;
  52.  
  53. int consistency(int n, int c, int d){
  54.  
  55. ordered_set<pair<int,int>> st;
  56.  
  57. int ans = 0;
  58.  
  59. for(int i=0; i<n; i++){
  60. int diff = a[i] - b[i];
  61. int k = c-d;
  62.  
  63.  
  64. ans += st.size() - st.order_of_key({ diff + k, -LINF});
  65.  
  66. st.insert({diff, i});
  67. }
  68.  
  69. return ans;
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. int practice(int n, int c, int d){
  87.  
  88.  
  89. return 0;
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96. void solve() {
  97.  
  98. int n, c, d;
  99. cin>> n >> c >> d;
  100.  
  101. a.resize(n);
  102. b.resize(n);
  103. for(int i=0; i<n; i++) cin >> a[i];
  104. for(int i=0; i<n; i++) cin >> b[i];
  105.  
  106. cout << consistency(n, c, d) << endl;
  107.  
  108.  
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115. int32_t main() {
  116. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  117.  
  118. int t = 1;
  119. // cin >> t;
  120. while (t--) {
  121. solve();
  122. }
  123.  
  124. return 0;
  125. }
Success #stdin #stdout 0.01s 5292KB
stdin
7 3 1
3 6 9 5 8 6 5
1 2 4 3 5 5 2
stdout
7