295A - Greg and Array - CodeForces Solution


data structures implementation *1400

Please click on ads to support us..

Python Code:

import sys 
import math
from functools import cmp_to_key
from collections import OrderedDict
 
 
sys.setrecursionlimit(10**9)
 
 
query = [0 for i in range(int(1e5 + 10))]
diff = [0 for i in range(int(1e5 + 10))]
 
 
def solve():

    n,m,k = list(map(int,input().split()))

    arr = [int(x) for x in input().split()]

    operations = []

    for i in range(m):
        temp = [int(x) for x in input().split()]
        operations.append(temp)


    for i in range(k):
        l,r = list(map(int,input().split()))

        query[l-1] += 1 
        query[r] += -1

    for i in range(1,100001):
        query[i] += query[i-1]


    for i in range(m):

        diff[operations[i][0]-1] += query[i]*operations[i][2]
        diff[operations[i][1]] -= query[i]*operations[i][2]

    for i in range(1,len(diff)):
        diff[i] += diff[i-1]


    for i in range(n):

        arr[i] = arr[i] + diff[i]
        print(arr[i],end = " ")

    print()


 
if __name__ == '__main__':
 
 
    solve()


Comments

Submit
0 Comments
More Questions

1092B - Teams Forming
1166C - A Tale of Two Lands
544B - Sea and Islands
152B - Steps
1174D - Ehab and the Expected XOR Problem
1511A - Review Site
1316A - Grade Allocation
838A - Binary Blocks
1515D - Phoenix and Socks
1624D - Palindromes Coloring
1552F - Telepanting
1692G - 2Sort
1191A - Tokitsukaze and Enhancement
903A - Hungry Student Problem
52B - Right Triangles
1712A - Wonderful Permutation
1712D - Empty Graph
1712B - Woeful Permutation
1712C - Sort Zero
1028B - Unnatural Conditions
735B - Urbanization
746C - Tram
1278B - A and B
1353D - Constructing the Array
1269C - Long Beautiful Integer
1076A - Minimizing the String
913C - Party Lemonade
1313A - Fast Food Restaurant
681A - A Good Contest
1585F - Non-equal Neighbours