Submission details
Task:Sums
Sender:megachainmail
Submission time:2020-10-03 15:58:39 +0300
Language:Python3 (CPython3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.03 sdetails
#2ACCEPTED0.03 sdetails
#3ACCEPTED0.03 sdetails
#4ACCEPTED0.03 sdetails
#5ACCEPTED0.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.queue()

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

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

    def exec(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,v):
        s = 0
        tobeexecuted = []
        i=0
        while i < self.queries.count():
        
            q = self.queries.popleft()

            (qt, qa, qb, qv) = q
            if a >= qa and b <= qb:
                tobeexecuted.append((qt, a, b, qv))
                if a > qa:
                    self.queries.appendleft((qt, qa, a-1, qv))
                if b < qb:
                    self.queries.appendleft((qt, qa + 1, qb, qv))
            else:
                self.queries.appendleft(q)
            
            i += 1
        q.append((3, a, b, v))

        for q in tobeexecuted:
            self.exec(q)
        







        
        


        return s


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


    inp = []

    for i in range(q):
        inp.append([int(s) for s in input().split()])

    for i in range(q):
        quer = inp[i]
        if quer[0] == 1:
            a = quer[1]
            b = quer[2]
            x = quer[3]
            for j in range(a-1,b):
                v[j] += x
        elif quer[0] == 2:
            a = quer[1]
            b = quer[2]
            x = quer[3]
            for j in range(a-1,b):
                v[j] = x
        elif quer[0] == 3:
            a = quer[1]
            b = quer[2]
            s = 0
            for j in range(a-1,b):
                s += v[j]
            print(s)



if __name__ == "__main__":
    main()

Test details

Test 1

Verdict: ACCEPTED

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
10
13
12

Test 2

Verdict: ACCEPTED

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
7
-13
-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: ACCEPTED

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
30
-30
-9

Test 5

Verdict: ACCEPTED

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
29
-20

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)