Chika and Friendly Pairs
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
Problem Description
Chika gives you an integer sequence a1,a2,…,an and m tasks. For each task, you need to answer the number of "friendly pairs" in a given interval.
friendly pair: for two integers ai and aj, if i
Input
The first line contains 3 integers n (1≤n≤27000), m (1≤m≤27000) and K (1≤K≤109), representing the number of integers in the sequence a, the number of tasks and the given constant integer.
The second line contains n non-negative integers, representing the integers in the sequence a. Every integer of sequence a is no more than 109.
Then m lines follow, each of which contains two integers L, R (1≤L≤R≤n). The meaning is to ask the number of "friendly pairs" in the interval [L,R]。
Output
For each task, you need to print one line, including only one integer, representing the number of "friendly pairs" in the query interval.
Sample Input
5 5 3
2 5 7 1 3
6 6
1 3
2 4
1 5
2 3
*/
Sample Output
0
2
1
3
1
题意:给你一个序列,多次询问,每次让你回答一个区间中差的绝对值不超过一个给定常数K的元素对数。
对序列中的所有元素以及这些元素+K,-K后的值进行离散化。 然后使用莫队算法,在莫队算法的端点移动过程中,新加入一个元素x的过程中,将其插入树状数组,查询[x-K,x+K]范围的元素数即可。删除一个元素的过程与其类似。
/**/
#include
#include
#include
#include
#include
#include
#include