fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1e5, M = 1e9 + 7;
  5. int n, sol[N];
  6. pair<int, int> a[N];
  7.  
  8. int main(int argc, char **argv) {
  9. int t;
  10. scanf("%d", &t);
  11. while (t-- != 0) {
  12. scanf("%d", &n);
  13. for (int i = 0; i < n; ++i) {
  14. scanf("%d", &a[i].first);
  15. a[i].second = i;
  16. }
  17. sort(a, a + n);
  18. for (int i = 0; i < n; ++i) {
  19. int cur = a[i].second;
  20. if (i + 1 == n)
  21. sol[cur] = (a[i].first + a[n - 2].first) % M;
  22. else
  23. sol[cur] = (a[i].first + a[n - 1].first) % M;
  24. int k = upper_bound(a, a + n, make_pair(M - a[i].first - 1, N)) - a - 1;
  25. if (k >= 0) {
  26. if (k != i)
  27. sol[cur] = max(sol[cur], (a[i].first + a[k].first) % M);
  28. else if (k - 1 >= 0)
  29. sol[cur] = max(sol[cur], (a[i].first + a[k - 1].first) % M);
  30. }
  31. }
  32. for (int i = 0; i < n; ++i)
  33. printf("%s%d", i ? " " : "", sol[i]);
  34. puts("");
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 16416KB
stdin
Standard input is empty
stdout