/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 17ms 4.523 MiB
#2 Accepted 88ms 4.816 MiB
#3 Accepted 86ms 4.812 MiB
#4 Accepted 87ms 4.812 MiB
#5 Accepted 87ms 4.816 MiB
#6 Accepted 86ms 4.812 MiB
#7 Accepted 87ms 4.773 MiB
#8 Accepted 84ms 4.816 MiB
#9 Accepted 84ms 4.828 MiB
#10 Accepted 86ms 4.77 MiB
#11 Accepted 85ms 4.77 MiB
#12 Accepted 85ms 4.77 MiB
#13 Accepted 86ms 4.898 MiB
#14 Accepted 87ms 4.77 MiB
#15 Accepted 112ms 4.684 MiB
#16 Accepted 86ms 4.77 MiB
#17 Accepted 85ms 4.816 MiB
#18 Accepted 86ms 4.77 MiB
#19 Accepted 87ms 4.77 MiB
#20 Accepted 86ms 4.676 MiB
#21 Accepted 87ms 4.816 MiB
#22 Accepted 86ms 4.77 MiB
#23 Accepted 86ms 4.711 MiB
#24 Accepted 85ms 4.77 MiB
#25 Accepted 86ms 4.762 MiB
#26 Accepted 87ms 4.656 MiB
#27 Accepted 87ms 4.859 MiB
#28 Accepted 87ms 4.816 MiB
#29 Accepted 86ms 4.77 MiB
#30 Accepted 85ms 4.77 MiB
#31 Accepted 85ms 4.77 MiB
#32 Accepted 86ms 4.711 MiB
#33 Accepted 86ms 4.684 MiB
#34 Accepted 85ms 4.832 MiB
#35 Accepted 88ms 4.875 MiB
#36 Accepted 85ms 4.77 MiB
#37 Accepted 86ms 4.707 MiB
#38 Accepted 87ms 4.77 MiB
#39 Accepted 85ms 4.77 MiB
#40 Accepted 85ms 4.77 MiB
#41 Accepted 86ms 4.84 MiB
#42 Time Exceeded ≥5097ms ≥15.578 MiB
#43 Time Exceeded ≥5099ms ≥15.352 MiB

Code

import math
import sys
input = sys.stdin.readline

MAXN = 100005
MAXBLOCKS = 400
NEG_INF = -10**18

a = [0] * MAXN
add = [0] * MAXBLOCKS
mx = [NEG_INF] * MAXBLOCKS
block = [0] * MAXN
n = 0
blocksize = 0

def update(l, r, x):
    global a, add, mx
    blockl = block[l]
    blockr = block[r]

    if blockl == blockr:
        for i in range(l, r + 1):
            a[i] += x
        mxb = NEG_INF
        for i in range((blocksize * (blockl - 1)) + 1, min(n, blocksize * blockl) + 1):
            a[i] += add[blockl]
            mxb = max(mxb, a[i])
        mx[blockl] = mxb
        add[blockl] = 0
        return

    if l % blocksize != 1:
        last = min(n, blocksize * blockl)
        for i in range(l, last + 1):
            a[i] += x
        mxb = NEG_INF
        for i in range((blocksize * (blockl - 1)) + 1, last + 1):
            a[i] += add[blockl]
            mxb = max(mxb, a[i])
        mx[blockl] = mxb
        add[blockl] = 0
        blockl += 1

    if r % blocksize != 0:
        first = blocksize * (blockr - 1) + 1
        for i in range(r, first - 1, -1):
            a[i] += x
        mxb = NEG_INF
        for i in range(min(n, blocksize * blockr), first - 1, -1):
            a[i] += add[blockr]
            mxb = max(mxb, a[i])
        mx[blockr] = mxb
        add[blockr] = 0
        blockr -= 1

    for i in range(blockl, blockr + 1):
        add[i] += x

def query(l, r):
    ans = NEG_INF
    blockl = block[l]
    blockr = block[r]

    if blockl == blockr:
        for i in range(l, r + 1):
            ans = max(ans, a[i] + add[blockl])
        return ans

    if l % blocksize != 1:
        last = min(n, blocksize * blockl)
        for i in range(l, last + 1):
            ans = max(ans, a[i] + add[blockl])
        blockl += 1

    if r % blocksize != 0:
        first = blocksize * (blockr - 1) + 1
        for i in range(r, first - 1, -1):
            ans = max(ans, a[i] + add[blockr])
        blockr -= 1

    for i in range(blockl, blockr + 1):
        ans = max(ans, mx[i] + add[i])
    return ans

def solve():
    global n, blocksize
    t = int(input())
    for _ in range(t):
        n = int(input())
        blocksize = int(math.sqrt(n))
        arr = list(map(int, input().split()))
        for i in range(1, n + 1):
            a[i] = arr[i - 1]
            block[i] = (i + blocksize - 1) // blocksize

        for i in range(1, MAXBLOCKS):
            add[i] = 0
            mx[i] = NEG_INF

        for i in range(1, n + 1, blocksize):
            mxv = a[i]
            for j in range(i, min(n, i + blocksize - 1) + 1):
                mxv = max(mxv, a[j])
            mx[block[i]] = mxv

        q = int(input())
        for _ in range(q):
            args = list(map(int, input().split()))
            if args[0] == 1:
                _, l, r, x = args
                update(l, r, x)
            else:
                _, l, r = args
                print(query(l, r))

if __name__ == "__main__":
    solve()

Information

Submit By
Type
Submission
Problem
P1211 Range MAX
Language
Python 3 (Python 3.12.3)
Submit At
2025-07-10 09:23:33
Judged At
2025-07-10 09:23:33
Judged By
Score
82
Total Time
≥5099ms
Peak Memory
≥15.578 MiB