結果

問題 No.3271 PQ Dot Product
ユーザー amentorimaru
提出日時 2025-09-12 23:11:04
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 1,000 ms
コード長 5,131 bytes
コンパイル時間 4,355 ms
コンパイル使用メモリ 260,296 KB
実行使用メモリ 27,328 KB
最終ジャッジ日時 2025-09-12 23:44:26
合計ジャッジ時間 10,584 ms
ジャッジサーバーID
(参考情報)
judge2 / judge10
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#define ATCODER
#include <bit>
#include <cstdint>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <math.h>
#include <climits>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <bitset>
#include <chrono>
#include <type_traits>
using namespace std;

using ll = long long;

#define FOR(i, a, b) for(ll i=(a); i<(b);i++)
#define REP(i, n) for(ll i=0; i<(n);i++)
#define ROF(i, a, b) for(ll i=(b-1); i>=(a);i--)
#define PER(i, n) for(ll i=n-1; i>=0;i--)
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VP vector< pair<ll,ll> >
#define VVP vector<vector<pair<ll,ll>>>
#define all(i) begin(i),end(i)
#define SORT(i) sort(all(i))
#define EXISTBIT(x,i) (((x>>i) & 1) != 0)
#define MP(a,b) make_pair(a,b)
#ifdef ATCODER
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using mint2 = modint998244353;
#endif
template<typename T = ll>
vector<T> read(size_t n) {
  vector<T> ts(n);
  for (size_t i = 0; i < n; i++) cin >> ts[i];
  return ts;
}

template<typename TV, const ll N> void read_tuple_impl(TV&) {}
template<typename TV, const ll N, typename Head, typename... Tail>
void read_tuple_impl(TV& ts) {
  get<N>(ts).emplace_back(*(istream_iterator<Head>(cin)));
  read_tuple_impl<TV, N + 1, Tail...>(ts);
}
template<typename... Ts> decltype(auto) read_tuple(size_t n) {
  tuple<vector<Ts>...> ts;
  for (size_t i = 0; i < n; i++) read_tuple_impl<decltype(ts), 0, Ts...>(ts);
  return ts;
}

template<typename T> T det2(array<T, 4> ar) { return ar[0] * ar[3] - ar[1] * ar[2]; }
template<typename T> T det3(array<T, 9> ar) { return ar[0] * ar[4] * ar[8] + ar[1] * ar[5] * ar[6] + ar[2] * ar[3] * ar[7] - ar[0] * ar[5] * ar[7] - ar[1] * ar[3] * ar[8] - ar[2] * ar[4] * ar[6]; }
template<typename T> bool chmax(T& tar, T src) { return tar < src ? tar = src, true : false; }
template<typename T> bool chmin(T& tar, T src) { return tar > src ? tar = src, true : false; }
template<typename T> void inc(vector<T>& ar) { for (auto& v : ar) v++; }
template<typename T> void dec(vector<T>& ar) { for (auto& v : ar) v--; }
template<typename T> vector<pair<T, int>> id_sort(vector<T>& a) {
  vector<T, int> res(a.size());
  for (int i = 0; i < a.size(); i++)res[i] = MP(a[i], i);
  SORT(res);
  return res;
}

using val = pair<ll, ll>; using func = ll;

val op(val a, val b) { return MP(a.first + b.first, a.second + b.second); }
val e() { return MP(0LL, 0LL); }
val mp(func f, val a) { return MP(f * a.second, a.second); }
func comp(func f, func g) {
  if (g == -1)return f;
  else return g;
}
func id() { return -1; }

val mp2(func f, val a) {
  if (f == -1) {
    return e();
  }
  return MP(a.first + f * a.second, a.second);
}
func comp2(func f, func g) {
  if (f == -1) {
    return g;
  }
  if (g == -1) {
    return -1;
  }
  return f + g;
}
func id2() { return 0; }


// Rook
ll dxr[4] = { 1,0,-1,0 };
ll dyr[4] = { 0,1,0,-1 };
// Bishop
ll dxb[4] = { -1,-1,1,1 };
ll dyb[4] = { -1,1,-1,1 };
// qween
ll dxq[8] = { 0,-1,-1,-1,0,1,1,1 };
ll dyq[8] = { -1,-1,0,1,1,1,0,-1 };

void solve() {
  ll n, k;
  cin >> n >> k;
  ll mn = 0;
  ll mx = 0;
  REP(i, n) {
    mx += (i + 1) * (i + 1);
    mn += (i + 1) * (n - i);
  }
  if (k<mn || k>mx) {    
    cout << "No\n";
    return;
  }

  if (n <= 8) {
    VL a(n);
    REP(i, n)a[i] = i + 1;
    do {
      ll tmp = 0;
      REP(i, n) {
        tmp += (i + 1) * a[i];
      }
      if (tmp == k) {
        cout << "Yes\n";
        REP(i, n) {
          cout << i + 1 << " ";
        }
        cout << "\n";
        REP(i, n) {
          cout << a[i] << " ";
        }
        return;
      }
    } while (next_permutation(all(a)));
    cout << "No\n";
    return;
  }

  ll sum = mx;
  VL ans;
  auto dfs = [&](auto self, ll l0, ll r0)->void {
    if (l0 == r0)return;
    if (l0 + 1 == r0) {
      ans.push_back(l0 + 1);
      return;
    }
    ll l = l0 - 1, r = r0 - 1;
    while (l + 1 < r) {
      ll m = (l + r) / 2;
      ll add = (r0 - m) * (r0 - m - 1) / 2;
      if (sum - add >= k) {
        r = m;
      }
      else {
        l = m;
      }
    }
    sum -= (r0 - r) * (r0 - r - 1) / 2;
    self(self, l0, r);
    ans.push_back(r0);
    self(self, r, r0 - 1);
  };
  dfs(dfs, 0, n);
  if (sum != k) {
    
  }
  cout << "Yes\n";
  REP(i, n) {
    cout << i + 1 << " ";
  }
  cout << "\n";
  REP(i, n) {
    cout << ans[i] << " ";
  }

  //VL a(n);
  //REP(i, n)a[i] = i + 1;
  //map<ll, VVL> mp;
  //do {
  //  ll tmp = 0;
  //  REP(i, n) {
  //    tmp += (i + 1) * a[i];
  //  }
  //  mp[tmp].push_back(a);
  //} while (next_permutation(all(a)));
  //for (auto& [k, v] : mp) {
  //  cout << k << "\n";
  //  for (auto& vv : v) {
  //    for(auto&vvv:vv)
  //      cout << vvv << " ";
  //    ll sm = 0;
  //    REP(i, n) {
  //      FOR(j, i + 1, n) {
  //        sm += max(0LL, vv[i] - vv[j]);
  //      }
  //    }

  //    cout << ":" << sm << "\n";

  //  }
  //  
  //}
  return;
}

int main() {
  ll t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

0