Submission #6697626


Source Code Expand

Copy
import sys
from operator import itemgetter

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()

co = []
for i in range(n):
    co.append(na())

co.sort(key=itemgetter(1))
for i in range(n):
    co[i][1] = i

print(co)
ft = [0] * (n + 5)

co.sort(key=itemgetter(0), reverse=True)

ups = [0] * n
downs = [0] * n

def addfenwick(ft, i, v):
    if v == 0 or i < 0: return
    i += 1
    while i < len(ft):
        ft[i] += v
        i += i&-i

def sumfenwick(ft, i):
    s = 0
    i += 1
    while i > 0:
        s += ft[i]
        i -= i&-i
    return s

for i in range(n):
    c = co[i]
    downs[n-1-i] = sumfenwick(ft, c[1])
    ups[n-1-i] = i - downs[n-1-i]
    addfenwick(ft, c[1], 1)

ft = [0] * (n+5)
co = co[::-1]

ans = 0
mod = 998244353
for i in range(n):
    c = co[i]
    d = sumfenwick(ft, c[1])
    u = i - d

    # print(d, u, ups[i], downs[i])
    ans += (pow(2, d, mod)-1) * (pow(2, ups[i], mod)-1) * pow(2, u+downs[i], mod)
    ans += (pow(2, u, mod)-1) * (pow(2, downs[i], mod)-1) * pow(2, d+ups[i], mod)
    ans -= (pow(2, d, mod)-1) * (pow(2, ups[i], mod)-1) * (pow(2, downs[i], mod)-1) * (pow(2, u, mod)-1)
    ans += pow(2, n-1, mod)
    addfenwick(ft, c[1], 1)

ans %= mod
if ans < 0:
    ans += mod
print(ans)

Submission Info

Submission Time
Task F - Enclosed Points
User uwi
Language PyPy3 (2.4.0)
Score 0
Code Size 1423 Byte
Status WA
Exec Time 2110 ms
Memory 159136 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
WA × 3
WA × 14
TLE × 12
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt WA 164 ms 38384 KB
02.txt WA 164 ms 38256 KB
03.txt WA 166 ms 38256 KB
04.txt WA 164 ms 38256 KB
05.txt WA 165 ms 38256 KB
06.txt WA 162 ms 38256 KB
07.txt WA 169 ms 38256 KB
08.txt WA 164 ms 38256 KB
09.txt WA 161 ms 38256 KB
10.txt WA 161 ms 38256 KB
11.txt TLE 2109 ms 159136 KB
12.txt TLE 2110 ms 157600 KB
13.txt TLE 2110 ms 157216 KB
14.txt TLE 2110 ms 155680 KB
15.txt TLE 2109 ms 156904 KB
16.txt TLE 2110 ms 156832 KB
17.txt TLE 2110 ms 157216 KB
18.txt TLE 2110 ms 156832 KB
19.txt TLE 2110 ms 156832 KB
20.txt TLE 2110 ms 159084 KB
21.txt TLE 2110 ms 157216 KB
22.txt TLE 2110 ms 157216 KB
23.txt WA 160 ms 38256 KB
s1.txt WA 161 ms 38256 KB
s2.txt WA 162 ms 38256 KB
s3.txt WA 162 ms 38384 KB