fork download
  1. #include <bits/stdc++.h>
  2. #include <set>
  3. // #include<ext/pb_ds/assoc_container.hpp>
  4. // #include<ext/pb_ds/tree_policy.hpp>
  5. //
  6. // using namespace __gnu_pbds;
  7. using namespace std;
  8. void fileIO() {
  9. #ifndef ONLINE_JUDGE
  10. freopen("input.txt", "r", stdin);
  11. freopen("output.txt", "w", stdout);
  12. #endif
  13. }
  14. void fastIO() {
  15. ios_base::sync_with_stdio(false);
  16. cin.tie(nullptr);
  17. cout.tie(nullptr);
  18. }
  19. // typedef tree<int, null_type, greater_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
  20. // //less => min to max , less_equal => min to max and repeated (and order_of_key method give no.of elements smaller than
  21. // //greater => max to min , greater_equal => max to min and repeated (order_of_key method give no.of elements bigger than
  22. // void Erase(orderedSet &s, int val){
  23. // int rank = s.order_of_key(val);
  24. // auto it = s.find_by_order(rank);
  25. // s.erase(it);
  26. // }
  27.  
  28. #define tests int t; cin>>t; for(int l = 0;l < (t); l++)
  29. #define loop(n) for(int i = 0; i < (n); i++)
  30. #define lop(n) for(int g = 1; g <= (n); g++)
  31. #define lp(n) for(int j = 0; j < (n); j++)
  32. #define ll long long
  33. #define endl '\n'
  34.  
  35. signed main() {
  36. fastIO();
  37. fileIO();
  38. tests
  39. {
  40. int n , m , q; cin >> n >> m >> q;
  41. vector<int> teachers(m);
  42. loop (m) {
  43. cin >> teachers[m];
  44. }
  45. sort(teachers.begin() , teachers.end());
  46. loop (q) {
  47. int a ; cin >> a;
  48. if (a<teachers[0])
  49. cout << teachers[0]-1 << endl;
  50. else if (a>teachers[m-1])
  51. cout << n-teachers[m-1] << endl;
  52. else {
  53. int r = upper_bound(teachers.begin() , teachers.end() , a ) - teachers.begin();
  54. cout << (teachers[r]-teachers[r-1])/2 << endl;
  55. }
  56. }
  57. }
  58. }
  59.  
Success #stdin #stdout 0.01s 5316KB
stdin
2
8 1 1
6
3
10 3 3
1 4 8
2 3 10
stdout
8
10
10
10