結果
| 問題 |
No.2336 Do you like typical problems?
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2023-06-02 22:09:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 517 ms / 2,000 ms |
| コード長 | 2,365 bytes |
| コンパイル時間 | 2,573 ms |
| コンパイル使用メモリ | 232,236 KB |
| 最終ジャッジ日時 | 2025-02-13 18:33:31 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#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';
}
Kude