結果
問題 | No.1649 Manhattan Square |
ユーザー |
|
提出日時 | 2021-07-28 21:48:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,366 ms / 3,000 ms |
コード長 | 1,696 bytes |
コンパイル時間 | 412 ms |
コンパイル使用メモリ | 82,072 KB |
実行使用メモリ | 106,408 KB |
最終ジャッジ日時 | 2024-10-03 15:54:31 |
合計ジャッジ時間 | 50,750 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
52,608 KB |
testcase_01 | AC | 34 ms
52,352 KB |
testcase_02 | AC | 125 ms
79,628 KB |
testcase_03 | AC | 131 ms
80,900 KB |
testcase_04 | AC | 132 ms
80,788 KB |
testcase_05 | AC | 132 ms
79,744 KB |
testcase_06 | AC | 131 ms
80,272 KB |
testcase_07 | AC | 1,285 ms
104,616 KB |
testcase_08 | AC | 1,284 ms
105,628 KB |
testcase_09 | AC | 1,276 ms
104,356 KB |
testcase_10 | AC | 1,228 ms
104,484 KB |
testcase_11 | AC | 1,278 ms
104,368 KB |
testcase_12 | AC | 1,338 ms
104,104 KB |
testcase_13 | AC | 1,291 ms
104,612 KB |
testcase_14 | AC | 1,254 ms
105,000 KB |
testcase_15 | AC | 1,312 ms
104,612 KB |
testcase_16 | AC | 1,327 ms
104,100 KB |
testcase_17 | AC | 1,306 ms
105,260 KB |
testcase_18 | AC | 1,304 ms
104,488 KB |
testcase_19 | AC | 1,295 ms
104,616 KB |
testcase_20 | AC | 1,309 ms
103,848 KB |
testcase_21 | AC | 1,341 ms
104,492 KB |
testcase_22 | AC | 1,289 ms
104,372 KB |
testcase_23 | AC | 1,287 ms
104,104 KB |
testcase_24 | AC | 1,289 ms
103,972 KB |
testcase_25 | AC | 1,319 ms
104,108 KB |
testcase_26 | AC | 1,346 ms
104,748 KB |
testcase_27 | AC | 1,311 ms
105,000 KB |
testcase_28 | AC | 1,347 ms
104,876 KB |
testcase_29 | AC | 1,345 ms
106,408 KB |
testcase_30 | AC | 1,321 ms
103,856 KB |
testcase_31 | AC | 1,366 ms
106,148 KB |
testcase_32 | AC | 1,288 ms
105,132 KB |
testcase_33 | AC | 1,342 ms
104,616 KB |
testcase_34 | AC | 1,346 ms
105,008 KB |
testcase_35 | AC | 1,310 ms
104,244 KB |
testcase_36 | AC | 1,324 ms
105,264 KB |
testcase_37 | AC | 1,301 ms
105,004 KB |
testcase_38 | AC | 1,354 ms
104,996 KB |
testcase_39 | AC | 1,315 ms
105,120 KB |
testcase_40 | AC | 1,300 ms
105,640 KB |
testcase_41 | AC | 1,305 ms
104,232 KB |
testcase_42 | AC | 979 ms
103,332 KB |
testcase_43 | AC | 33 ms
52,480 KB |
testcase_44 | AC | 34 ms
52,480 KB |
ソースコード
import bisect class BIT: def __init__(self, n, func=int.__add__, one=0): self.n = n self.func = func self.one = one self.a = [0] * (self.n + 1) self.all_sum = 0 def update(self, i, x): i += 1 while i <= self.n: self.a[i] = self.func(self.a[i], x) i += i & (-i) self.all_sum += x def get(self, i): s = self.one while i != 0: s = self.func(s, self.a[i]) i -= i & (-i) return s def out_get(self, i): return self.all_sum - self.get(i) n = int(input()) y_list = list() point = list() for _ in range(n): x, y = map(int, input().split()) y_list.append(y) point.append((x, y)) y_list.sort() point.sort() def compress_index(y): idx = bisect.bisect_left(y_list, y) return idx mod = 998244353 one_bit = BIT(n) x_plus_y_bit = BIT(n) x_plus_y2_bit = BIT(n) x_minus_y_bit = BIT(n) x_minus_y2_bit = BIT(n) ans = 0 for x, y in point: y_idx = compress_index(y) one = one_bit.get(y_idx) x_plus_y = x_plus_y_bit.get(y_idx) x_plus_y2 = x_plus_y2_bit.get(y_idx) ans += (x + y) ** 2 * one - 2 * (x + y) * x_plus_y + x_plus_y2 ans %= mod one = one_bit.out_get(y_idx) x_minus_y = x_minus_y_bit.out_get(y_idx) x_minus_y2 = x_minus_y2_bit.out_get(y_idx) ans += (x - y) ** 2 * one - 2 * (x - y) * x_minus_y + x_minus_y2 ans %= mod one_bit.update(y_idx, 1) x_plus_y_bit.update(y_idx, (x + y) % mod) x_plus_y2_bit.update(y_idx, (x + y) ** 2 % mod) x_minus_y_bit.update(y_idx, (x - y) % mod) x_minus_y2_bit.update(y_idx, (x - y) ** 2 % mod) print(ans % mod)