結果

問題 No.1649 Manhattan Square
ユーザー MitarushiMitarushi
提出日時 2021-07-28 21:48:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,661 ms / 3,000 ms
コード長 1,696 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 106,536 KB
最終ジャッジ日時 2024-04-14 15:57:06
合計ジャッジ時間 60,463 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,200 KB
testcase_01 AC 38 ms
53,156 KB
testcase_02 AC 149 ms
80,012 KB
testcase_03 AC 155 ms
80,380 KB
testcase_04 AC 160 ms
81,232 KB
testcase_05 AC 152 ms
80,128 KB
testcase_06 AC 155 ms
80,276 KB
testcase_07 AC 1,572 ms
105,000 KB
testcase_08 AC 1,570 ms
105,640 KB
testcase_09 AC 1,575 ms
104,484 KB
testcase_10 AC 1,567 ms
104,744 KB
testcase_11 AC 1,558 ms
104,868 KB
testcase_12 AC 1,586 ms
104,360 KB
testcase_13 AC 1,582 ms
104,728 KB
testcase_14 AC 1,571 ms
104,744 KB
testcase_15 AC 1,605 ms
105,000 KB
testcase_16 AC 1,589 ms
104,488 KB
testcase_17 AC 1,582 ms
104,612 KB
testcase_18 AC 1,580 ms
104,872 KB
testcase_19 AC 1,594 ms
104,620 KB
testcase_20 AC 1,582 ms
104,004 KB
testcase_21 AC 1,590 ms
104,364 KB
testcase_22 AC 1,601 ms
104,648 KB
testcase_23 AC 1,619 ms
104,104 KB
testcase_24 AC 1,613 ms
104,092 KB
testcase_25 AC 1,596 ms
103,980 KB
testcase_26 AC 1,661 ms
105,000 KB
testcase_27 AC 1,597 ms
104,232 KB
testcase_28 AC 1,596 ms
105,004 KB
testcase_29 AC 1,595 ms
106,536 KB
testcase_30 AC 1,591 ms
104,236 KB
testcase_31 AC 1,596 ms
106,304 KB
testcase_32 AC 1,593 ms
104,744 KB
testcase_33 AC 1,571 ms
104,356 KB
testcase_34 AC 1,592 ms
104,872 KB
testcase_35 AC 1,571 ms
104,232 KB
testcase_36 AC 1,582 ms
105,512 KB
testcase_37 AC 1,584 ms
105,260 KB
testcase_38 AC 1,581 ms
104,612 KB
testcase_39 AC 1,568 ms
105,000 KB
testcase_40 AC 1,567 ms
105,892 KB
testcase_41 AC 1,592 ms
104,492 KB
testcase_42 AC 1,196 ms
103,340 KB
testcase_43 AC 37 ms
52,404 KB
testcase_44 AC 38 ms
53,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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