結果

問題 No.1141 田グリッド
ユーザー sepa38
提出日時 2023-03-28 10:54:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,411 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 88,748 KB
最終ジャッジ日時 2024-09-20 01:51:54
合計ジャッジ時間 5,607 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
  def __init__(self, n, element):
    self.num = n
    self.ele = element
    self.data = [self.ele] * (self.num + 1)
  
  def calc(self, x, y):
    return x * y % (10 ** 9 + 7)

  def update(self, idx, x):
    while idx <= self.num:
      self.data[idx] = self.calc(self.data[idx], x)
      idx += idx & -idx
  
  def sum(self, idx):
    res = self.ele
    while idx > 0:
      res = self.calc(res, self.data[idx])
      idx -= idx & -idx
    return res
  
  def prod(self, l, r):
    mod = 10 ** 9 + 7
    return self.sum(r) * pow(self.sum(l), mod-2, mod) % mod


h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
mod = 10 ** 9 + 7
if h < w:
  st = [BIT(w, 1) for _ in range(h)]
  for i in range(h):
    for j in range(w):
      st[i].update(j+1, a[i][j])
  for _ in range(int(input())):
    r, c = map(lambda x: int(x)-1, input().split())
    ans = 1
    for i in range(h):
      if i == r:
        continue
      ans *= st[i].prod(0, c) * st[i].prod(c+1, w) % mod
      ans %= mod
    print(ans)
else:
  st = [BIT(h, 1) for _ in range(w)]
  for i in range(h):
    for j in range(w):
      st[j].update(i+1, a[i][j])
  for _ in range(int(input())):
    r, c = map(lambda x: int(x)-1, input().split())
    ans = 1
    for j in range(w):
      if j == c:
        continue
      ans *= st[j].prod(0, r) * st[j].prod(r+1, h) % mod
      ans %= mod
    print(ans)
0