fork(5) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 1e3;
  5. int n, m, a[N];
  6.  
  7. int main(int argc, char **argv) {
  8. int t;
  9. scanf("%d", &t);
  10. while (t-- != 0) {
  11. scanf("%d%d", &n, &m);
  12. for (int i = 0; i < n; ++i)
  13. scanf("%d", &a[i]);
  14. int at = -1;
  15. for (int i = 0; i < n; ++i)
  16. if (a[i] != -1) {
  17. at = i;
  18. break;
  19. }
  20. assert(at != -1);
  21. for (int i = at + 1; i < n; ++i)
  22. a[i] = (a[i - 1] + 1) % m;
  23. for (int i = at - 1; i >= 0; --i)
  24. a[i] = ((a[i + 1] - 1) % m + m) % m;
  25. for (int i = 0; i < n; ++i)
  26. printf("%s%d", i ? " " : "", a[i]);
  27. puts("");
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty