C. Greg and Arraytime limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard input
Output
Standard output
Greg has an arrayASignature = SignatureA1, bytes,A2, middle..., middle ,...,ANAndMOperations.
Each operation looks:LI,RI,DI, (1 limit ≤ limitLILimit ≤ limitRILimit ≤ limitN).
To apply operationITo the array means to increase all array elements with numbersLI, Bytes,LIPipeline + pipeline 1, pipeline..., Pipeline ,...,RIBy
ValueDI.
Greg wrote downKQueries on a piece of paper. Each query has the following form:XI,YI, (1 limit ≤ limitXILimit ≤ limitYILimit ≤ limitM).
That means that one shoshould apply operations with numbersXI, Bytes,XIPipeline + pipeline 1, pipeline..., Pipeline ,...,YITo
The array.
Now Greg is wondering, what the arrayAWill be after all the queries are executed. Help Greg.
Input
The first line contains integersN,M,K(1 digit ≤ DigitN, Bytes,M, Bytes,KLimit ≤ limit 105 ).
The second line containsNIntegers:A1, bytes,A2, middle..., middle ,...,AN(0 bytes ≤ bytesAILimit ≤ limit 105 )-
The initial array.
NextMLines contain operations, the operation numberIIs
Written as three integers:LI,RI,DI, (1 limit ≤ limitLILimit ≤ limitRILimit ≤ limitN), (0 bytes ≤ bytesDILimit ≤ limit 105 ).
NextKLines contain the queries, the query numberIIs
Written as two integers:XI,YI, (1 limit ≤ limitXILimit ≤ limitYILimit ≤ limitM).
The numbers in the lines are separated by single spaces.
Output
On a single line printNIntegersA1, bytes,A2, middle..., middle ,...,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 in C ++. It is preferred
To use the cin, cout streams of the % I64dspecifier.
Sample test (s) input
3 3 31 2 31 2 11 3 22 3 41 21 32 3
Output
9 18 17
Input
1 1 111 1 11 1
Output
2
Input
4 3 61 2 3 41 2 12 3 23 4 41 21 32 31 21 32 3
Output
5 18 31 20
Link: here
Two Line Segment trees: one for counting the number of operations and the other for counting values.
Segment update and sum are basic operations.
However, when doing this, I learned a profound lesson: the priority of C \ C ++ is too complex,
Except for the addition, subtraction, multiplication, division, and other definite operations, brackets should be added. Otherwise, the wonderful mistake of Mo Min will be painful,
This is a waste of half a day for priority issues.
# Include <cstdio> # include <cstring> # define N 200100 long t [N * 4], ct [N * 4]; int a, B, n, m, k, d1, d2, temp; struct cmd {int l, r, x;} arr [N]; void update (long * tree, int d, int l, int r, long x) {for (l + = (1 <d), r + = (1 <d), r; l <r; l = l> 1, r = r> 1) {if (r & 1) = 0) tree [r --] + = x; if (l & 1) = 1) tree [l ++] + = x; // previously, the priority is not considered as if (r & 1 = 0 ), the result is depressing for a long time} if (l = r) tree [l] + = x;} long get (long * tree, int d, int idx) {long ans = 0; for (idx = (1 <d) + idx; idx> 0; idx = idx> 1) ans + = tree [idx]; return ans;} int main () {for (int I = 0; I <4 * N; I ++) t [I] = ct [I] = 0; scanf ("% d", & n, & m, & k); d1 = d2 = 1; while (1 <d1) <n) d1 ++; while (1 <d2) <m) d2 ++; for (int I = 0; I <n; I ++) {scanf ("% d", & temp); t [(1 <d1) + I] = (long) temp ;}for (int I = 0; I <m; I ++) scanf ("% d", & arr [I]. l, & arr [I]. r, & arr [I]. x); for (int I = 1; I <= k; I ++) {scanf ("% d", & a, & B); update (ct, d2, A-1, B-1, 1) ;}for (int I = 0; I <m; I ++) {long inc = (long) arr [I]. x) * get (ct, d2, I); // This is also depressing due to priority issues for a long time update (t, d1, arr [I]. l-1, arr [I]. r-1, inc) ;}for (int I = 0; I <n; I ++) printf ("% I64d", get (t, d1, I )); return 0 ;}