結果

問題 No.2206 Popcount Sum 2
ユーザー とりゐとりゐ
提出日時 2023-01-16 20:39:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,216 ms / 4,000 ms
コード長 1,126 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 125,024 KB
最終ジャッジ日時 2023-09-15 10:59:41
合計ジャッジ時間 17,132 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
103,916 KB
testcase_01 AC 116 ms
104,060 KB
testcase_02 AC 219 ms
105,124 KB
testcase_03 AC 215 ms
105,140 KB
testcase_04 AC 217 ms
105,168 KB
testcase_05 AC 1,211 ms
124,540 KB
testcase_06 AC 1,216 ms
124,192 KB
testcase_07 AC 1,214 ms
123,992 KB
testcase_08 AC 1,214 ms
124,092 KB
testcase_09 AC 1,201 ms
124,036 KB
testcase_10 AC 805 ms
124,528 KB
testcase_11 AC 800 ms
124,608 KB
testcase_12 AC 800 ms
124,404 KB
testcase_13 AC 736 ms
125,024 KB
testcase_14 AC 739 ms
124,824 KB
testcase_15 AC 728 ms
124,876 KB
testcase_16 AC 591 ms
124,432 KB
testcase_17 AC 586 ms
124,424 KB
testcase_18 AC 593 ms
124,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
input=lambda :stdin.readline()[:-1]

mod=998244353
M=(10**5)*3 
fac=[1]*M
ninv=[1]*M
finv=[1]*M
for i in range(2,M):
  fac[i]=fac[i-1]*i%mod
  ninv[i]=(-(mod//i)*ninv[mod%i])%mod
  finv[i]=finv[i-1]*ninv[i]%mod

def binom(n,k):
  if n<0 or k<0:
    return 0
  if k>n:
    return 0
  return (fac[n]*finv[k]%mod)*finv[n-k]%mod

pow2=[1]
for _ in range(M):
  pow2.append(pow2[-1]*2%mod)


N=2*10**5+10
q=int(input())
M=int(q**0.5)+1
bucket=[[] for i in range(M)]
ans=[0]*q
for i in range(q):
  n,m=map(int,input().split())
  ans[i]=pow2[n]-1
  n-=1
  m-=1
  bucket[m*M//N].append((m,n,i))

for i in range(M):
  if i&1:
    bucket[i].sort(key=lambda x:-x[1])
  else:
    bucket[i].sort(key=lambda x:x[1])

res=1
n=1
m=0
inv2=pow(2,mod-2,mod)

for b in bucket:
  for mi,ni,i in b:
    while n<ni:
      res=2*res-binom(n,m)
      res%=mod
      n+=1
    while n>ni:
      res=inv2*(res+binom(n-1,m))
      res%=mod
      n-=1
    while m<mi:
      res+=binom(n,m+1)
      res%=mod
      m+=1
    while m>mi:
      res-=binom(n,m)
      res%=mod
      m-=1
    ans[i]*=res
    ans[i]%=mod

print(*ans,sep='\n')
0