fork(1) download
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
  3.  
  4. # include <iostream>
  5. # include <algorithm>
  6. using namespace std;
  7.  
  8. int a[101010];
  9. int b[101010];
  10.  
  11. int main() {
  12. ios_base::sync_with_stdio(0);cin.tie(0);
  13. int tc;
  14. cin >> tc;
  15. for (int cs = 1; cs <= tc; ++cs) {
  16. cout << "Case #" << cs << ": ";
  17. int n, k;
  18. cin >> n >> k;
  19. for (int i = 0; i < n; ++i) {
  20. cin >> a[i];
  21. }
  22. for (int i = 0; i < n; ++i) {
  23. cin >> b[i];
  24. }
  25. long long ans = 0;
  26. for (int i = n - 1; i >= 0; --i) {
  27. int whereA = int(std::lower_bound(a + i + 1, a + n, a[i]) - a);
  28. int x = a[i];
  29. for (int j = i; j < whereA; ++j) {
  30. a[j] = x;
  31. }
  32. int whereB = int(std::lower_bound(b + i + 1, b + n, b[i]) - b);
  33. x = b[i];
  34. for (int j = i; j < whereB; ++j) {
  35. b[j] = x;
  36. }
  37. for (int j = i; j < n; ++j) {
  38. ans += abs(a[j] - b[j]) <= k;
  39. }
  40. }
  41. cout << ans << endl;
  42. }
  43. return 0;
  44. }
  45.  
Runtime error #stdin #stdout 0s 16024KB
stdin
6
4 0
1 1 1 8
8 8 8 8
3 0
0 1 1
1 1 0
1 0
3
3
5 0
0 8 0 8 0
4 0 4 0 4
3 0
1 0 0
0 1 2
5 2
1 2 3 4 5
5 5 5 5 10
stdout
Standard output is empty