TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

You have been given an array num[1..n] contains N integers and have to do some operations on it. Each operation can be indicated by four integers L, R, J, P, which means: change the value of a[P] to the maximum value among a[L], A[L+J], A[L+2J], ... , A[R]. Finally, calculate the sum of all elements of the array.

Input Format

There are several testcases. Each testcase begin with a positive integer N(<=10,000) followed by N integers (<=109). Then there are a positive integer M(<=10,000) and next M lines are the operations you have to do. Each line has four integers L,R,J,P (1<=L,R,J,P<=N, L<=R, J|R-L).

Output Format

For each testcase output an interger: the sum of final array.

Sample Input 1

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

Sample Output 1

10

Hints

Problem Source

Migrated from old NTUJ.

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 200