Submission #61611260


Source Code Expand

from collections import defaultdict, deque, Counter
from functools import cache
# import copy
from itertools import combinations, permutations, product, accumulate, groupby, chain
from more_itertools import distinct_permutations
from heapq import heapify, heappop, heappush, heappushpop
import math
import bisect
# from pprint import pprint
from random import randint, shuffle, randrange
from sortedcontainers import SortedSet, SortedList, SortedDict
import sys
# sys.setrecursionlimit(2000000)
input = lambda: sys.stdin.readline().rstrip('\n')
inf = float('inf')
mod1 = 10**9+7
mod2 = 998244353
def ceil_div(x, y): return -(-x//y)

#################################################   

def parallel_binary_search():
    oks, ngs = [0]*Q, [(r-l)//2+1 for l, r in querys]
    while True:
        exit_flag = True
        events = []
        look = []
        for q, (l, r) in enumerate(querys):
            if abs(oks[q]-ngs[q]) > 1:
                look.append(q)
                exit_flag = False
                mid = (oks[q]+ngs[q])>>1
                events.append((l, q))
                events.append((l+mid, q))
        if exit_flag:
            return oks
        
        events.sort(key=lambda e: e[0])
        T = [0]*Q
        hq = []
        deled = set()
        ei = 0
        is_out = [False]*Q
        for i in range(N):
            while ei < len(events) and events[ei][0] == i:
                _, q = events[ei]
                l, r = querys[q]
                mid = (oks[q]+ngs[q])>>1
                if T[q] == 0:
                    heappush(hq, (r-mid-l, q))
                else:
                    deled.add(q)
                T[q] ^= 1
                ei += 1
            while hq and i+hq[0][0] >= N or hq and A[i]*2 > A[i+hq[0][0]]:
                _, q = heappop(hq)
                if q not in deled:
                    is_out[q] = True

        for q in look:
            mid = (oks[q]+ngs[q])>>1
            if is_out[q]:
                ngs[q] = mid
            else:
                oks[q] = mid

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
querys = []
for _ in range(Q):
    l, r = map(int, input().split())
    l -= 1
    querys.append((l, r))
print(*parallel_binary_search(), sep="\n")

Submission Info

Submission Time
Task G - Simultaneous Kagamimochi 2
User knty
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 2324 Byte
Status TLE
Exec Time 2233 ms
Memory 349728 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 575
Status
AC × 2
AC × 5
TLE × 41
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 02_handmade_40.txt, 02_handmade_41.txt, 02_handmade_42.txt, 02_handmade_43.txt, 02_handmade_44.txt, 02_handmade_45.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 152 ms 89316 KiB
00_sample_01.txt AC 152 ms 89432 KiB
01_random_02.txt TLE 2229 ms 310864 KiB
01_random_03.txt TLE 2230 ms 323112 KiB
01_random_04.txt TLE 2229 ms 297904 KiB
01_random_05.txt TLE 2229 ms 316044 KiB
01_random_06.txt TLE 2229 ms 310820 KiB
01_random_07.txt TLE 2230 ms 316812 KiB
01_random_08.txt TLE 2233 ms 349728 KiB
01_random_09.txt TLE 2229 ms 312916 KiB
01_random_10.txt TLE 2229 ms 314412 KiB
01_random_11.txt TLE 2230 ms 321916 KiB
01_random_12.txt TLE 2231 ms 327904 KiB
01_random_13.txt TLE 2229 ms 314056 KiB
01_random_14.txt TLE 2229 ms 314796 KiB
01_random_15.txt TLE 2229 ms 313676 KiB
01_random_16.txt TLE 2229 ms 312584 KiB
01_random_17.txt TLE 2232 ms 312724 KiB
01_random_18.txt TLE 2229 ms 311320 KiB
01_random_19.txt TLE 2232 ms 313520 KiB
01_random_20.txt TLE 2229 ms 304440 KiB
01_random_21.txt TLE 2229 ms 315108 KiB
01_random_22.txt TLE 2230 ms 328776 KiB
01_random_23.txt TLE 2231 ms 333040 KiB
01_random_24.txt TLE 2230 ms 315152 KiB
01_random_25.txt TLE 2230 ms 314592 KiB
01_random_26.txt TLE 2230 ms 316212 KiB
01_random_27.txt TLE 2230 ms 313284 KiB
01_random_28.txt TLE 2230 ms 308936 KiB
01_random_29.txt TLE 2231 ms 327320 KiB
01_random_30.txt TLE 2231 ms 326128 KiB
01_random_31.txt TLE 2230 ms 313256 KiB
01_random_32.txt TLE 2231 ms 324888 KiB
01_random_33.txt TLE 2230 ms 320052 KiB
01_random_34.txt TLE 2230 ms 345684 KiB
01_random_35.txt TLE 2230 ms 313372 KiB
01_random_36.txt TLE 2229 ms 314420 KiB
01_random_37.txt TLE 2230 ms 321096 KiB
01_random_38.txt TLE 2229 ms 315188 KiB
01_random_39.txt TLE 2232 ms 313804 KiB
02_handmade_40.txt AC 544 ms 170156 KiB
02_handmade_41.txt AC 543 ms 170388 KiB
02_handmade_42.txt AC 1048 ms 245804 KiB
02_handmade_43.txt TLE 2229 ms 306524 KiB
02_handmade_44.txt TLE 2230 ms 333136 KiB
02_handmade_45.txt TLE 2230 ms 332780 KiB