QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#268964#5109. Spider WalkjuampiWA 2723ms78476kbPython31.6kb2023-11-29 04:51:222023-11-29 04:51:23

Judging History

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

  • [2023-11-29 04:51:23]
  • 评测
  • 测评结果:WA
  • 用时:2723ms
  • 内存:78476kb
  • [2023-11-29 04:51:22]
  • 提交

answer

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

n, m, s = map(int, input().split())
s -= 1

a = [0] * N
c = [0] * N

lines = [(d, t - 1) for _ in range(m) for d, t in (map(int, input().split()),)]

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)

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 = (t + 1) % n
    
    v1 = query(t)
    v2 = query(nx)
    
    if abs(v1 - v2) <= 1:
        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

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2723ms
memory: 78476kb

input:

200000 500000 116205
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50...

output:

83796
83797
83798
83799
83800
83801
83802
83803
83804
83805
83806
83807
83808
83809
83810
83811
83812
83813
83814
83815
83816
83817
83818
83819
83820
83821
83822
83823
83824
83825
83826
83827
83828
83829
83830
83831
83832
83833
83834
83835
83836
83837
83838
83839
83840
83841
83842
83843
83844
83845
...

result:

wrong answer 1st lines differ - expected: '2', found: '83796'