結果

問題 No.2652 [Cherry 6th Tune N] Δρονε χιρχλινγ
ユーザー StanMarshStanMarsh
提出日時 2024-02-23 22:59:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 670 ms / 2,000 ms
コード長 6,762 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 154,108 KB
最終ジャッジ日時 2024-02-23 23:00:02
合計ジャッジ時間 47,703 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
89,468 KB
testcase_01 AC 461 ms
92,924 KB
testcase_02 AC 462 ms
92,924 KB
testcase_03 AC 495 ms
94,076 KB
testcase_04 AC 586 ms
114,172 KB
testcase_05 AC 559 ms
114,172 KB
testcase_06 AC 544 ms
114,940 KB
testcase_07 AC 610 ms
116,400 KB
testcase_08 AC 635 ms
116,700 KB
testcase_09 AC 620 ms
120,828 KB
testcase_10 AC 607 ms
119,748 KB
testcase_11 AC 612 ms
119,804 KB
testcase_12 AC 633 ms
116,956 KB
testcase_13 AC 637 ms
126,460 KB
testcase_14 AC 646 ms
138,236 KB
testcase_15 AC 662 ms
129,280 KB
testcase_16 AC 664 ms
116,772 KB
testcase_17 AC 663 ms
126,620 KB
testcase_18 AC 637 ms
122,976 KB
testcase_19 AC 628 ms
122,364 KB
testcase_20 AC 658 ms
137,724 KB
testcase_21 AC 645 ms
137,724 KB
testcase_22 AC 615 ms
137,724 KB
testcase_23 AC 610 ms
137,724 KB
testcase_24 AC 635 ms
137,724 KB
testcase_25 AC 612 ms
137,724 KB
testcase_26 AC 640 ms
137,724 KB
testcase_27 AC 649 ms
137,724 KB
testcase_28 AC 645 ms
137,724 KB
testcase_29 AC 670 ms
137,724 KB
testcase_30 AC 605 ms
137,596 KB
testcase_31 AC 601 ms
137,596 KB
testcase_32 AC 630 ms
137,596 KB
testcase_33 AC 603 ms
137,596 KB
testcase_34 AC 612 ms
137,596 KB
testcase_35 AC 637 ms
137,724 KB
testcase_36 AC 639 ms
137,596 KB
testcase_37 AC 616 ms
137,724 KB
testcase_38 AC 608 ms
137,596 KB
testcase_39 AC 641 ms
137,724 KB
testcase_40 AC 455 ms
154,108 KB
testcase_41 AC 462 ms
138,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from random import getrandbits, randrange
from string import ascii_lowercase, ascii_uppercase
import sys
from math import ceil, floor, sqrt, pi, factorial, gcd, log, log10, log2, inf, cos, sin
from copy import deepcopy, copy
from collections import Counter, deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import (
    accumulate,
    chain,
    product,
    combinations,
    combinations_with_replacement,
    permutations,
)
from bisect import bisect, bisect_left, bisect_right
from functools import lru_cache, reduce
from decimal import Decimal, getcontext
from typing import List, Tuple, Optional


inf = float("inf")


class Inf:
    def __init__(self, value):
        self.value = value

    def __lt__(self, other):
        return False

    def __le__(self, other):
        if isinstance(other, Inf):
            return True
        return False

    def __gt__(self, other):
        if isinstance(other, Inf):
            return False
        return True

    def __ge__(self, other):
        return True

    def __eq__(self, other):
        return isinstance(other, Inf) and self.value == other.value

    def __repr__(self):
        return f"{self.value}"

    def __add__(self, other):
        return Inf(self.value) if isinstance(other, Inf) else self

    def __sub__(self, other):
        return Inf(self.value) if isinstance(other, Inf) else self

    def __mul__(self, other):
        return Inf(self.value) if isinstance(other, Inf) else self


def ceil_div(a, b):
    return (a + b - 1) // b


def isqrt(num):
    res = int(sqrt(num))
    while res * res > num:
        res -= 1
    while (res + 1) * (res + 1) <= num:
        res += 1
    return res


def int1(s):
    return int(s) - 1


from types import GeneratorType


def bootstrap(f, stack=[]):
    def wrapped(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to

    return wrapped


import sys
import os

input = lambda: sys.stdin.readline().rstrip("\r\n")

print = lambda *args, end="\n", sep=" ": sys.stdout.write(
    sep.join(map(str, args)) + end
)


def II():
    return int(input())


def MII(base=0):
    return map(lambda s: int(s) - base, input().split())


def LII(base=0):
    return list(MII(base))


def NA():
    n = II()
    a = LII()
    return n, a


def read_graph(n, m, base=0, directed=False, return_edges=False):

    g = [[] for _ in range(n)]
    edges = []
    for _ in range(m):
        a, b = MII(base)
        if return_edges:
            edges.append((a, b))
        g[a].append(b)
        if not directed:
            g[b].append(a)
    if return_edges:
        return g, edges
    return g


def read_graph_with_weight(n, m, base=0, directed=False, return_edges=False):

    g = [[] for _ in range(n)]
    edges = []
    for _ in range(m):
        a, b, w = MII()
        a, b = a - base, b - base
        if return_edges:
            edges.append((a, b, w))
        g[a].append((b, w))
        if not directed:
            g[b].append((a, w))
    if return_edges:
        return g, edges
    return g


def read_edges_from_ps():
    ps = LII(1)
    edges = []
    for i, p in enumerate(ps, 1):
        edges.append((p, i))
    return edges


def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


tokens = None


def NI():
    global tokens
    if tokens is None:
        tokens = iterate_tokens()
    return int(next(tokens))


def LNI(n):
    return [NI() for _ in range(n)]


def yes(res):
    print("Yes" if res else "No")


def YES(res):
    print("YES" if res else "NO")


def pairwise(a):
    n = len(a)
    for i in range(n - 1):
        yield a[i], a[i + 1]


def factorial(n):
    return reduce(lambda x, y: x * y, range(1, n + 1))


def cmin(dp, i, x):
    if x < dp[i]:
        dp[i] = x


def cmax(dp, i, x):
    if x > dp[i]:
        dp[i] = x


def alp_a_to_i(s):
    return ord(s) - ord("a")


def alp_A_to_i(s):
    return ord(s) - ord("A")


def alp_i_to_a(i):
    return chr(ord("a") + i)


def alp_i_to_A(i):
    return chr(ord("A") + i)


d4 = [(1, 0), (0, 1), (-1, 0), (0, -1)]
d8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]


def ranges(n, m):
    return ((i, j) for i in range(n) for j in range(m))


def rangess(a, b, c):
    return ((i, j, k) for i in range(a) for j in range(b) for k in range(c))


def valid(i, j, n, m):
    return 0 <= i < n and 0 <= j < m


def ninj(i, j, n, m):
    return [(i + di, j + dj) for di, dj in d4 if valid(i + di, j + dj, n, m)]


def gen(x, *args):
    if len(args) == 1:
        return [x] * args[0]
    if len(args) == 2:
        return [[x] * args[1] for _ in [0] * args[0]]
    if len(args) == 3:
        return [[[x] * args[2] for _ in [0] * args[1]] for _ in [0] * args[0]]
    if len(args) == 4:
        return [
            [[[x] * args[3] for _ in [0] * args[2]] for _ in [0] * args[1]]
            for _ in [0] * args[0]
        ]


list2d = lambda a, b, v: [[v] * b for _ in range(a)]
list3d = lambda a, b, c, v: [[[v] * c for _ in range(b)] for _ in range(a)]


class Debug:
    def __init__(self, debug=False):
        self.debug = debug
        cur_path = os.path.dirname(os.path.abspath(__file__))
        self.local = os.path.exists(cur_path + "/.cph")

    def get_ic(self):
        if self.debug and self.local:
            from icecream import ic

            return ic
        else:
            return lambda *args, **kwargs: ...


class Mo:
    def __init__(self, N):
        self.N = N
        self.Q = 0
        self.left = []
        self.right = []

    def add_query(self, l, r):
        self.left.append(l)
        self.right.append(r + 1)
        self.Q += 1

    def calculate(self):
        block_size = self.N // (min(self.N, int(self.Q**0.5 + 0.5)))
        t = (self.N + block_size - 1) // block_size
        B = [[] for _ in range(t)]

        left = self.left
        right = self.right

        for q in range(self.Q):
            B[left[q] // block_size].append(q)

        for i in range(t):
            B[i].sort(key=lambda q: right[q], reverse=i % 2)
        return B


ic = Debug(1).get_ic()
for _ in range(II()):
    n, l = MII()
    ps = [LII() for _ in range(n)]
    mo = Mo(l + 1)
    for l, r in ps:
        mo.add_query(l, r)
    B = mo.calculate()
    print(n)
    for b in B:
        for q in b:
            print(*ps[q], sep=" ")
0