結果
| 問題 |
No.1141 田グリッド
|
| コンテスト | |
| ユーザー |
sepa38
|
| 提出日時 | 2023-03-28 10:49:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,703 bytes |
| コンパイル時間 | 182 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 90,112 KB |
| 最終ジャッジ日時 | 2024-09-20 01:48:30 |
| 合計ジャッジ時間 | 5,737 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 TLE * 1 -- * 18 |
ソースコード
class segt:
def __init__(self, n, ele, calc):
self.num = 2 ** (n - 1).bit_length()
self.el = ele
self.data = [ele] * (2 * self.num)
self.calc = calc
def update(self, idx, x):
idx += self.num - 1
self.data[idx] = x
while idx > 0:
idx = (idx - 1) // 2
self.data[idx] = self.calc(self.data[2*idx+1], self.data[2*idx+2])
def renew(self, idx, x):
self.update(idx, self.calc(self.get(idx), x))
def prod(self, left, right):
l = left + self.num
r = right + self.num
res = self.el
while l < r:
if l % 2:
res = self.calc(res, self.data[l-1])
l += 1
if r % 2:
r -= 1
res = self.calc(res, self.data[r-1])
l //= 2
r //= 2
return res
def get(self, idx):
return self.data[idx+self.num-1]
def mul(x, y):
return x * y % (10 ** 9 + 7)
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
mod = 10 ** 9 + 7
if h < w:
st = [segt(w, 1, mul) for _ in range(h)]
for i in range(h):
for j in range(w):
st[i].update(j, 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 = [segt(h, 1, mul) for _ in range(w)]
for i in range(h):
for j in range(w):
st[j].update(i, 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)
sepa38