fork download
  1. #include<bits/stdc++.h>
  2. #include<ext/pb_ds/assoc_container.hpp>
  3. #include<ext/pb_ds/tree_policy.hpp>
  4. #define ll long long int
  5. #define ld long double
  6. using namespace std;
  7. using namespace __gnu_pbds;
  8. #define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  9. typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
  10. const ll N = 1e6 + 5, MOD1 = 998244353, MOD2 = 1e9 + 7;
  11.  
  12. void solve(int t) {
  13. ll n, k;
  14. cin >> n >> k;
  15. vector<ll> ans(n + 1, -1);
  16. if (k & 1) {
  17. return void(cout << "No");
  18. }
  19. ll l = 1, r = n;
  20. while (l <= r) {
  21. if (k >= (r - l) * 2) {
  22. k -= (r - l) * 2;
  23. ans[l] = r;
  24. ans[r] = l;
  25. r--;
  26. l++;
  27. } else {
  28. if (k & 1) {
  29. return void(cout << "No");
  30. } else {
  31. ans[l] = l + k / 2;
  32. ans[l + k / 2] = l;
  33. k = 0;
  34. break;
  35. }
  36. }
  37. }
  38. if (k > 0) {
  39. return void(cout << "No");
  40. }
  41. cout << "Yes\n";
  42. for (int i = 1; i <= n; i++) {
  43. cout << (ans[i] == -1 ? i : ans[i]);
  44. if (i <= n - 1) cout << " ";
  45. }
  46. }
  47.  
  48. signed main() {
  49. FAST
  50. #ifndef ONLINE_JUDGE
  51. freopen("input.txt", "r", stdin);
  52. freopen("output.txt", "w", stdout);
  53. #endif
  54. int t = 1;
  55. cin>>t;
  56. for (ll i = 1; i <= t; i++) {
  57. solve(i);
  58. if (i < t) cout << "\n";
  59. }
  60. }
Runtime error #stdin #stdout #stderr 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc