Advertisement
stlss

Untitled

Jun 16th, 2024
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.22 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. constexpr auto sp = " ";
  4. constexpr auto en = "\n";
  5.  
  6. using ull = unsigned long long;
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. #define isz(x) int((x).size())
  11. #define all(x) begin(x), end(x)
  12. #define rall(x) rbegin(x), rend(x)
  13. #define fin(x) for (auto& it : x) cin >> it;
  14. #define foutsp(x) for (auto& it : x) cout << it << " "; cout << en;
  15. #define fouten(x) for (auto& it : x) cout << it << en;
  16. #define fyesno(x) cout << (x ? "YES" : "NO") << en;
  17.  
  18. using namespace std;
  19.  
  20. void solve();
  21. void global();
  22.  
  23. ull get_gcd(ull a, ull b) {
  24.     return b == 0 ? a : gcd(b, a % b);
  25. }
  26.  
  27. ull get_lcm(ull a, ull b) {
  28.     return a * b / gcd(a, b);
  29. }
  30.  
  31. vector<int> to_z(string& s, bool flag = false) {
  32.     vector<int> z(isz(s));
  33.     if (flag) z[0] = isz(z);
  34.     int l = 0, r = 1;
  35.     for (int i = 1; i < isz(z); i++) {
  36.         if (r > i) z[i] = min(z[i - l], r - i);
  37.         while (z[i] + i < isz(z) && s[z[i]] == s[z[i] + i]) z[i]++;
  38.         if (r < z[i] + i) { l = i; r = z[i] + i; }
  39.     }
  40.     return z;
  41. }
  42.  
  43. ull get_c(ull n, ull k) {
  44.     ull r = 1, dif = n - k;
  45.     for (int i = 1; i <= k; i++)
  46.         r += r * dif / i;
  47.     return r;
  48. }
  49.  
  50. string get_bits(ull x) {
  51.     string r = "";
  52.     while (x != 0) {
  53.         if (x & 1) r.push_back('1');
  54.         else r.push_back('0');
  55.         x >>= 1;
  56.     }
  57.     reverse(all(r));
  58.     return r;
  59. }
  60.  
  61. string pi_str = "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
  62. string alphabet_str = "abcdefghijklmnopqrstuvwxyz";
  63.  
  64. double get_pi() {
  65.     return acos(-1);
  66. }
  67.  
  68. int my_rand(int left, int right) {
  69.     return rand() % (right - left + 1) + left;
  70. }
  71.  
  72. void test() {
  73.     solve();
  74. }
  75.  
  76. void tests() {
  77.     int t; cin >> t;
  78.     for (int i = 1; i <= t; i++) {
  79.         solve();
  80.     }
  81. }
  82.  
  83. int main() {
  84.     ios::sync_with_stdio(false);
  85.     cin.tie(nullptr); cout.tie(nullptr);
  86.     cout.setf(ios::fixed); cout.precision(12);
  87.  
  88.     srand(time(0));
  89.     global();
  90.     tests();
  91.  
  92.     return 0;
  93. }
  94.  
  95. void global() {
  96.  
  97. }
  98.  
  99. void solve() {
  100.     int n;
  101.     ull k;
  102.     cin >> n >> k;
  103.  
  104.     if (k & 1) {
  105.         cout << "No" << en;
  106.         return;
  107.     }
  108.  
  109.     vector<int> v(n);
  110.     for (int i = 0; i < n; i++)
  111.         v[i] = n - i;
  112.  
  113.     ull sum = 0;
  114.     for (int i = 0; i < n; i++)
  115.         sum += abs(v[i] - (i + 1));
  116.  
  117.     if (sum < k) {
  118.         cout << "No" << en;
  119.         return;
  120.     }
  121.  
  122.     vector<int> answer(n);
  123.     for (int i = 0; i < n; i++)
  124.         answer[i] = i + 1;
  125.  
  126.     if (k == 0) {
  127.         cout << "Yes" << en;
  128.         foutsp(answer);
  129.         return;
  130.     }
  131.  
  132.     ull k_ = 0;
  133.     for (int i = 0; i < n; i++) {
  134.         int j1 = i, j2 = n - i - 1;
  135.         int x = 2 * (j2 - j1);
  136.  
  137.         if (k_ + x < k) {
  138.             k_ += x;
  139.             swap(answer[j1], answer[j2]);
  140.         }
  141.         else if (k_ + x == k) {
  142.             swap(answer[j1], answer[j2]);
  143.  
  144.             cout << "Yes" << en;
  145.             foutsp(answer);
  146.  
  147.             return;
  148.         }
  149.         else {
  150.             int x = k - k_;
  151.             int j1 = i, j2 = i + x / 2;
  152.  
  153.             swap(answer[j1], answer[j2]);
  154.  
  155.             cout << "Yes" << en;
  156.             foutsp(answer);
  157.  
  158.             return;
  159.         }
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement