QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#268959#5109. Spider WalkjuampiCompile Error//C++171.7kb2023-11-29 04:24:522023-11-29 04:24:52

Judging History

你现在查看的是最新测评结果

  • [2023-11-29 04:24:52]
  • 评测
  • [2023-11-29 04:24:52]
  • 提交

answer

N = 2 * (10**5) + 5
M = 5 * (10**5) + 5

n = None
m = None
a = [0]*N
s = None

def nxt(x, c):
    return (x + c) % n

def pre(x, c):
    return (x - c + n) % n

lines = []

c = [0] * N

def lowbit(x):
    return x & -x

def add(x, y):
    x += 1
    while x <= n:
        c[x] += y
        x += lowbit(x)

def query(x):
    res = 0
    x += 1
    while x:
        res += c[x]
        x -= lowbit(x)
    return res

def padd(l, r, x):
    add(l, x)
    add(r + 1, -x)

def work(l, r):
    if l <= r:
        padd(l, r, -1)
    else:
        padd(l, n - 1, -1)
        padd(0, r, -1)

n ,m , s= map(int, input().split())
s = s - 1
for i in range(m):
    d, t = map(int, input().split())
    t = t - 1
    lines.append((d, t))


for i in range(n):
    padd(i, i, min(abs(s - i), n - abs(s - i)))

lines.sort(reverse=True)

for d, t in lines:
    nx = nxt(t, 1)
    
    v1 = query(t)
    v2 = query(nx)
    
    assert abs(v1 - v2) <= 1
    if v1 == v2:
        continue
    if v1 > v2:
        padd(t, t, -1)
        cur = 0
        for i in range(18, -1, -1):
            if cur + (1 << i) <= n - 2 and query(pre(t, cur + (1 << i))) == v1 + cur + (1 << i):
                cur += 1 << i
        if cur:
            work(pre(t, cur), pre(t, 1))
        if query(nxt(nx, 1)) != v2 - 1:
            padd(nx, nx, 1)
    else:
        padd(nx, nx, -1)
        cur = 0
        for i in range(18, -1, -1):
            if cur + (1 << i) <= n - 2 and query(nxt(nx, cur + (1 << i))) == v2 + cur + (1 << i):
                cur += 1 << i
        if cur:
            work(nxt(nx, 1), nxt(nx, cur))
        if query(pre(t, 1)) != v1 - 1:
            padd(t, t, 1)
for i in range(n):
    print(query(i))

Details

answer.code:1:1: error: ‘N’ does not name a type
    1 | N = 2 * (10**5) + 5
      | ^