結果

問題 No.2627 Unnatural Pitch
ユーザー KudeKude
提出日時 2024-02-09 23:49:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,721 bytes
コンパイル時間 4,180 ms
コンパイル使用メモリ 310,308 KB
実行使用メモリ 43,316 KB
最終ジャッジ日時 2024-02-09 23:49:10
合計ジャッジ時間 10,228 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 156 ms
30,968 KB
testcase_05 AC 157 ms
30,968 KB
testcase_06 WA -
testcase_07 AC 52 ms
11,940 KB
testcase_08 AC 101 ms
16,560 KB
testcase_09 AC 295 ms
43,192 KB
testcase_10 AC 267 ms
43,192 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 3 ms
6,676 KB
testcase_16 WA -
testcase_17 AC 522 ms
43,192 KB
testcase_18 AC 511 ms
43,316 KB
testcase_19 WA -
testcase_20 AC 153 ms
20,920 KB
testcase_21 WA -
testcase_22 AC 356 ms
39,020 KB
testcase_23 AC 176 ms
21,416 KB
testcase_24 AC 265 ms
24,552 KB
testcase_25 AC 269 ms
23,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;


auto floor_div(signed_integral auto x, signed_integral auto y) {
  return x / y - ((x ^ y) < 0 && x % y != 0);
}
template <integral T>
T floor_div(T x, unsigned_integral auto y) {
  return x >= 0 ? T(x / y) : -T(-x / y + (-x % y != 0));
}
auto ceil_div(signed_integral auto x, signed_integral auto y) {
  return x / y + ((x ^ y) >= 0 && x % y != 0);
}
template <integral T>
T ceil_div(T x, unsigned_integral auto y) {
  return x >= 0 ? T(x / y + (x % y != 0)) : -T(-x / y);
}

constexpr long long INF = 1002003004005006007;

template <class S>
struct value_compression : vector<S> {
  bool built = false;
  using VS = vector<S>;
  using VS::VS;
  value_compression(vector<S> v) : vector<S>(move(v)) {}
  void build() {
    sort(this->begin(), this->end());
    this->erase(unique(this->begin(), this->end()), this->end());
    built = true;
  }
  template <class T>
  void convert(T first, T last) {
    assert(built);
    for (; first != last; ++first) *first = (*this)(*first);
  }
  int operator()(S x) {
    assert(built);
    return lower_bound(this->begin(), this->end(), x) - this->begin();
  }
  void clear() {
    this->clear();
    built = false;
  }
};

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  ll l, r;
  cin >> n >> k >> l >> r;
  r++;
  VL addl, addr;
  vector<tuple<int, int, ll, ll>> add_seg;
  rep(_, n) {
    ll a;
    cin >> a;
    ll la = l - a, ra = r - a;
    auto lc = ceil_div(la, k);
    auto rc = ceil_div(ra, k) - 1;
    addl.emplace_back(lc);
    addr.emplace_back(rc);
    int nxt_l = (la - 1) % k;
    if (nxt_l < 0) nxt_l += k;
    int nxt_r = (ra - 1) % k;
    if (nxt_r < 0) nxt_r += k;
    if (nxt_l) add_seg.emplace_back(nxt_l, -1, -INF, lc);
    if (nxt_r) add_seg.emplace_back(nxt_r, 1, rc, INF);
  }
  value_compression<ll> vc;
  for (ll x : addl) vc.emplace_back(x);
  for (ll x : addr) vc.emplace_back(x);
  for (auto [t, v, l, r] : add_seg) vc.emplace_back(l), vc.emplace_back(r);
  vc.build();
  int sz = vc.size();
  VL init(sz);
  {
    ll a = 0, b = 0;
    sort(rall(addl));
    sort(rall(addr));
    for (ll x : addl) a--, b += x;
    rep(i, sz) {
      ll x = vc[i];
      while (addl.size() && addl.back() == x) {
        a++, b -= x;
        addl.pop_back();
      }
      while (addr.size() && addr.back() == x) {
        a++, b -= x;
        addr.pop_back();
      }
      ll v;
      if (__builtin_mul_overflow(x, a, &v)) v = INF;
      else v += b;
      init[i] = v;
    }
  }
  lazy_segtree<ll, [](ll x, ll y) { return min(x, y); }, []() { return INF; }, int, [](int f, ll x) { return x >= INF ? INF : x + f; }, [](int f, int g) { return f + g; }, []() { return 0; }> seg(init);
  sort(rall(add_seg));
  ll ans = seg.all_prod();
  rep(r, k) {
    while (add_seg.size() && get<0>(add_seg.back()) == r) {
      auto [_, v, l, r] = add_seg.back();
      add_seg.pop_back();
      seg.apply(vc(l), vc(r), v);
    }
    chmin(ans, seg.all_prod());
  }
  assert(add_seg.empty());
  cout << ans << '\n';
}
0