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