![]() |
||||||||||
|
||||||||||
Play With SequenceTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 677 Accepted Submission(s): 358 Problem Description When the girl was solving GSSX, a serious of tough problems about data structure on SPOJ, something intriguing once again comes to GYZ's mind. That is, for a changing sequences, how to count how many elements in a specific range efficiently. Without any beneficial idea, as usual, GYZ asks her friend, CLJ for help. But this time, unfortunately, CLJ is playing a gal-game at present, does not have sparse time. So now , it is your turn... Cause the original problem is not as easy as first glance, let's examine a simplified one: you are given a sequence A[1], A[2],..., A[N]. On this sequence you have to apply M operations: Add all the elements whose value are in range [l, r] with d or, ask for a query how many element are in range [l, r]. Input There are only one test case, Process until the end of the file. The first line of each case contains two numbers, N, M, described as above. And then start from the second line, have N numbers described the sequence's initial value. ( 1¡Ü N ¡Ü 250,000, M ¡Ü 50,000), |A[i]|¡Ü 1,000,000,000 .) The following M lines described the operation: C l r d: Add all the element whose value are in range [l, r] with d. (Redeclare: Not its Position! .. ) Q l r: ask for a query how many elements, whose value are in range [l, r]. ( l ¡Ü r, |l|,|r|,|d|¡Ü 1,000,000,000 ) We guarantee every elements are suits 32-integer, and will not cause overflow, even during the running-time. (.. but still be careful ;) Besides, all the test-data are generated randomly. Output For each query, print the result. Example Sample Input
Sample Output
Hint (In the first example, after the two operations, the sequences are become to, {-4, -3, -2, -1, 0, 11, 12, 13, 14, 15}, so there are no elements whose value are in range [1, 10]. ) Source | ||||||||||
|