結果

問題 No.3366 Reversible Tile:Revival
コンテスト
ユーザー cho435
提出日時 2025-11-14 17:48:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,712 bytes
コンパイル時間 4,528 ms
コンパイル使用メモリ 269,612 KB
実行使用メモリ 25,136 KB
最終ジャッジ日時 2025-11-17 20:46:21
合計ジャッジ時間 18,412 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 = ll;
S op(S a, S b) {
	return max(a, b);
}
S e() {
	return 0;
}
using F = ll;
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 mt(rd());
		rep(i, 0, m) {
			int nl = get_ith(l[i]);
			int nr = get_ith(r[i]);
			seg.apply(nl, nr, mt());
		}
	}
	map<ll, 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();
}
0