Problem:


Score : 800 points

Problem Statement

There are N lines in the xy-plane. The i-th line is represented by A_ix+B_iy=C_i.
Any two lines among the N+2 lines, the above N lines plus the x-axis and y-axis, cross each other at exactly one point.

For each pair 1 \leq i < j \leq N, there is a car at the cross point of the i-th and j-th lines.
Even where three or more lines intersect at a point, a car is individually placed for each pair of lines.
That is, there will be k(k-1)/2 cars placed at the intersection of k lines.

Those cars are already very old, and can only be moved parallel to the x-axis or y-axis.

Takahashi will hold an exhibition of antique cars at a place on the xy-plane.
In order to avoid damaging the half-broken cars too much, he will select the place of the exhibition so that the total distance covered will be minimized when all the cars are moved to the place.
If such a place is not uniquely determined, among the places that satisfy the condition above, the place with the minimum x-coordinate will be selected.
If the place is still not uniquely determined, among the places that satisfy the two conditions above, the place with the minimum y-coordinate will be selected.

Find the place of the exhibition that will be selected.

Constraints

2 \leq N \leq 4 × 10^4

1 \leq |A_i|,|B_i| \leq 10^4(1 \leq i \leq N)

0 \leq |C_i| \leq 10^4(1 \leq i \leq N)

No two given lines are parallel.

All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N
A_1 B_1 C_1
:
A_N B_N C_N

Outputs

Print the x-coordinate and y-coordinate of the place of the exhibition that will be selected, in this order, with a space in between. The output will be judged as correct when the absolute or relative error is at most 10^{-9}.

Sample Input 1

3
1 1 1
2 -1 2
-1 2 2

Sample Output 1

1.000000000000000 1.000000000000000

There is a car at each place shown by a blue circle in the figure. The place to be selected is shown by a purple circle.

Sample Input 2

4
1 1 2
1 -1 0
3 -1 -2
1 -3 4

Sample Output 2

-1.000000000000000 -1.000000000000000

Sample Input 3

7
1 7 8
-2 4 9
3 -8 -5
9 2 -14
6 7 5
-8 -9 3
3 8 10

Sample Output 3

-1.722222222222222 1.325000000000000



Sample input:
3
1 1 1
2 -1 2
-1 2 2


Sample output:
1.000000000000000 1.000000000000000

Submission status: Accepted

Solution code:
class Bit:
    # 参考1: http://hos.ac/slides/20140319_bit.pdf
    # 参考2: https://atcoder.jp/contests/arc046/submissions/6264201
    # 検証: https://atcoder.jp/contests/arc046/submissions/7435621
    # values の 0 番目は使わない
    # len(values) を 2 冪 +1 にすることで二分探索の条件を減らす
    def __init__(self, a):
        if hasattr(a, "__iter__"):
            le = len(a)
            self.n = 1 << le.bit_length()  # le を超える最小の 2 冪
            self.values = values = [0] * (self.n + 1)
            values[1:le + 1] = a[:]
            for i in range(1, self.n):
                values[i + (i & -i)] += values[i]
        elif isinstance(a, int):
            self.n = 1 << a.bit_length()
            self.values = [0] * (self.n + 1)
        else:
            raise TypeError

    def add(self, i, val):
        n, values = self.n, self.values
        while i <= n:
            values[i] += val
            i += i & -i

    def sum(self, i):  # (0, i]
        values = self.values
        res = 0
        while i > 0:
            res += values[i]
            i -= i & -i
        return res

    def bisect_left(self, v):  # self.sum(i) が v 以上になる最小の i
        n, values = self.n, self.values
        if v > values[n]:
            return None
        i, step = 0, n >> 1
        while step:
            if values[i + step] < v:
                i += step
                v -= values[i]
            step >>= 1
        return i + 1

def inversion_number(arr):
    n = len(arr)
    arr = sorted(range(n), key=lambda x: arr[x])
    bit = Bit(n)
    res = n * (n-1) >> 1
    for val in arr:
        res -= bit.sum(val+1)
        bit.add(val+1, 1)
    return res

N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)]
A, B, C = zip(*ABC)
th = N*(N-1)//2 // 2 + 1
def solve(A, B, C):
    # y = (-Ax+C) / B
    if N < 100:
        ok = -1e10
        ng = 1e10
        n_iteration = 70
    else:
        ok = -1e4
        ng = 1e4
        n_iteration = 46
    A, B, C = zip(*sorted(zip(A, B, C), key=lambda x: -x[0]/x[1]))
    for _ in range(n_iteration):
        x = (ok+ng) * 0.5
        Y = [(-a*x+c)/b for a, b, c in zip(A, B, C)]
        inv_num = inversion_number(Y)
        if inv_num >= th:
            ok = x
        else:
            ng = x
    return ok
print(solve(A, B, C), solve(B, A, C))

Submission status: Accepted

Solution code:
import os
import sys

import numpy as np


def solve(inp):
    def bit_add(arr, n, i, x):
        while i <= n:
            arr[i] += x
            i += i & -i

    def bit_sum(arr, i):
        result = 0
        while i > 0:
            result += arr[i]
            i ^= i & -i
        return result

    n = int(inp[0])
    lim = (n * (n - 1) // 2 + 1) // 2
    aaa = inp[1::3]
    bbb = inp[2::3]
    ccc = inp[3::3]

    inclines_x = [(aaa[i] / bbb[i], i) for i in range(n)]
    inclines_y = [(bbb[i] / aaa[i], i) for i in range(n)]
    inclines_x.sort()
    inclines_y.sort()
    incline_rank_x = np.zeros(n, dtype=np.int64)
    incline_rank_y = np.zeros(n, dtype=np.int64)
    for k in range(n):
        incline_rank_x[inclines_x[k][1]] = n - k
        incline_rank_y[inclines_y[k][1]] = n - k

    def check_x(m):
        yyy = [((ccc[i] - aaa[i] * m) / bbb[i], i) for i in range(n)]
        yyy.sort()

        bit = np.zeros(n + 1, dtype=np.int64)
        intersection_left = 0
        for j in range(n):
            i = yyy[j][1]
            k = incline_rank_x[i]
            intersection_left += bit_sum(bit, k)
            bit_add(bit, n + 1, k, 1)

        return intersection_left >= lim

    def check_y(m):
        xxx = [((ccc[i] - bbb[i] * m) / aaa[i], i) for i in range(n)]
        xxx.sort()

        bit = np.zeros(n + 1, dtype=np.int64)
        intersection_left = 0
        for j in range(n):
            i = xxx[j][1]
            k = incline_rank_y[i]
            intersection_left += bit_sum(bit, k)
            bit_add(bit, n + 1, k, 1)

        return intersection_left >= lim

    l = -2.0 * 10 ** 8
    r = 2.0 * 10 ** 8
    while r - l > 1e-9 and abs((r - l) / l if l != 0 else r) > 1e-9:
        m = (l + r) / 2
        if check_x(m):
            r = m
        else:
            l = m
    x = l

    l = -2.0 * 10 ** 8
    r = 2.0 * 10 ** 8
    while r - l > 1e-9 and abs((r - l) / l if l != 0 else r) > 1e-9:
        m = (l + r) / 2
        if check_y(m):
            r = m
        else:
            l = m
    y = l

    return x, y


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(f8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(f8[:],)', cache=True)(solve)

inp = np.fromstring(sys.stdin.buffer.read(), dtype=np.float64, sep=' ')
x, y = solve(inp)
print(x, y)

Submission status: Accepted

Solution code:
import os
import sys

import numpy as np


def solve(inp):
    def bit_add(arr, n, i, x):
        while i <= n:
            arr[i] += x
            i += i & -i

    def bit_sum(arr, i):
        result = 0
        while i > 0:
            result += arr[i]
            i ^= i & -i
        return result

    n = int(inp[0])
    lim = (n * (n - 1) // 2 + 1) // 2
    aaa = inp[1::3]
    bbb = inp[2::3]
    ccc = inp[3::3]

    inclines_x = []
    inclines_y = []
    for i in range(n):
        inclines_x.append((aaa[i] / bbb[i], i))
        inclines_y.append((bbb[i] / aaa[i], i))
    inclines_x.sort()
    inclines_y.sort()
    incline_rank_x = np.zeros(n, dtype=np.int64)
    incline_rank_y = np.zeros(n, dtype=np.int64)
    for k in range(n):
        incline_rank_x[inclines_x[k][1]] = n - k
        incline_rank_y[inclines_y[k][1]] = n - k

    def check_x(m):
        yyy = []
        for i in range(n):
            yyy.append(((ccc[i] - aaa[i] * m) / bbb[i], i))
        yyy.sort()

        bit = np.zeros(n + 1, dtype=np.int64)
        intersection_left = 0
        for j in range(n):
            i = yyy[j][1]
            k = incline_rank_x[i]
            intersection_left += bit_sum(bit, k)
            bit_add(bit, n + 1, k, 1)

        return intersection_left >= lim

    def check_y(m):
        xxx = []
        for i in range(n):
            xxx.append(((ccc[i] - bbb[i] * m) / aaa[i], i))
        xxx.sort()

        bit = np.zeros(n + 1, dtype=np.int64)
        intersection_left = 0
        for j in range(n):
            i = xxx[j][1]
            k = incline_rank_y[i]
            intersection_left += bit_sum(bit, k)
            bit_add(bit, n + 1, k, 1)

        return intersection_left >= lim

    l = -2.0 * 10 ** 8
    r = 2.0 * 10 ** 8
    while r - l > 1e-9 and abs((r - l) / l if l != 0 else r) > 1e-9:
        m = (l + r) / 2
        if check_x(m):
            r = m
        else:
            l = m
    x = l

    l = -2.0 * 10 ** 8
    r = 2.0 * 10 ** 8
    while r - l > 1e-9 and abs((r - l) / l if l != 0 else r) > 1e-9:
        m = (l + r) / 2
        if check_y(m):
            r = m
        else:
            l = m
    y = l

    return x, y


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(f8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(f8[:],)', cache=True)(solve)

inp = np.fromstring(sys.stdin.buffer.read(), dtype=np.float64, sep=' ')
try:
    x, y = solve(inp)
    print(x, y)
except ZeroDivisionError:
    print('WA')
    exit()

Submission status: Accepted

Solution code:
class BIT():
    def __init__(self,n):
        self.BIT=[0]*(n+1)
        self.num=n

    def query(self,idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx&(-idx)
        return res_sum

    #Ai += x O(logN)
    def update(self,idx,x):
        while idx <= self.num:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return

def comp(L):
    S=list(set(L))
    S.sort()
    return {i:e for e,i in enumerate(S)}

import sys,random

input=sys.stdin.readline

N=int(input())
A=[0]*N;B=[0]*N;C=[0]*N
for i in range(N):
    A[i],B[i],C[i]=map(int,input().split())

line=[(A[i]/B[i],i) for i in range(N)]
line.sort()
line=[line[i][1] for i in range(N)]

line2=[(B[i]/A[i],i) for i in range(N)]
line2.sort()
line2=[line2[i][1] for i in range(N)]

def cond(n):
    tempC=[C[i]-n*A[i] for i in range(N)]
    data=[tempC[i]/B[i] for i in range(N)]
    data=comp(data)
    bit=BIT(len(data))
    res=0
    for i in range(N):
        id2=data[tempC[line[i]]/B[line[i]]]
        res+=i-bit.query(id2)
        bit.update(id2+1,1)
    num=N*(N-1)//2
    return res>=(num+1)//2

def cond2(n):
    tempC=[C[i]-n*B[i] for i in range(N)]
    data=[tempC[i]/A[i] for i in range(N)]
    data=comp(data)
    bit=BIT(len(data))
    res=0
    for i in range(N):
        id2=data[tempC[line2[i]]/A[line2[i]]]
        res+=i-bit.query(id2)
        bit.update(id2+1,1)
    num=N*(N-1)//2
    return res>=(num+1)//2

start=-2*10**8
end=2*10**8
count=0
while end-start>10**-9:
    count+=1
    test=(end+start)/2
    if cond(test):
        end=test
    else:
        start=test
    if (end-start)*10**9<min(abs(start),abs(end)):
        break

start2=-2*10**8
end2=2*10**8
while end2-start2>10**-9:
    test=(end2+start2)/2
    count+=1
    if cond2(test):
        end2=test
    else:
        start2=test
    if (end2-start2)*10**9<min(abs(start2),abs(end2)):
        break

print(end,end2)
#print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
EPS = 1e-9
# ----------------------------------------------------------- #

class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):  # 1-index
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):  # 1-index
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    """
    # 使用例
    bit = BinaryIndexedTree(10)     # 要素数を与えてインスタンス化
    bit.add(2, 10)    # a2に10を加える
    bit.add(3, -6)    # a3に-6を加える
    print(bit.sum(6)) # a1～a6の合計を返す
    print(bit.sum(6) - bit.sum(3))  # a4～a6の合計を返す
    """

def compress(A):
    dic = {element: i for i, element in enumerate(sorted(set(A)), start=1)}
    return [dic[a] for a in A]

def meguru_bisect(ng, ok, check):
    """
    初期値のng,okを受け取り, check=>Trueを満たす最大値(最小値)を返す
    条件を満たす最大値を求める場合、初期値は(ng:上限の外, ok:下限の外)   例) 10**9+1, -1
    条件を満たす最小値を求める場合、初期値は(ng:下限の外, ok:上限の外)   例) -1, 10**9+1
    上限の外や下限の外が返ってくる場合は条件を満たす値が範囲内になかったことを示すので、例外処理が必要
    """
    # while abs(ok - ng) > 1:
    for _ in range(80):
        if abs(ok - ng) < EPS:
            break
        # mid = (ok + ng) // 2
        mid = (ok + ng) / 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok

def check_x(num):
    bit = BinaryIndexedTree(n)
    inversion_num = 0
    X = compress([(c-b*num)/a for a, b, c in X_ABC])
    for i, x in enumerate(X, start=1):
        bit.add(x, 1)
        inversion_num += i - bit.sum(x)
    return inversion_num >= m

def check_y(num):
    bit = BinaryIndexedTree(n)
    inversion_num = 0
    Y = compress([(c-a*num)/b for a, b, c in Y_ABC])
    for i, y in enumerate(Y, start=1):
        bit.add(y, 1)
        inversion_num += i - bit.sum(y)
    return inversion_num >= m

n = I()
ABC = TIR(n)
m = (n*(n-1)//2+1)//2
X_ABC = sorted(ABC, key=lambda abc: abc[1]/abc[0])  # 傾きb/aの昇順
Y_ABC = sorted(ABC, key=lambda abc: abc[0]/abc[1])  # 傾きa/bの昇順
mid_x = meguru_bisect(-10**9, 10**9, check_x)
mid_y = meguru_bisect(-10**9, 10**9, check_y)

print(mid_y, mid_x)  # ????

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

class BIT:
    #1-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.p = 2**(n.bit_length() - 1)
        self.dep = n.bit_length()
    def get(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
    
    def bl(self, v):
        if v <= 0:
            return -1
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.tree[s+k] < v:
                s += k
                v -= self.tree[s+k]
            k //= 2
        return s + 1
    
    def reset(self):
        self.tree = [0]*(self.size+1)

N = int(readline())
INF = 2e8 + 10
EPS = 1e-9

Points = [tuple(map(int, readline().split())) for _ in range(N)]
Points.sort(key = lambda x: -x[0]/x[1])
XA = [-a/b for a, b, _ in Points]
XB = [c/b for _, b, c in Points]
Points.sort(key = lambda x: -x[1]/x[0])
YA = [-b/a for a, b, _ in Points]
YB = [c/a for a, _, c in Points]
con = -(-N*(N-1)//4)
T = BIT(N)

ng = -INF
ok = INF
nf = con
of = con


while abs(ok-ng)/max(1, min(abs(ok), abs(ng))) > EPS:
    med = (ok*nf+ng*of)/(of+nf)
    T.reset()
    res = 0
    for idx in sorted(range(N), key = lambda x: XA[x]*med + XB[x]):
        res += T.get(idx+1)
        T.add(idx+1, 1)
    if res >= con:
        ok = med
        of = ((res - con)*2 + 1) ** 0.3
    else:
        ng = med
        nf = ((con - res)*2) ** 0.3

X = ok

ng = -INF
ok = INF
nf = con
of = con

cnt = 1
while abs(ok-ng)/max(1, min(abs(ok), abs(ng))) > EPS:
    cnt += 1
    med = (ok*nf+ng*of)/(of+nf)
    T.reset()
    res = 0
    for idx in sorted(range(N), key = lambda x: YA[x]*med + YB[x]):
        res += T.get(idx+1)
        T.add(idx+1, 1)
    if res >= con:
        ok = med
        of = ((res - con)*2 + 1) ** 0.3
    else:
        ng = med
        nf = ((con - res)*2) ** 0.3

Y = ok

print(X, Y)

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(min(abs(l), abs(r)), 1) > 0.000000002:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.3
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.3
    return (l+r) / 2

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.2
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.2
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.3
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.3
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.4
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.4
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.5
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.5
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.6
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.6
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.8
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.8
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r = -1<<28, 1<<28
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l+r)/2
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
        else:
            r = m
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = [b for a, b in sorted([(s*m+t, i) for i, (s, t) in enumerate(Z)])]
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = [b for a, b in sorted([(s*m+t, i) for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Accepted

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    f = 1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l+r) / 2 if f else (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))