結果
| 問題 |
No.3366 Reversible Tile:Revival
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-29 16:46:17 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 275 ms / 3,000 ms |
| コード長 | 1,519 bytes |
| コンパイル時間 | 3,440 ms |
| コンパイル使用メモリ | 293,672 KB |
| 実行使用メモリ | 22,408 KB |
| 最終ジャッジ日時 | 2025-11-17 20:36:08 |
| 合計ジャッジ時間 | 13,310 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define fast cin.tie(nullptr); ios_base::sync_with_stdio(false)
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll mod = 998244353;
struct Event{
ll pos;
ll type;
ll idx;
bool operator<(const Event &e) const {
if(pos != e.pos) return pos < e.pos;
return type < e.type;
}
};
void zobrist_init(vector<ull> &a){
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
for(int i = 0; i < a.size(); i++) a[i] = rng();
}
int main(){
fast;
ll n,m,l,r,two_pow = 748683265;// 4^{-1} mod 998244353
vector<Event> events;
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> l >> r;
events.push_back({l, 0, i});
events.push_back({r + 1, 1, i});
two_pow = (two_pow << 1) % mod;
}
vector<ull> zobrist(m + 1);
zobrist_init(zobrist);
sort(all(events));
map<ull,ll> t;
ll last = 1;
ull hash = 0;
for(auto&e : events){
ll now = e.pos;
if(now > last) t[hash] = (t[hash] + (now - last)) % mod;
hash ^= zobrist[e.idx];
last = now;
}
if(last <= n) t[hash] = (t[hash] + (n - last + 1)) % mod;
ll n0 = t[0],p = 0;
for(auto&[h,w] : t){
if(h) p = (p + w * (w - 1)) % mod;
}
ll ans = ((n + n0) % mod) % mod;
ans = (ans * ((n + n0) % mod)) % mod;
ans = (ans + n + p - n0) % mod;
ans = (ans * two_pow) % mod;
cout << ans << endl;
}