結果

問題 No.3436 [Cherry 8th Tune B] この夏に何が起こるかな?
コンテスト
ユーザー Mao-beta
提出日時 2026-02-04 02:05:29
言語 PyPy3
(7.3.17)
結果
AC  
実行時間 3,101 ms / 4,000 ms
コード長 2,067 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,614 ms
コンパイル使用メモリ 82,496 KB
実行使用メモリ 127,984 KB
最終ジャッジ日時 2026-02-04 02:07:26
合計ジャッジ時間 89,589 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.set_int_max_str_digits(10 ** 6)
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


def main():
    Q = NI()
    for _ in range(Q):
        N, M, K, P = NMI()
        T = NLI()
        C = NLI()
        B = NLI()
        D = NLI()
        S = [0] + NLI()
        BD2J = defaultdict(list)
        B2J = defaultdict(list)

        K2B = [[] for _ in range(K+1)]
        for j, (b, d) in enumerate(zip(B, D)):
            K2B[d].append(b)
            BD2J[(b, d)].append(j)
            B2J[b].append(j)
        for k in range(K+1):
            K2B[k].sort()
        SB = sorted(B)

        def judge(X):
            res = 0
            for t, c in zip(T, C):
                res += bisect.bisect_right(SB, X-t)
                res += bisect.bisect_right(K2B[c], X+S[c]-t)
                res -= bisect.bisect_right(K2B[c], X-t)
            return res >= P

        ok = 10**18
        ng = 0
        while abs(ok - ng) > 1:
            X = (ok + ng) // 2
            if judge(X):
                ok = X
            else:
                ng = X

        for i, (t, c) in enumerate(zip(T, C)):
            # print(t, ok+S[c]-t)
            same = BD2J[(ok+S[c]-t, c)]
            # print(same)
            if same:
                print(i+1, same[0]+1)
                break
            odd = B2J[ok-t]
            flg = False
            for j in odd:
                if D[j] != c:
                    flg = True
                    print(i+1, j+1)
                    break
            if flg:
                break


if __name__ == "__main__":
    main()
0