結果
| 問題 |
No.3366 Reversible Tile:Revival
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-14 17:58:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 393 ms / 3,000 ms |
| コード長 | 1,729 bytes |
| コンパイル時間 | 4,480 ms |
| コンパイル使用メモリ | 271,852 KB |
| 実行使用メモリ | 25,132 KB |
| 最終ジャッジ日時 | 2025-11-17 20:46:40 |
| 合計ジャッジ時間 | 17,429 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)
template <class T> bool chmin(T& x, T y) {
return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
return x < y ? (x = y, true) : false;
}
struct io_setup {
io_setup() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
}
} io_setup;
using mint = atcoder::modint998244353;
// template atcoder lazy segtree
using S = unsigned long long;
S op(S a, S b) {
return max(a, b);
}
S e() {
return 0;
}
using F = S;
S mapping(F f, S x) {
return f ^ x;
}
F comp(F f, F g) {
return f ^ g;
}
F id() {
return 0;
}
using segtree = atcoder::lazy_segtree<S, op, e, F, mapping, comp, id>;
void solve() {
ll n, m;
cin >> n >> m;
vector<ll> l(m), r(m);
rep(i, 0, m) cin >> l[i] >> r[i], l[i]--;
vector<ll> cv = {0, n};
rep(i, 0, m) {
cv.push_back(l[i]);
cv.push_back(r[i]);
}
sort(cv.begin(), cv.end());
cv.erase(unique(cv.begin(), cv.end()), cv.end());
int k = cv.size();
auto get_ith = [&](ll x) {
return lower_bound(cv.begin(), cv.end(), x) - cv.begin();
};
segtree seg(k);
{
random_device rd;
mt19937_64 mt(rd());
rep(i, 0, m) {
int nl = get_ith(l[i]);
int nr = get_ith(r[i]);
seg.apply(nl, nr, mt());
}
}
map<S, mint> mp;
rep(i, 0, k - 1) {
mp[seg.get(i)] += cv[i + 1] - cv[i];
}
mint ans = 0;
{
mint tmp = mp[0] + (n - mp[0]) / 2;
ans += tmp * tmp;
mp.erase(0);
}
for (auto [hs, ad] : mp) {
ans += ad * ad / 4;
}
ans *= mint(2).pow(m);
cout << ans.val() << '\n';
}
int main() {
int t = 1;
// cin >> t;
while (t--) solve();
}