結果

問題 No.2336 Do you like typical problems?
ユーザー KudeKude
提出日時 2023-06-02 22:09:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 601 ms / 2,000 ms
コード長 2,365 bytes
コンパイル時間 2,804 ms
コンパイル使用メモリ 240,896 KB
実行使用メモリ 19,824 KB
最終ジャッジ日時 2023-08-28 03:45:53
合計ジャッジ時間 7,925 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 601 ms
19,696 KB
testcase_14 AC 593 ms
19,604 KB
testcase_15 AC 599 ms
19,676 KB
testcase_16 AC 595 ms
19,552 KB
testcase_17 AC 593 ms
19,672 KB
testcase_18 AC 69 ms
6,640 KB
testcase_19 AC 79 ms
6,756 KB
testcase_20 AC 483 ms
19,824 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>;
using mint = modint998244353;

struct S {
  int len;
  mint v;
};

S op(S x, S y) { return {x.len + y.len, x.v + y.v}; }
S e() { return {0, mint()}; }
mint composition(mint f, mint g) { return f + g; }
mint id() { return mint(); }
S mapping(mint f, S x) { return {x.len, x.v + x.len * f}; }

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;
  cin >> n;
  vector<P> bc(n);
  value_compression<int> vc;
  for(auto& [b, c] : bc) {
    cin >> b >> c;
    b--;
    vc.emplace_back(b);
    vc.emplace_back(c);
  }
  vc.build();
  int sz = int(vc.size()) - 1;
  vector<S> init(sz);
  rep(i, sz) init[i] = S{vc[i+1] - vc[i], mint()};
  lazy_segtree<S, op, e, mint, mapping, composition, id> seg(init);
  mint ans = mint(n) * (n - 1) / 2;
  for(auto [b, c] : bc) {
    int l = vc(b), r = vc(c);
    int len = c - b;
    mint inv = mint(len).inv();
    ans -= seg.prod(l, r).v * inv;
    seg.apply(l, r, inv);
  }
  ans /= 2;
  rep(i, n) ans *= i + 1;
  cout << ans.val() << '\n';
}
0