Похожие чаты

Ganesh: Problem Description: Krish loves chocolates very much. He has N containers

numbered from 1 to N.Everyday, he used to select two indices [l,r] and adds 1 chocolate to each box starting from l to r (both inclusive).He repeats the same activity for M days.

After M days, he asked his friend Nakshatra Q queries. Each query can be described as: How many containers have atleast K chocolates.
Help Nakshatra to answer these queries.

Input Format:
First line contains an integer N that denotes the number of containers.
Second line contains an integer M denoting the number of days.
Each of the next M lines consists of two space separated integers l and r.
Followed by an integer Q denoting the number of queries.
Each of next Q lines contain a single integer K.

Output Format:
For each query, print the result in new line.

Constraints:
1 <= N <= 100000
1 <= M <= 1000
1 <= l <= r <= N
1 <= Q <= 100000
1 <= K <= N
Example:
Input:
7
4
1 3
2 5
1 2
5 6
4
1
7
4
2
Output:
6
0
0
4
Explanation:
Initially, as shown in the sample test case, we have 7 containers, so let's have an array of 7 integers initialized to 0 (consider 1-based indexing).

arr = [0,0,0,0,0,0,0]
After Day 1, arr becomes:
arr = [1,1,1,0,0,0,0]
After Day 2, arr becomes:
arr = [1,2,2,1,1,0,0]
After Day 3, arr becomes:
arr = [2,3,2,1,1,0,0]
After Day 4, arr becomes:
arr = [2,3,2,1,2,1,0]

Now, Krish asked 4 queries from his friend:
Query 1: How many containers have atleast 1 chocolate?
Ans 1: Containers 1,2,3,4,5 and 6 have atleast 1 chocolates in them. Hence, the output is 6.

Query 2: How many containers have atleast 7 chocolates?
Ans 2: We can see that there is no container which contains atleast 7 chocolates. Hence, the output is 0.

Query 3: Similar to Query 2.
Query 4: How many containers have atleast 2 chocolates?
Ans 4: Containers 1,2,3 and 5 have atleast 2 chocolates in them. Hence, the output is 4.

1 ответов

5 просмотров
DarkLord- Автор вопроса

How to solve this in order (n)?

Похожие вопросы

Обсуждают сегодня

Ясн. Но я всеравно к кедам отношусь с опасением. Чисто субьективное кедосозерцание. Что касаемо "восторга изяшности кед" так и не вкурил, хотя много слышал, пока не поставил с...
Артем Записной
30
Такой вопросец - есть функция function MySuperDuperConcat(const a: array of AnsiString): AnsiString; Как мне в её теле сделать вот так? Result:=Concat(a); А не грустный вариан...
notme
15
Есть какой-нибудь для Delphi/FPC T*Compression(Decompression)Stream на базе LZ4/Zstd/любой другой быстрый(и хорошо сжимающий) алгоритм А ещё лучше в pure pascal А ещё лучше од...
notme
48
type TObj = object procedure Init; virtual; end; TObj1 = object(TObj) procedure Init; override; end; procedure TObj1.Init; begin inherited; end; procedur...
Alexander 👋
29
They keep hyping $FUN but where's the progress? 🙄
Noah Noure
23
Btw guys very stupid question but i haven't researchd so js asking you pros . Can ltc be traced too? Literally point to pint to the user? And getting the banks blocked ? Exch...
20
А чем вам питонисты не угодили?😂
.
79
Hey guys, did you see the new announcement about $Fun? 🔥
Filip Murphy
55
How can a minority hashrate chain defend from a fork-hopping ASIC miner? The problem: 1. A miner comes into your network, and mines at 60-70% hashrate. 2. After some time, th...
Kishniev
13
yeap, thanks guys for response, but I really like to understand does a pool created on curve.fi has the option or api or I can call a function of a smart contract to set excha...
Oleg Karoza
11
Карта сайта