Roy and Coin Boxes
Practice
4.5 (39 votes)
Approved
Bit manipulation
Data structures
Dynamic programming
Medium
Open
Segment trees
Problem
82% Success 8700 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code
Roy has N coin boxes numbered from 1 to N.
Every day he selects two indices [L,R] and adds 1 coin to each coin box starting from L to R (both inclusive).
He does this for M number of days.
After M days, Roy has a query: How many coin boxes have atleast X coins.
He has Q such queries.
Input:
First line contains N - number of coin boxes.
Second line contains M - number of days.
Each of the next M lines consists of two space separated integers L and R.
Followed by integer Q - number of queries.
Each of next Q lines contain a single integer X.
Output:
For each query output the result in a new line.
Constraints:
1 ≤ N ≤ 1000000
1 ≤ M ≤ 1000000
1 ≤ L ≤ R ≤ N
1 ≤ Q ≤ 1000000
1 ≤ X ≤ N
Submissions
Please login to view your submissions
Similar Problems
Points:30
7 votes
Tags:
AlgorithmsC++Dynamic Programming
Points:30
11 votes
Tags:
ApprovedData StructuresDynamic ProgrammingMediumOpen
Points:30
34 votes
Tags:
Basic ProgrammingMediumReady
Editorial