F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Lucky

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2238    Accepted Submission(s): 788


Problem Description
WLD is always very lucky.His secret is a lucky number $K$.$k$ is a fixed odd number. Now he meets a stranger with $N$ numbers:$a1,a2,...,aN$.The stranger asks him $M$ questions.Each question is like this:Given two ranges $[Li,Ri]$ and $[Ui,Vi]$,you can choose two numbers $X$ and $Y$ to make $aX+aY=K$.The $X$ you can choose is between $Li$ and $Ri$ and the $Y$ you can choose is between $Ui$ and $Vi$.How many pairs of numbers$(X,Y)$ you can choose?
If WLD can answer all the questions correctly,he'll be the luckiest man in the world.Can you help him?
 

Input
There are multiple cases.(At MOST $5$)

For each case:

The first line contains an integer $N(1 \leq N \leq 30000)$.

The following line contains an integer $K(2 \leq K \leq 2*N)$,WLD's lucky number.K is odd.

The following line contains $N$ integers $a1,a2,...,aN(1 \leq ai \leq N)$.

The following line contains an integer $M(1 \leq M \leq 30000)$,the sum of the questions WLD has to answer.

The following $M$ lines,the i-th line contains $4$ numbers $Li,Ri,Ui,Vi(1 \leq Li \leq Ri < Ui \leq Vi \leq N)$,describing the i-th question the stranger asks.
 

Output
For each case:

Print the total of pairs WLD can choose for each question.
 

Sample Input
5 3 1 2 1 2 3 1 1 2 3 5
 

Sample Output
2
 

Hint
a1+a4=a2+a3=3=K.
So we have two pairs of numbers (1,4) and (2,3).
Good luck!
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-27 02:09:07, Gzip enabled