結果

問題 No.1649 Manhattan Square
ユーザー mkawa2mkawa2
提出日時 2024-01-06 12:17:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,611 ms / 3,000 ms
コード長 2,226 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 175,540 KB
最終ジャッジ日時 2024-01-06 12:18:04
合計ジャッジ時間 59,444 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 98 ms
77,460 KB
testcase_03 AC 96 ms
77,460 KB
testcase_04 AC 97 ms
77,460 KB
testcase_05 AC 95 ms
77,460 KB
testcase_06 AC 99 ms
77,456 KB
testcase_07 AC 1,577 ms
175,348 KB
testcase_08 AC 1,560 ms
174,540 KB
testcase_09 AC 1,562 ms
175,136 KB
testcase_10 AC 1,565 ms
174,940 KB
testcase_11 AC 1,553 ms
175,152 KB
testcase_12 AC 1,364 ms
112,088 KB
testcase_13 AC 1,479 ms
128,032 KB
testcase_14 AC 1,418 ms
118,616 KB
testcase_15 AC 1,443 ms
121,304 KB
testcase_16 AC 1,345 ms
107,040 KB
testcase_17 AC 1,345 ms
114,904 KB
testcase_18 AC 1,312 ms
108,760 KB
testcase_19 AC 1,453 ms
121,780 KB
testcase_20 AC 1,379 ms
111,664 KB
testcase_21 AC 1,499 ms
128,728 KB
testcase_22 AC 1,589 ms
174,716 KB
testcase_23 AC 1,596 ms
174,776 KB
testcase_24 AC 1,560 ms
174,952 KB
testcase_25 AC 1,560 ms
174,904 KB
testcase_26 AC 1,583 ms
175,408 KB
testcase_27 AC 1,611 ms
174,648 KB
testcase_28 AC 1,599 ms
175,300 KB
testcase_29 AC 1,583 ms
175,048 KB
testcase_30 AC 1,563 ms
174,764 KB
testcase_31 AC 1,567 ms
174,504 KB
testcase_32 AC 1,561 ms
174,896 KB
testcase_33 AC 1,553 ms
174,604 KB
testcase_34 AC 1,580 ms
174,792 KB
testcase_35 AC 1,567 ms
174,332 KB
testcase_36 AC 1,603 ms
175,212 KB
testcase_37 AC 1,549 ms
175,540 KB
testcase_38 AC 1,551 ms
174,652 KB
testcase_39 AC 1,548 ms
174,668 KB
testcase_40 AC 1,566 ms
174,556 KB
testcase_41 AC 1,548 ms
174,760 KB
testcase_42 AC 1,418 ms
164,456 KB
testcase_43 AC 37 ms
53,460 KB
testcase_44 AC 37 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

class BitSum:
    def __init__(self, n):
        self._n = n+1
        self._table = [0]*self._n

    def add(self, i, x):
        if x == 0: return
        i += 1
        while i < self._n:
            self._table[i] += x
            self._table[i] %= md
            i += i & -i

    def sum(self, r):
        res = 0
        while r > 0:
            res += self._table[r]
            res %= md
            r -= r & -r
        return res

n = II()
xy = LLI(n)
xy.sort()

dec = sorted(set(y for x, y in xy))
enc = {a: i for i, a in enumerate(dec)}

s = t = s2 = t2 = u = 0
cbit = BitSum(len(dec))
xbit = BitSum(len(dec))
ybit = BitSum(len(dec))
xybit = BitSum(len(dec))
ans = 0
for p, (x, y) in enumerate(xy):
    # (x-X+y-Y)2
    # x2+X2+y2+Y2-2xX+2xy-2xY-2yX+2XY-2yY
    # x2+y2+X2+Y2-2(xX+yY)+2(xy-xY-yX+XY) (Y<y)
    # x2+y2+X2+Y2-2(xX+yY)-2(xy-xY-yX+XY) (Y>=y)
    ans += p*(x*x%md+y*y%md)%md+s2+t2-2*(x*s%md+y*t%md)
    i = enc[y]
    c = cbit.sum(i)
    xb = xbit.sum(i)
    yb = ybit.sum(i)
    xyb = xybit.sum(i)
    # ans += 2*(c*x*y%md-x*yb%md-y*xb%md+xyb)-2*((p-c)*x*y%md-x*(t-yb)%md-y*(s-xb)%md+(u-xyb))
    ans += 2*((2*c-p)*x*y%md-x*(2*yb-t)%md-y*(2*xb-s)%md+2*xyb-u)
    ans %= md

    x2 = x*x%md
    y2 = y*y%md
    xy = x*y%md
    s += x
    s2 += x2
    t += y
    t2 += y2
    u += xy
    s %= md
    s2 %= md
    t %= md
    t2 %= md
    u %= md
    cbit.add(i, 1)
    xbit.add(i, x)
    ybit.add(i, y)
    xybit.add(i, xy)

print(ans)
0