Submission details
Task:Sums
Sender:megachainmail
Submission time:2020-10-03 17:01:00 +0300
Language:Python3 (CPython3)
Status:READY
Result:
Test results
testverdicttime
#10.03 sdetails
#20.03 sdetails
#3ACCEPTED0.03 sdetails
#40.03 sdetails
#50.03 sdetails
#6--details
#7--details
#8--details
#9--details
#10--details

Code

import collections

class stru:
    def __init__(self, v):
        self.data = v
        self.queries = collections.deque()

    def ass(self, a, b, x):
        #self.queries.put((1,a,b,x))
        self.queries.append((2,a,b,x))

    def inc(self, a,b,x):
        #self.queries.put((2,a,b,x))
        self.queries.append((1,a,b,x))

    def execc(self, q):
        if q[0] == 1:
            a = q[1]
            b = q[2]
            x = q[3]
            for j in range(a-1,b):
                self.data[j] += x
        elif q[0] == 2:
            a = q[1]
            b = q[2]
            x = q[3]
            for j in range(a-1,b):
                self.data[j] = x
        elif q[0] == 3:
            a = q[1]
            b = q[2]
            s = 0
            for j in range(a-1,b):
                s += self.data[j]
            print(s)

    def summ(self, a,b):
        s = 0
        tobeexecuted = []
        i=0
        newqueries = collections.deque()
        while len(self.queries) != 0:
        
            q = self.queries.popleft()

            (qt, qa, qb, qv) = q
            #if (a >= qa or b <= qb) and (b>= qa or a >=qb) :
            if (qa <= a <=qb) or (qa <= b <=qb) :
                tobeexecadd = (qt, max(a, qa), min(b, qb), qv)
                tobeexecuted.append(tobeexecadd)
                if a > qa:
                    qadd = (qt, qa, a-1, qv)
                    newqueries.append(qadd)
                if b < qb:
                    qadd = (qt, b + 1, qb, qv)
                    newqueries.append(qadd)
            else:
                newqueries.append(q)
            
        tobeexecuted.append((3, a, b))
        

        for q in tobeexecuted:
            self.execc(q)
        
        self.queries = newqueries







        
        


        return s


def main():
    n = int(input())
    v = [int(i) for i in input().split()]
    q = int(input())
    
    s = stru(v)


    for i in range(q):
        inp = [int(s) for s in input().split()]
        if inp[0] == 1:
            s.inc(*inp[1:4])
        elif inp[0] == 2:
            s.ass(*inp[1:4])
        elif inp[0] == 3:
            s.summ(*inp[1:3])

   



if __name__ == "__main__":
    main()

Test details

Test 1

Verdict:

input
10
-10 3 -1 4 4 1 6 7 9 3
20
2 7 10 -5
2 5 9 2
...

correct output
-2
32
10
13
12

user output
-2
32
-18
49
12

Test 2

Verdict:

input
10
-10 -4 -7 -2 5 -8 0 -5 -5 5
20
3 8 10
1 5 6 7
...

correct output
-5
12
7
-13
-33
...

user output
-5
12
1
-19
-33
...

Test 3

Verdict: ACCEPTED

input
10
0 -2 7 4 1 4 -5 8 9 -10
20
2 2 8 -5
2 8 9 -2
...

correct output
-17
-10
-12
-5
21

user output
-17
-10
-12
-5
21

Test 4

Verdict:

input
10
0 6 -6 -9 7 -9 2 6 -4 -8
20
1 8 10 9
2 2 6 -10
...

correct output
6
30
-30
-9

user output
6
21
-30
-9

Test 5

Verdict:

input
10
-8 6 0 8 1 -8 3 6 10 -6
20
2 5 7 -3
3 2 4
...

correct output
14
18
7
29
-20

user output
14
18
7
31
6

Test 6

Verdict:

input
100000
273768 -746242 141310 -177646 ...

correct output
6647300100
16584491568
2201217278
4428835910
-5370398949
...

user output
(empty)

Test 7

Verdict:

input
100000
-371240 -967819 -659618 -83603...

correct output
-8551444
-14584129201
-9051387
1006850011
-1119500762
...

user output
(empty)

Test 8

Verdict:

input
100000
954118 382497 -92991 199841 98...

correct output
-31591117
3979951718
1018552734
1672204000
230714784
...

user output
(empty)

Test 9

Verdict:

input
100000
-374041 -712493 -568255 490384...

correct output
9993656711
4138033702
8839287
3596183407
-643074001
...

user output
(empty)

Test 10

Verdict:

input
100000
257414 -141188 -721927 -67385 ...

correct output
-47022095
-13947364
19483822021
10788657040
-4163257456
...

user output
(empty)