#P8512. Sequence Assignment and Summation

    ID: 21684 Type: Default 1000ms 256MiB

Sequence Assignment and Summation

Sequence Assignment and Summation

You are given an operation sequence \( (l_i, r_i, v_i) \) where each operation assigns the value \( v_i \) to every element in the interval \( [l_i, r_i] \) (1-indexed) of a sequence.

There are \( q \) queries. In each query, you start with an array \( c \) of length \( m \) initialized with zeros. You are also given two integers \( l \) and \( r \) (defining the range of operations to be executed, where operations are numbered from 1 to \( n \)). For that query, you sequentially execute operations \( l, l+1, \dots, r \). Each operation overwrites the values in the specified interval.

Your task is to compute the sum of all elements in \( c \) after performing the given operations for each query. Note that the queries are independent; that is, changes made in one query do not affect another.

inputFormat

The first line contains three integers \( n \), \( m \), and \( q \), representing the number of operations, the length of the sequence, and the number of queries respectively.

Then \( n \) lines follow. Each line contains three integers \( l_i \), \( r_i \), and \( v_i \) describing an operation.

Then \( q \) lines follow. Each line contains two integers \( l \) and \( r \) indicating that in this query you should execute operations numbered from \( l \) to \( r \) (inclusive).

outputFormat

For each query, output a single integer which is the sum of all numbers in the sequence \( c \) after performing the operations.

sample

3 5 2
1 3 5
2 5 3
4 5 1
1 2
2 3
17

8

</p>