結果
| 問題 |
No.2650 [Cherry 6th Tune *] セイジャク
|
| コンテスト | |
| ユーザー |
timi
|
| 提出日時 | 2024-02-23 21:54:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 945 ms / 2,500 ms |
| コード長 | 2,791 bytes |
| コンパイル時間 | 824 ms |
| コンパイル使用メモリ | 82,384 KB |
| 実行使用メモリ | 100,136 KB |
| 最終ジャッジ日時 | 2024-09-29 06:27:01 |
| 合計ジャッジ時間 | 24,827 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
ソースコード
# T=int(input())
# for i in range(T):
N,A=map(int,input().split())
#N=int(input())
X=list(map(int, input().split()))
C=[]
for i in range(N):
C.append((X[i],i))
C=sorted(C)
D=sorted(X)
#print(C,D)
import bisect
import sys
class Lazysegtree:
def __init__(self, A, intv, initialize = True):
#区間は 1-indexed で管理
self.N = len(A)
self.N0 = 2**(self.N-1).bit_length()
self.intv = intv
#self.segf = segf
self.lazy = [None]*(2*self.N0)
if initialize:
self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
for i in range(self.N0-2, -1, -1):
self.data[i] = min(self.data[2*i], self.data[2*i+1])
else:
self.data = [intv]*(2*self.N0)
def _ascend(self, k):
k = k >> 1
c = k.bit_length()
for j in range(c):
idx = k >> j
self.data[idx] = min(self.data[2*idx], self.data[2*idx+1])
def _descend(self, k):
k = k >> 1
idx = 1
c = k.bit_length()
for j in range(1, c+1):
idx = k >> (c - j)
if self.lazy[idx] is None:
continue
self.data[2*idx] = self.data[2*idx+1] = self.lazy[2*idx] \
= self.lazy[2*idx+1] = self.lazy[idx]
self.lazy[idx] = None
def query(self, l, r):
L = l+self.N0
R = r+self.N0
self._descend(L//(L & -L))
self._descend(R//(R & -R) - 1)
s = self.intv
while L < R:
if R & 1:
R -= 1
s = min(s, self.data[R])
if L & 1:
s = min(s, self.data[L])
L += 1
L >>= 1
R >>= 1
return s
def update(self, l, r, x):
L = l+self.N0
R = r+self.N0
Li = L//(L & -L)
Ri = R//(R & -R)
self._descend(Li)
self._descend(Ri-1)
while L < R :
if R & 1:
R -= 1
self.data[R] = x
self.lazy[R] = x
if L & 1:
self.data[L] = x
self.lazy[L] = x
L += 1
L >>= 1
R >>= 1
self._ascend(Li)
self._ascend(Ri-1)
T = Lazysegtree([0]*(N+10), 2**31-1, initialize = False)
Q=int(input())
for i in range(Q):
l,r=map(int,input().split())
ll,rr=bisect.bisect_left(D,l),bisect.bisect_right(D,r)
T.update(ll,rr,i+2)
E=[]
for i in range(N):
E.append(T.query(i,i+1))
ans=[-1]*N;now=0
for _,x in C:
e=E[now]
now+=1
if e!=2147483647:
ans[x]=e-1
for i in ans:
print(i)
timi