結果
| 問題 | No.3366 Reversible Tile:Revival |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-11-30 18:55:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,631 bytes |
| 記録 | |
| コンパイル時間 | 289 ms |
| コンパイル使用メモリ | 82,164 KB |
| 実行使用メモリ | 120,572 KB |
| 最終ジャッジ日時 | 2025-11-30 18:55:26 |
| 合計ジャッジ時間 | 26,086 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 24 WA * 21 |
ソースコード
INF = 10**9
MOD = 998244353
inv2 = (MOD+1)//2
inv4 = inv2*inv2 % MOD
N,M = map(int,input().split())
ans = 0
array = [(0,0)]
for _ in range(M):
L,R = map(int,input().split())
L -= 1
R -= 1
array.append((L, +1))
array.append((R+1, -1))
array.append((N,INF))
array.sort()
array_cum = []
c = 0
for i in range(len(array)-1):
#print(array[i],array[i+1])
L = array[i][0]
R = array[i+1][0]
c += array[i][1]
if L == R:
continue
array_cum.append((L,R,c))
#print(array_cum)
count_wraped = 0
count_samepair = 0
for i in range(len(array_cum)):
d = array_cum[i][2]
length = array_cum[i][1] - array_cum[i][0]
if d != 0:
count_wraped += length
count_samepair += (length*(length-1)%MOD)
count_samepair %= MOD
count_wraped %= MOD
count_nonwraped = (N - count_wraped)%MOD
#print(count_nonwraped)
count_fixedpair = count_nonwraped*(count_nonwraped-1)%MOD
count_diffpair = count_nonwraped*count_wraped%MOD*2%MOD
count_allpair = N * (N-1) % MOD
count_otherpair = count_allpair - count_diffpair - count_fixedpair - count_samepair
count_otherpair %= MOD
#print(count_wraped, count_nonwraped, count_diffpair, count_fixedpair, count_samepair, count_otherpair)
ans = 0
ans1 = count_wraped * pow(2,M,MOD) % MOD * inv2 % MOD
ans2 = count_nonwraped * pow(2,M,MOD) % MOD
ans3 = count_diffpair * pow(2,M,MOD) % MOD * inv2 % MOD
ans4 = count_fixedpair * pow(2,M,MOD) % MOD % MOD
ans5 = count_samepair * pow(2,M,MOD) % MOD * inv2 % MOD
ans6 = count_otherpair * pow(2,M,MOD) % MOD * inv4 % MOD
#print(ans1 , ans2 , ans3 , ans4 , ans5 , ans6)
ans = ans1 + ans2 + ans3 + ans4 + ans5 + ans6
ans %= MOD
print(ans)