Greg and Array
Time limit per test 2 seconds
Memory limit per test 56 megabytes
Input standard input
Output standard output
Greg has an array a signature = comment a1, comment a2, comment ,..., specified an andm operations. each operation looks as: li, ri, di, (1 Gbit/s ≤ 1_li Gbit/s ≤ 1_ri Gbit/s ≤ 1_n ). to apply operationi to the array means to increase all array elements with numbersli, please li + Example 1, example ,..., specified ri by valuedi.
Greg wrote down k queries on a piece of paper. each query has the following form: xi, yi, (1 ≤ 1_xi ≤ 1_yi ≤ 1_m ). that means that one shoshould apply operations with numbersxi, 1_xi + 1_1, 1 ,..., operation yi to the array.
Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.
Input
The first line contains integers n, m, k (1 segment ≤ limit n, limit m, limit k branch ≤ limit 105 ). the second line containsn integers: a1, clerk a2, clerk ,..., divide an (0 blocks ≤ artificial ai blocks ≤ limit 105)-the initial array.
Next m lines contain operations, the operation numberi is written as three integers: li, ri, di, (1 ≤ 1_li ≤ 1_ri ≤ 1_n ), (0 digit ≤ cost di digit ≤ cost 105 ).
Next k lines contain the queries, the query numberi is written as two integers: xi, yi, (1 ≤ 1_xi ≤ 1_yi ≤ 1_m ).
The numbers in the lines are separated by single spaces.
Output
On a single line print n integers a1, clerk a2, clerk..., clerk an-the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the % lld specifier to read or write 64-bit integers inC ++. It is preferred to use thecin, cout streams of the % I64d specifier.
Sample test (s)
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
This question is really a pity. There is a place where the subscript should be written as 0 starting from 1. The result is a waste of more than five minutes to find a bug, and the result is the end of the competition. Sorry. Research point: Tree array idea: create two tree arrays to calculate the number of operations and the change of each operation value.
[Cpp]
# Include <stdio. h>
# Include <string. h>
# Include <math. h>
_ Int64 tree1 [110000], tree2 [110000];
Struct num {
Int l, r, val;} a [1, 110000];
_ Int64 B [1000000], sum [110000];
_ Int64 n, m; int main ()
{Void build (_ int64 k ,__ int64 val );
Void build2 (_ int64 k ,__ int64 val );
_ Int64 search (_ int64 k );
_ Int64 search2 (_ int64 k );
_ Int64 I, j, s, t;
_ Int64 x, y, k;
While (scanf ("% I64d % I64d % I64d", & n, & m, & k )! = EOF)
{For (I = 1; I <= n; I ++)
{Scanf ("% I64d", & B [I]);}
For (I = 1; I <= m; I ++)
{Scanf ("% d", & a [I]. l, & a [I]. r, & a [I]. val );
} Memset (tree2, 0, sizeof (tree2 ));
Memset (tree1, 0, sizeof (tree1); for (I = 1; I <= k; I ++)
{Scanf ("% I64d % I64d", & x, & y );
Build (y, 1 );
Building (x-1,-1 );}
Memset (sum, 0, sizeof (sum ));
For (I = 1; I <= m; I ++)
{T = search (I );
Sum [I] = sum [I] + t;
} For (I = 1; I <= m; I ++)
{Build2 (a [I]. r, sum [I] * a [I]. val );
Build2 (a [I] L-1,-1 * sum [I] * a [I]. val );}
For (I = 1; I <= n; I ++ ){
T = search2 (I); B [I] + = t;
If (I = 1 ){
Printf ("% I64d", B [I]);
} Else {
Printf ("% I64d", B [I]);
} Printf ("\ n ");
} Return 0;} int f (int k ){
Return (k &-k);} void build (_ int64 k ,__ int64 val ){
While (k> 0) {tree2 [k] + = val;
K-= f (k) ;}}_ _ int64 search (_ int64 k ){
_ Int64 s = 0; while (k <= m)
{S + = tree2 [k];
K + = f (k );}
Return s;} void build2 (_ int64 k ,__ int64 val)
{
While (k> 0)
{
Tree1 [k] + = val;
K-= f (k );
}}_ _ Int64 search2 (_ int64 k ){
_ Int64 s = 0; while (k <= n)
{S + = tree1 [k];
K + = f (k );}
Return s ;}