結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
103,932 KB
testcase_01 AC 109 ms
103,956 KB
testcase_02 AC 216 ms
104,800 KB
testcase_03 AC 215 ms
105,224 KB
testcase_04 AC 223 ms
104,996 KB
testcase_05 AC 1,195 ms
124,200 KB
testcase_06 AC 1,203 ms
123,816 KB
testcase_07 AC 1,207 ms
123,900 KB
testcase_08 AC 1,191 ms
124,284 KB
testcase_09 AC 1,324 ms
124,124 KB
testcase_10 AC 820 ms
124,228 KB
testcase_11 AC 888 ms
124,360 KB
testcase_12 AC 800 ms
124,728 KB
testcase_13 AC 734 ms
124,972 KB
testcase_14 AC 742 ms
125,288 KB
testcase_15 AC 743 ms
124,468 KB
testcase_16 AC 613 ms
124,720 KB
testcase_17 AC 589 ms
124,784 KB
testcase_18 AC 595 ms
124,604 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 m<mi:
      res+=binom(n,m+1)
      res%=mod
      m+=1
    while m>mi:
      res-=binom(n,m)
      res%=mod
      m-=1
    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
    ans[i]*=res
    ans[i]%=mod

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