結果

問題 No.1649 Manhattan Square
ユーザー MitarushiMitarushi
提出日時 2021-07-28 21:53:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,601 ms / 3,000 ms
コード長 1,648 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 82,980 KB
実行使用メモリ 136,852 KB
最終ジャッジ日時 2024-04-14 16:00:54
合計ジャッジ時間 59,201 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,500 KB
testcase_01 AC 38 ms
53,760 KB
testcase_02 AC 137 ms
78,520 KB
testcase_03 AC 119 ms
77,772 KB
testcase_04 AC 126 ms
78,040 KB
testcase_05 AC 122 ms
77,768 KB
testcase_06 AC 130 ms
77,732 KB
testcase_07 AC 1,563 ms
123,532 KB
testcase_08 AC 1,563 ms
136,676 KB
testcase_09 AC 1,589 ms
136,820 KB
testcase_10 AC 1,547 ms
136,852 KB
testcase_11 AC 1,531 ms
136,756 KB
testcase_12 AC 1,507 ms
111,140 KB
testcase_13 AC 1,552 ms
118,044 KB
testcase_14 AC 1,526 ms
114,340 KB
testcase_15 AC 1,541 ms
115,112 KB
testcase_16 AC 1,495 ms
108,704 KB
testcase_17 AC 1,513 ms
111,264 KB
testcase_18 AC 1,516 ms
107,812 KB
testcase_19 AC 1,535 ms
114,088 KB
testcase_20 AC 1,525 ms
112,040 KB
testcase_21 AC 1,541 ms
117,924 KB
testcase_22 AC 1,551 ms
126,364 KB
testcase_23 AC 1,541 ms
126,140 KB
testcase_24 AC 1,549 ms
126,208 KB
testcase_25 AC 1,551 ms
127,408 KB
testcase_26 AC 1,561 ms
124,344 KB
testcase_27 AC 1,554 ms
126,292 KB
testcase_28 AC 1,572 ms
126,104 KB
testcase_29 AC 1,553 ms
126,332 KB
testcase_30 AC 1,568 ms
126,028 KB
testcase_31 AC 1,556 ms
126,056 KB
testcase_32 AC 1,545 ms
126,040 KB
testcase_33 AC 1,559 ms
125,820 KB
testcase_34 AC 1,601 ms
125,840 KB
testcase_35 AC 1,556 ms
126,016 KB
testcase_36 AC 1,565 ms
126,600 KB
testcase_37 AC 1,543 ms
126,280 KB
testcase_38 AC 1,552 ms
124,000 KB
testcase_39 AC 1,565 ms
126,184 KB
testcase_40 AC 1,564 ms
126,188 KB
testcase_41 AC 1,571 ms
122,868 KB
testcase_42 AC 1,213 ms
126,160 KB
testcase_43 AC 39 ms
52,836 KB
testcase_44 AC 39 ms
54,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect


class BIT:
    def __init__(self, n, one=0):
        self.n = n
        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] += x
            i += i & (-i)

        self.all_sum += x

    def get(self, i):
        s = self.one
        while i != 0:
            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()

compress_idx = {i: idx for idx, i in enumerate(y_list)}


def compress_index(y):
    return compress_idx[y]


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)
0