Submission #6697800


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 1425 Byte
Status TLE
Exec Time 2109 ms
Memory 103188 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 18
TLE × 8
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 AC 163 ms 38384 KB
02.txt AC 163 ms 38256 KB
03.txt AC 167 ms 38256 KB
04.txt AC 165 ms 38256 KB
05.txt AC 166 ms 38384 KB
06.txt AC 164 ms 38384 KB
07.txt AC 166 ms 38256 KB
08.txt AC 161 ms 38256 KB
09.txt AC 161 ms 38256 KB
10.txt AC 165 ms 38256 KB
11.txt TLE 2109 ms 99932 KB
12.txt TLE 2109 ms 99292 KB
13.txt TLE 2109 ms 102800 KB
14.txt TLE 2109 ms 98396 KB
15.txt TLE 2109 ms 100828 KB
16.txt TLE 2109 ms 100828 KB
17.txt TLE 2108 ms 103188 KB
18.txt TLE 2109 ms 100828 KB
19.txt AC 1640 ms 100000 KB
20.txt AC 1600 ms 99432 KB
21.txt AC 1914 ms 100572 KB
22.txt AC 1972 ms 100572 KB
23.txt AC 165 ms 38256 KB
s1.txt AC 168 ms 38256 KB
s2.txt AC 163 ms 38256 KB
s3.txt AC 167 ms 38424 KB