fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int binarySearch(vector<int>* a, int d) {
  5. int ans = -1;
  6. int l = 0; int h = (*a).size()-1;
  7. while (l <= h) {
  8. int m = floor((l+h)/2);
  9. if (d < (*a)[m]) { h = m - 1; }
  10. else { l = m+1; ans = m; }
  11. // cout << "l=" << l << " m=" << m << " h=" << h << "\n";
  12. }
  13. return ans;
  14. }
  15.  
  16. void solve() {
  17. int n, k, q; cin >> n >> k >> q;
  18. vector<int> a(k+1); vector<int> b(k+1);
  19. a[0] = 0; b[0] = 0;
  20. for (int i = 0; i < k; i++) { cin >> a[i+1]; }
  21. for (int i = 0; i < k; i++) { cin >> b[i+1]; }
  22.  
  23. for (int i = 0; i < q; i++) {
  24. int d; cin >> d;
  25. int prev = binarySearch(&a, d);
  26. // cout << prev << " ";
  27.  
  28. if (d == a[prev]) { cout << b[prev] << " "; }
  29. else {
  30. int temp = floor( (d - a[prev]) * (b[prev+1]-b[prev]) / (a[prev+1]-a[prev]) );
  31. cout << b[prev+1]-b[prev] << " " << a[prev+1]-a[prev] << " " << temp << " ";
  32. cout << b[prev] + temp << " ";
  33. }
  34. }
  35. cout << "\n";
  36. }
  37.  
  38. int main() {
  39. int t; cin >> t;
  40. for (int i=0; i<t; i++) { solve(); }
  41. return 0;
  42. }
  43.  
Success #stdin #stdout 0s 5312KB
stdin
4
10 1 3
10
10
0
6
7
10 2 4
4 10
4 7
6
4
2
7
1000000000 1 1
1000000000
1000000000
99999999
6 1 3
6
5
2
6
5
stdout
0 10 10 6 6 10 10 7 7 
3 6 1 5 4 4 4 2 2 3 6 1 5 
1000000000 1000000000 0 0 
5 6 1 1 5 5 6 4 4