結果

問題 No.1649 Manhattan Square
ユーザー mkawa2mkawa2
提出日時 2024-01-06 12:17:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,606 ms / 3,000 ms
コード長 2,226 bytes
コンパイル時間 604 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 176,068 KB
最終ジャッジ日時 2024-09-27 19:18:06
合計ジャッジ時間 55,065 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,156 KB
testcase_01 AC 36 ms
53,700 KB
testcase_02 AC 93 ms
78,040 KB
testcase_03 AC 93 ms
77,804 KB
testcase_04 AC 98 ms
77,720 KB
testcase_05 AC 94 ms
77,868 KB
testcase_06 AC 95 ms
78,020 KB
testcase_07 AC 1,535 ms
175,560 KB
testcase_08 AC 1,594 ms
175,048 KB
testcase_09 AC 1,504 ms
175,600 KB
testcase_10 AC 1,493 ms
175,624 KB
testcase_11 AC 1,606 ms
175,496 KB
testcase_12 AC 1,217 ms
112,664 KB
testcase_13 AC 1,361 ms
128,448 KB
testcase_14 AC 1,415 ms
119,140 KB
testcase_15 AC 1,471 ms
122,572 KB
testcase_16 AC 1,287 ms
107,220 KB
testcase_17 AC 1,314 ms
115,464 KB
testcase_18 AC 1,236 ms
109,112 KB
testcase_19 AC 1,366 ms
122,452 KB
testcase_20 AC 1,243 ms
112,388 KB
testcase_21 AC 1,357 ms
129,312 KB
testcase_22 AC 1,462 ms
175,352 KB
testcase_23 AC 1,477 ms
175,592 KB
testcase_24 AC 1,520 ms
175,428 KB
testcase_25 AC 1,501 ms
175,476 KB
testcase_26 AC 1,478 ms
175,804 KB
testcase_27 AC 1,491 ms
175,072 KB
testcase_28 AC 1,427 ms
175,972 KB
testcase_29 AC 1,462 ms
175,888 KB
testcase_30 AC 1,408 ms
175,136 KB
testcase_31 AC 1,414 ms
174,908 KB
testcase_32 AC 1,403 ms
175,524 KB
testcase_33 AC 1,405 ms
175,304 KB
testcase_34 AC 1,399 ms
175,264 KB
testcase_35 AC 1,405 ms
174,652 KB
testcase_36 AC 1,424 ms
175,704 KB
testcase_37 AC 1,433 ms
176,068 KB
testcase_38 AC 1,434 ms
175,024 KB
testcase_39 AC 1,395 ms
175,188 KB
testcase_40 AC 1,430 ms
175,104 KB
testcase_41 AC 1,405 ms
175,448 KB
testcase_42 AC 1,249 ms
164,756 KB
testcase_43 AC 36 ms
53,436 KB
testcase_44 AC 36 ms
52,832 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