結果

問題 No.1649 Manhattan Square
ユーザー 已经死了已经死了
提出日時 2024-06-27 19:05:42
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 5,445 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 164,668 KB
最終ジャッジ日時 2024-06-27 19:06:32
合計ジャッジ時間 50,376 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
92,528 KB
testcase_01 AC 157 ms
92,300 KB
testcase_02 AC 264 ms
94,976 KB
testcase_03 AC 242 ms
94,964 KB
testcase_04 AC 264 ms
95,680 KB
testcase_05 AC 240 ms
94,932 KB
testcase_06 AC 250 ms
95,740 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 1,946 ms
161,712 KB
testcase_43 AC 159 ms
92,324 KB
testcase_44 AC 156 ms
92,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import os,sys,random,threading
#sys.exit() 退
from random import randint,choice,shuffle
#randint(a,b)[a,b]
#choice(seq)seq,,seq
#shuffle(x)x
from copy import deepcopy
from io import BytesIO,IOBase
from types import GeneratorType
from functools import lru_cache,reduce
#reduce(op,)
from bisect import bisect_left,bisect_right
#bisect_left(x) x
#bisect_right(x) x
from collections import Counter,defaultdict,deque
from itertools import accumulate,combinations,permutations
#accumulate(a)alist[0]
#combinations(a,k)ak
#permutations(a,k)ak
from heapq import heapify,heappop,heappush
#heapify
from typing import Generic,Iterable,Iterator,TypeVar,Union,List
from string import ascii_lowercase,ascii_uppercase,digits
#
from math import ceil,floor,sqrt,pi,factorial,gcd,log,log10,log2,inf
#ceilfloor sqrt factorial
from decimal import Decimal,getcontext
#Decimal(s) Decimal,使
#getcontext().prec=100
from sys import stdin, stdout, setrecursionlimit
input = lambda: sys.stdin.readline().rstrip("\r\n")
MI = lambda :map(int,input().split())
li = lambda :list(MI())
ii = lambda :int(input())
mod = int(1e9 + 7) #998244353
inf = int(1e20)
py = lambda :print("YES")
pn = lambda :print("NO")
DIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] #
DIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),(-1, 1)] # →↘↓↙←↖↑↗
import os,sys,random,threading
#sys.exit() 退
#sys.setrecursionlimit(10**6) #
from random import randint,choice,shuffle
#randint(a,b)[a,b]
#choice(seq)seq,,seq
#shuffle(x)x
from copy import deepcopy
from io import BytesIO,IOBase
from types import GeneratorType
from functools import lru_cache,reduce
#reduce(op,)
from bisect import bisect_left,bisect_right
#bisect_left(x) x
#bisect_right(x) x
from collections import Counter,defaultdict,deque
from itertools import accumulate,combinations,permutations
#accumulate(a)alist[0]
#combinations(a,k)ak
#permutations(a,k)ak
from heapq import heapify,heappop,heappush
#heapify
from typing import Generic,Iterable,Iterator,TypeVar,Union,List
from string import ascii_lowercase,ascii_uppercase,digits
#
from math import ceil,floor,sqrt,pi,factorial,gcd,log,log10,log2,inf
#ceilfloor sqrt factorial
from decimal import Decimal,getcontext
#Decimal(s) Decimal,使
#getcontext().prec=100
from sys import stdin, stdout, setrecursionlimit
input = lambda: sys.stdin.readline().rstrip("\r\n")
MI = lambda :map(int,input().split())
li = lambda :list(MI())
ii = lambda :int(input())
mod = int(1e9 + 7) #998244353
inf = 1<<60
py = lambda :print("YES")
pn = lambda :print("NO")
DIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] #
DIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),(-1, 1)] # →↘↓↙←↖↑↗
class BIT:
""","""
__slots__ = "size", "bit", "tree"
def __init__(self, n: int):
self.size = n
self.bit = n.bit_length()
self.tree = [0]*(n+1)
def add(self, index: int, delta: int) -> None:
# index 0
while index <= self.size:
self.tree[index]+=delta
index += index & -index
def _query(self, index: int) -> int:
res = 0
while index > 0:
res += self.tree[index]
index -= index & -index
return res
def query(self, left: int, right: int) -> int:
return self._query(right) - self._query(left - 1)
def bisectLeft(self, k: int) -> int:
"""kpos
1 <= pos <= self.size + 1
"""
curSum, pos = 0, 0
for i in range(self.bit, -1, -1):
nextPos = pos + (1 << i)
if nextPos <= self.size and curSum + self.tree[nextPos] < k:
pos = nextPos
curSum += self.tree[pos]
return pos + 1
mod=998244353
n=ii()
a=[li() for _ in range(n)]
a.sort()
d=[y for x,y in a]
d.sort()
d={x:i+1 for i,x in enumerate(d)}
m=len(d)+5
bit=BIT(m) #
b1=BIT(m) #x+y
b2=BIT(m) #x-y
b3=BIT(m) #(x+y)^2
b4=BIT(m) #(x-y)^2
res=0
cnt=0
for x,y in a:
idx=d[y]
sc=bit._query(idx)
bc=cnt-sc
res+=(x+y)*(x+y)*sc+b3._query(d[y])-2*(x+y)*b1._query(d[y])
res+=(x-y)*(x-y)*bc+b4.query(idx+1,m-1)-2*(x-y)*b2.query(idx+1,m-1)
res%=mod
bit.add(idx,1)
b1.add(idx,x+y)
b2.add(idx,x-y)
b3.add(idx,(x+y)**2)
b4.add(idx,(x-y)**2)
cnt+=1
print(res)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0