結果

問題 No.3366 Reversible Tile:Revival
コンテスト
ユーザー kotatsugame
提出日時 2025-11-18 00:33:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 311 ms / 3,000 ms
コード長 840 bytes
コンパイル時間 1,248 ms
コンパイル使用メモリ 111,904 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2025-11-18 00:33:59
合計ジャッジ時間 12,133 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:17: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   33 |         for(auto[x,h]:LR)
      |                 ^
main.cpp:42:17: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   42 |         for(auto[h,v]:mp)
      |                 ^

ソースコード

diff #

#include<iostream>
#include<random>
#include<algorithm>
#include<vector>
#include<map>
#include<cassert>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
long N;
int M;
int TO[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M;
	mt19937_64 rng;
	vector<pair<long,unsigned long> >LR(M+M+1);
	LR[M+M]=make_pair(N,0uL);
	for(int i=0;i<M;i++)
	{
		long l,r;cin>>l>>r;
		l--;
		auto h=rng();
		LR[i+i]=make_pair(l,h);
		LR[i+i+1]=make_pair(r,h);
	}
	sort(LR.begin(),LR.end());
	map<unsigned long,mint>mp;
	mint prv=0;
	unsigned long H=0;
	for(auto[x,h]:LR)
	{
		mp[H]+=x-prv;
		prv=x;
		H^=h;
	}
	mint N0=mp[0uL];
	mint ans=N0*N0+N0*(N-N0)/2;
	mp.erase(0uL);
	for(auto[h,v]:mp)
	{
		ans+=v*v/2;
		ans+=N0*v/2;
		ans+=v*(N-N0-v)/4;
	}
	ans*=mint(2).pow(M);
	cout<<ans.val()<<endl;
}
0