13548번 - 수열과 쿼리 6
import sys
input = sys.stdin.readline
X = 100001
N = int(input())
n = list(map(int, input().split()))
M = int(input())
a = [0]*M
q = [[i] + list(map(int, input().split())) for i in range(M)]
q.sort(key = lambda x : (x[1] // N ** 0.5, x[2]))
l = [0]*X
c, z, x = 0, 0, -1
t = [0]*(N+2)
t[0] = N
for x, i, j in q:
i -= 1
j -= 1
while x < j :
x += 1
t[n[l[x]]] -= 1
l[n[x]] += 1
t[l[n[x]]] += 1
c = max(l[n[x]], c)
while x > j :
t[l[n[x]]] -= 1
if c == l[n[x]] and not t[c] :c -= 1
l[n[x]] -= 1
x -= 1
while z < i :
t[l[n[z]]] -= 1
if c == l[n[z]] and not t[c] :c -= 1
l[n[z]] -= 1
t[l[n[z]]] += 1
z += 1
while z > i :
z -= 1
l[n[z]] += 1
c = max(l[n[z]], c)
a[x] = c
print(*a, sep = '\n')
인덱스에러인데 어떻게 고칠까요?
x
아하 그렇군요 감사합니다!!!
댓글을 작성하려면 로그인해야 합니다.
woobin_coding 10달 전
import sys
input = sys.stdin.readline
X = 100001
N = int(input())
n = list(map(int, input().split()))
M = int(input())
a = [0]*M
q = [[i] + list(map(int, input().split())) for i in range(M)]
q.sort(key = lambda x : (x[1] // N ** 0.5, x[2]))
l = [0]*X
c, z, x = 0, 0, -1
t = [0]*(N+2)
t[0] = N
for x, i, j in q:
i -= 1
j -= 1
while x < j :
x += 1
t[n[l[x]]] -= 1
l[n[x]] += 1
t[l[n[x]]] += 1
c = max(l[n[x]], c)
while x > j :
t[l[n[x]]] -= 1
if c == l[n[x]] and not t[c] :c -= 1
l[n[x]] -= 1
t[l[n[x]]] += 1
x -= 1
while z < i :
t[l[n[z]]] -= 1
if c == l[n[z]] and not t[c] :c -= 1
l[n[z]] -= 1
t[l[n[z]]] += 1
z += 1
while z > i :
z -= 1
t[l[n[z]]] -= 1
l[n[z]] += 1
t[l[n[z]]] += 1
c = max(l[n[z]], c)
a[x] = c
print(*a, sep = '\n')
인덱스에러인데 어떻게 고칠까요?